views:

135

answers:

2

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.

+5  A: 

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

codaddict
thanks, i thought i read that thoroughly but apparently not enough..
Fantastic Fourier
A: 

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

ceo