Home > Blockchain >  Linux TCP blocking socket is returning zero with EAGAIN
Linux TCP blocking socket is returning zero with EAGAIN

Time:03-08

I have a blocking TCP socket as a part of a TCP client implemented in C . It is trying to read data using a ::read() call on the socket descriptor. I am seeing very frequent cases, where the read returns with a value of 0, but the value of errno is EAGAIN.

What is EAGAIN supposed to mean in case of blocking sockets?

I understand the functioning in case of a non-blocking socket, but unclear about a blocking socket.

I understand it might be because of hitting a read timeout, but I am currently not setting a read timeout value.

What is the default read timeout value in case of linux TCP sockets?

CodePudding user response:

where the read returns with a value of 0

This means the peer has gracefully closed its end of the connection. You need to close your socket descriptor for that connection. Don't bother checking errno, it is meaningless in this condition. It only has meaning if read() had returned < 0 instead.

  • Related