This version of this document is no longer maintained. For the latest documentation, see http://www.qnx.com/developers/docs. |
Receive a message from a socket
#include <sys/types.h> #include <sys/socket.h> ssize_t recv( int s, void * buf, size_t len, int flags );
The MSG_WAITALL flag isn't supported by the tiny TCP/IP stack. For more information, see npm-ttcpip.so in the Utilities Reference. |
libsocket
Use the -l socket option to qcc to link against this library.
The recv() function receives a message from a socket. It's normally used only on a connected socket -- see connect() -- and is identical to recvfrom() with a zero from parameter.
This routine returns the length of the message on successful completion. If a message is too long for the supplied buffer, buf, then excess bytes might 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().
You can use select() to determine when more data is to arrive.
The number of bytes received, or -1 if an error occurs (errno is set).
Safety: | |
---|---|
Cancellation point | Yes |
Interrupt handler | No |
Signal handler | No |
Thread | Yes |
connect(), ioctl(), getsockopt(), read(), recvfrom(), recvmsg(), select(), socket()