c - What does recv() return when using non-blocking sockets? -
if set socket non-blocking, should recv() if there no new data read? at moment, using , if statement see if received greater -1. seems block somehow if nothing received. code looks like: flags = fcntl(newfd, f_getfl); flags |= o_nonblock; fcntl(newfd, f_setfl, flags); while(1){ ... ... if( (recvbytes = recv(newfd, recvbuf, maxbuflen-1, 0)) > -1) { ... } } according manpage: if no messages available @ socket , o_nonblock not set on socket's file descriptor, recv() shall block until message arrives. if no messages available @ socket , o_nonblock set on socket's file descriptor, recv() shall fail , set errno [eagain] or [ewouldblock].