Question

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.

Was it helpful?

Solution

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

OTHER TIPS

Note that you can implement a timeout using select() or poll(), which also lets you wait on multiple sockets at once.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top