Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
Socket.Poll timeout occurs unexpectedly #29772
I am trying to detect disconnection issues by using
Microsoft Docs say that
Is it possible to detect disconnections with both
When the server is up and the connection ok, if I use Poll with
If this is the case to check that everything is ok I should set a very low timeout.
I'm not sure I understand your use case @luigiberrettini Maybe simple sample code would help.
Hi @wfurt here you can find references to the behavior I need clarifications about:
Basically I am trying to detect UDP and TCP (besides using KeepAlive) disconnections before continuing sending data on a Socket.
AFAIK, there is no reliable way how to detect "disconnect" for UDP. (as there is no connection) Your data may or may not be delivered and there is no feedback or confirmation. The only option is getting ICMP (port)unreachable. And you will not get it unless you sent data to closed port.
#1 from your previous comment is really confusing. Detection if socket is readable or writable is fully independent of data sent to the socket.
Using a heartbeat is not feasible because I am not the owner of the Syslog protocol
The only way to know if a Socket is really writable is to send data on it, but to avoid the server receiving bad data I would like to know if I can send some sort of data that is usually discarded (0 bytes array or something else).
I read that
I know that UDP is a connectionless protocol, but in the UDP constructor A
As a result I need a way to understand if the Socket can be used to send data on it both for UDP and TCP
To me it is really strange that I am allowed to call Poll on a UDP socket and this does not detects disconnections as stated in the documentation: either the docs should be updated or there should be a TcpSocket class implementing Poll and a UdpSocket not implementing it.
Even if only for the TCP case should I call
Or should I use the approach suggested on StackOverflow?
I would like to have a confirmation that by design
no, I was not suggesting heat-beat and I'm somewhat familiar with syslog protocol.
Back to the Poll, discussion: The primary function is not to detect disconnects. It can detect errors on socket - and for TCP disconnect is one of them. do "man poll" on your linux system and read the page. Since UDP does not have connection, there is no disconnect and socket will not transition to error mode unless you get ICMP back as I mentioned. (all that is handled at OS level)
You can sue select() to get all the three attributes in single call. You can use 0 for timeout and the call would return immediately.
But why don't you just write your data and react to errors?
About heart-beats I only wanted to clarify that it was not feasible for me even if you did not suggest it.
The poll man page does not help so much in understanding how to detect a disconnection in C# and
As for Syslog RFCs I support both RFC 3164 and RFC 5424.
Unfortunately section 8.5 of RFC 5424 does not explain/suggest implementation details:
My code is already reacting to errors but I would like to minimize message lost: a potentially big log message can be split in mutiple Syslog messages and if only one fails it would cause the entire message to be lost.
Since I am quite confused, it would be really helpful if you could give me a crystal clear answer on what I should do.
One of the reasons for introducing this check was that during debug sessions I noticed that, after unplugging the cable, the first Write did not fail, therefore I was losing messages.