Confused about recv()
Pardon if this question has been answered but I couldn't find it.
I'm kinda开发者_如何转开发 confused about recv()
and recvfrom()
. Once the server binds the address (or accepts connection for TCP), recv()
is called. Does recv()
constantly check for messages that has been sent or does it wait until a message is received? If it does wait, how long is the wait time?
Not sure if I'm making sense, but if someone could enlighten me, I'd be grateful.
If no messages are available at the socket and
O_NONBLOCK
is not set on the socket's file descriptor,recv
() shall block until a message arrives.If no messages are available at the socket and
O_NONBLOCK
is set on the socket's file descriptor,recv
() shall fail and set errno to [EAGAIN
] or [EWOULDBLOCK
].
Source: http://www.opengroup.org/onlinepubs/009695399/functions/recv.html
Note that you can implement a timeout using select() or poll(), which also lets you wait on multiple sockets at once.
精彩评论