recvmsg

Receives bytes on a socket and places them into scattered buffers..

Format

#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.

Arguments

s
A socket descriptor that has been created with socket.
msg
A msghdr structure. See <socket.h> for a description of the msghdr structure.
flags
A bit mask that may contain one or more of MSG_OOB and MSG_ PEEK. It is built by ORing the appropriate values together.

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.

Description

This routine may be used with any socket, whether it is in a connected state or not. It receives data sent by a call to sendmsg, send, or sendto. The message is scattered into several user buffers if such buffers are specified.

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.

Return Values
The number of bytes returned in the msg_iov buffers. 
-1  Indicates an error; errno is set to one of the following values:

  • EBADF - The socket descriptor is invalid.

  • ENOTSOCK - The socket descriptor references a file, not a socket.

  • EPIPE - An attempt was made to write to a socket that is not open for reading by any process.

  • EWOULDBLOCK - The NBIO (nonblocking) flag is set for the socket descriptor and the process would be delayed in the write operation.

  • EINTR - The receive was interrupted by delivery of a signal before any data was available for the receive.

  • EFAULT - The data was specified to be received into a non-existent or protected part of the process address space.
 


Previous Page | Next Page | Table of Contents | Index