reem / rust-event

A global event loop
108 stars 10 forks source link

hi, I ran your tcp.rs example #1

Closed miketang84 closed 9 years ago

miketang84 commented 9 years ago

hi, I ran your tcp.rs example,

I visit 127.0.0.1:3000 using telnet, I found that this example write RESPONSE forever, why? this is not my want. I want after I send a msg, it response once. What should I do?

Thank you.

reem commented 9 years ago

This is just a result of oversimplification in the example, since it doesn't deregister interest in the socket once it's done writing the response and doesn't track its own status. You could easily modify the handler to remove interest in mio::event::WRITABLE after the response has been written.

reem commented 9 years ago

I'll see if I can spend some time rewriting the example to be idiomatic and correctly track interest etc.

reem commented 9 years ago

@daogangtang The easiest thing to do is to just poll with Interest::writable() and PollOpt::edge() + PollOpt::oneshot() so that you receive only one writable notification on the stream and can write the RESPONSE once before deregistering/closing the connection.

reem commented 9 years ago

That's not really a robust approach to general tcp communication though, but anything more is out-of-scope for this crate, but isn't for rust-aio, for instance.