ASPLes / nopoll

OpenSource WebSocket toolkit
http://www.aspl.es/nopoll
GNU Lesser General Public License v2.1
124 stars 74 forks source link

How do you handle TCP RST frames? #75

Closed DarkLigther closed 1 year ago

DarkLigther commented 1 year ago

When the server was disconnected using TCP RST, I used nopoll_conn_is_ok, which didn't give me the correct result.

francisbrosnan commented 1 year ago

Hello,

nopoll_conn_is_ok does not gets updated automatically. It needs to be run through nopoll_loop (which is not obligatory) or a call to nopoll_get_next_msg.

That is, it needs an interaction with the socket so now it is not working (otherwise OS does not have any mean to convey broken pipe).

Best Regards

DarkLigther commented 1 year ago

Hello,

nopoll_conn_is_ok does not gets updated automatically. It needs to be run through nopoll_loop (which is not obligatory) or a call to nopoll_get_next_msg.

That is, it needs an interaction with the socket so now it is not working (otherwise OS does not have any mean to convey broken pipe).

Best Regards

Thank you very much for your answer:

I still have some questions: I call nopoll_is_ok and nopoll_conn_get_msg every 10ms to make sure the server is connected and to process the messages from the server. I also keep sending messages to the server, but when the server disconnects using TCP RST, I don't know. So every subsequent send will fail, is there any way to let me know if the connection is working?

francisbrosnan commented 1 year ago

Hello, Taking your description "..but when the server disconnects using TCP", you can see this the other way around: it is not possible for nopoll to block/discard tcp reset received on the socket associated to that noPollConn.

Even in the case such feature was possible (which is not), it is not a desired behaviour: noPoll library excepts tcp layer from OS to report any problem as soon as possible so noPoll can also update and report state about that.

In that case, if you know server disconnected with tcp reset and nopoll_conn_get_msg still works without reporting, then it is a firewall or similar service that is blocking that tcp frame to come in into the system that is running nopoll client, so that system have no way to know tcp session has been blocked/discarded/closed, and hence, it cannot send broken pipe (or similar) to upper level where nopoll and your application works..