I’m writing a TCP client that connect to a server and send data periodically. The server isn’t supposed to answer with an ACK (and I can’t change it).
I open the client socket as a blocking one and get send() return that it’s supposed to be the number of bytes sent. All works perfect until I unplug the server ethernet wire, the send function return a valid number of written bytes although obviously it isn’t.
If server side close connection with close() doing a send() at the client return -1 (it works). It only “fails” when I unplug the wire.
Somethings I try but doesn’t work:
Set socket as non-blocking and select() it to know if write is possible. It says me it’s although it isn’t.
poll() for POLLOUT event. Same as above.
Set SNDBUFF to 0.
The only way I got it working is doing “Open-Send-Close” because when I try to reopen a non-connected server it warn me. But I want to avoid doing that if possible. Is there any way to know if destination of a open socket it’s up?
Thanks in advance.