Quote:
Originally Posted by
neutronscott
... so what exactly does recv() return from a dead server ... ?
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.