Is this the right way to add multiple flags into a function?
recv(sfd, &buf, sizeof(buf), MSG_DONTWAIT | MSG_ERRQUEUE);
I don't get an error message in my buf.
recv() does not block.
I get errno: 11, which says "try again".
Is this the right way to add multiple flags into a function?
recv(sfd, &buf, sizeof(buf), MSG_DONTWAIT | MSG_ERRQUEUE);
I don't get an error message in my buf.
recv() does not block.
I get errno: 11, which says "try again".
The way you have added flags to the last parameter to recv() is fine. It seems you do not understand what the MSG_DONTWAIT will do.
The MSG_DONTWAIT flag will cause the recv() call to be performed as a non-blocking operation. That means it will return -1 with errno set to EAGAIN or EWOULDBLOCK if there is no data to be returned.
MSG_DONTWAIT(since Linux 2.2)
- Enables nonblocking operation; if the operation would block, the call fails with the error
EAGAINorEWOULDBLOCK. This provides similar behavior to setting theO_NONBLOCKflag (via thefcntl(2)F_SETFLoperation), but differs in thatMSG_DONTWAITis a per-call option ...
If you want recv() to block until there is data returned, remove the MSG_DONTWAIT flag, and make sure your socket is does not set O_NONBLOCK.