The problem of recv return value in non-blocking state

In the non-blocking state of the

recv function, no data is returned with a value of 0. If the client shuts down, the return value is also 0. How can the two states be distinguished?

Mar.23,2021

default recv should be blocked. When setting MSG_DONTWAIT or socket descriptor with O_NONBLOCK option, in the absence of data, should return-1 and set errno to EAGAIN or EWOULDBLOCK


non-blocking mode, no data return value is-1, and the error code is EAGAIN or EWOULDBLOCK.

Menu