lemunozm / message-io

Fast and easy-to-use event-driven network library.
Apache License 2.0
1.11k stars 74 forks source link

Question about Signal usage in ping-pong example #90

Closed tatref closed 3 years ago

tatref commented 3 years ago

Hi,

In the client, a Signal is sent when the connection is established https://github.com/lemunozm/message-io/blob/656f486fd55bb456bb0e5720f6ffa1d518d54106/examples/ping-pong/client.rs#L22-L25

Then the real message is sent later: https://github.com/lemunozm/message-io/blob/656f486fd55bb456bb0e5720f6ffa1d518d54106/examples/ping-pong/client.rs#L46-L50

Is there any reason for not sending the message directly in the NetEvent::Connect event? Maybe to prevent blocking the thread while sending the message?

lemunozm commented 3 years ago

Hi @tatref,

The only reason to make it so is to not duplicate lines 22-24 in the code example. There are no blocking issues. It's totally safe to send the message just in the Connected event if the established flag is true.

EDIT: no blocking issues beyond the TCP blocking issues if the receiver buffer is full.

lemunozm commented 3 years ago

I close this issue. If you need more information feel free to reopen or open a new issue :)