Reputation: 133
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".
Upvotes: 2
Views: 1584
Reputation: 70472
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
EAGAIN
orEWOULDBLOCK
. This provides similar behavior to setting theO_NONBLOCK
flag (via thefcntl
(2)F_SETFL
operation), but differs in thatMSG_DONTWAIT
is 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
.
Upvotes: 1