![]() |
![]() |
![]() |
Receive a message from the socket at a specified address
#include <sys/types.h> #include <sys/socket.h> int recvfrom( int s, void * buff, size_t len, int flags, struct sockaddr * from, size_t * fromlen );
libsocket
The recvfrom() routine receives a message from the socket, s, whether or not it's connection-oriented.
If from is nonzero, and the socket is connectionless, the source address of the message is filled in. The parameter fromlen is a value-result parameter, initialized to the size of the buffer associated with from, and modified on return to indicate the actual size of the stored address.
This routine returns the length of the message on successful completion. If a message is too long for the supplied buffer, buf, excess bytes may be discarded depending on the type of socket that the message is received from -- see socket().
If no messages are available at the socket, the receive call waits for a message to arrive, unless the socket is nonblocking -- see ioctl() -- in which case -1 is returned and the external variable errno is set to EWOULDBLOCK. Normally, the receive calls return any data available, up to the requested amount, rather than wait for the full amount requested; this behavior is affected by the socket-level options SO_RCVLOWAT and SO_RCVTIMEO described in getsockopt().
The select() call may be used to determine when more data is to arrive.
The flags argument is formed by "ORing" one or more of the values:
![]() |
The MSG_WAITALL flag isn't supported by the tiny TCP/IP stack. For more information, see the npm-ttcpip.so interface in the Utilities reference. |
The number of bytes received, or -1 if an error occurs (errno is set).
Standard Unix, POSIX 1003.1g (draft)
Safety: | |
---|---|
Cancellation point | Yes |
Interrupt handler | No |
Signal handler | No |
Thread | Yes |
![]() |
![]() |
![]() |