Receives bytes on a socket and places them into scattered buffers..
#include <socket.h> int recvmsg (int s, struct msghdr msg[], int flags);Routine Variants This socket routine has a variant named __bsd44_recvmsg. Enabled by defining _SOCKADDR_LEN, this variant implements 4.4BSD-compatible semantics. See Section A.7 for more information.
The MSG_OOB flag allows out-of-band data to be received. If out-of- band data is availiable, it will be read before any normal data that is available. If no out-of-band data is available, the MSG_OOB flag is ignored. Out-of-band data can be sent using send, sendmsg, and sendto.
The MSG_PEEK flag allows you to peek at the data that is next in line to be received without actually removing it from the system's buffers.
To receive data, the socket need not be connected to another socket.
When the iovec[iovcnt] array specifies more than one buffer, the input data is scattered into iovcnt buffers as specified by the members of the iovec array:
iov[0], iov[1], ..., iov[iovcnt]
When a message is received, it is split among the buffers by filling the first buffer in the list, then the second, and so on, until either all of the buffers are full or there is no more data to be placed in the buffers.
When a message is sent, the first buffer is copied to a system buffer and then the second buffer is copied, followed by the third buffer and so on, until all the buffers are copied. After the data is copied, the protocol will send the data to the remote host at the appropriate time, depending upon the protocol.
You may use the select routine to determine when more data arrives.
See also read, send, and socket in this section.
x | The number of bytes returned in the msg_iov buffers. |
-1 | Indicates an error; errno is set to one of the following values:
|