Reads a message from a socket and stores it in a message structure.
(IN) Specifies the socket file handle from which data is to be read.
(IN/OUT) Points to message and buffer address information.
(IN) Specifies the type of message reception. See Message Types.
If successful, returns the number of bytes received. If no message is available and the peer has performed an orderly shutdown, returns 0. Otherwise, returns -1 and sets errno to one of the following:
The recvmsg function is normally used with connectionless sockets because the application can retrieve the source address of the received data.
From a message-based socket, such as a SOCK_DGRAM socket, the entire message is read in a single operation. If a message is too long to fit in the supplied buffer, and MSG_PEEK is not set in the flags argument, the excess bytes are discarded.
From a stream-based socket, such as a SOCK_STREAM socket, data is returned to a user as soon as it is available and no data is discarded.
If data is not available at the socket, one of the following occurs:
If the O_NONBLOCK flag is not set on the socket handle, the recvmsg function blocks.
If the socket is nonblocking because the O_NONBLOCK flag is set on the socket handle, recvmsg returns -1 and sets errno to EWOULDBLOCK.
Call select to determine when more data arrives.
MSG_OOB is used only with TCP sockets. MSG_OOB actually refers to the byte of data following a TCP urgent boundary. After the socket client has discovered new out-of-band data (by calling select for exceptions) and has read normal data up to the out-of-band byte, it reads one byte of out-of-band data by setting the MSG_OOB flag.
MSG_PEEK permits the socket client to look at a message or STREAM data without removing it from the socket.