TCP connection check

Maybe you would like to put a timeout on your select(), "No response from server." and you did change your recv() to check for 0?

Your code is beautiful, btw. :slight_smile:

Actually, I think TEMP_FAILURE_RETRY does it for me.
Still, I am stuck. I tried few small modifications and still I get SIGPIPE only during second communication trial.
Timeout on select does not help, because first time send and receive does not return any error, select also"thinks" that socket is active. I don't know, maybe there is some trick to flush socket after every successful send?

If you're getting 'valid' replies even when the socket's dead, you couldn't have gotten everything the server sent.

I asked for the contents of that macro and never got it, but suspect it's not quite doing what you want.

... so what exactly does recv() return from a dead server ... ? :confused:

Anything that's left in the buffer, like a pipe.

Imagine this scenario, you send 'HELLO' to the server and it sends 'SLARTIBARTFAST' back. However, some data's still in transit, and you don't know how much is coming, so you only read 'SLAR'. The rest arrives when you're not waiting for it.

Next time around, you try sending again. Between then and now the server's been set aflame by hostile pygmy shrews, but it'll take a few minutes of nonresponses for the client socket to realize that, so the socket optimistically accepts the data and begins transmitting it to the dead and smoking server. Since the send() is smaller than the buffer size, it doesn't even make you wait, it just goes. Following which you read a 'TIBARTFAST' which arrived minutes ago and decide everything's okay.

On try three, it's long since realized the server's flopped over and died, so the instant you write to it, you get SIGPIPE.

I was prompting him to print more. His buffer was 'AAAAAAAA' b/c of a memset() so I'm guessing recv() is already returning 0 which requires action, and he never said/showed that he changed that.