Receive multiple messages and their headers from a socket


#include <sys/types.h>
#include <sys/socket.h>

int recvmmsg( int s,
              struct mmsghdr *mmsg,
              unsigned int vlen,
              unsigned int flags,
              struct timespec *timeout );


The descriptor for the socket; see socket().
A pointer to an array of mmsghdr structures where the function can store the message headers; see below.
The length of the mmsg array; limited to 1024 elements.
A bitwise OR of zero or more of the following:
  • MSG_OOB — process out-of-band data. This flag requests receipt of out-of-band data that wouldn't be received in the normal data stream. You can't use this flag with protocols that place expedited data at the head of the normal data queue.
  • MSG_PEEK — peek at the incoming message. This flag causes the receive operation to return data from the beginning of the receive queue without removing that data from the queue. Thus, a subsequent receive call will return the same data.
  • MSG_WAITALL — wait for full request or error. This flag requests that the operation block until the full request is satisfied. But the call may still return less data than requested if a signal is caught, if an error or disconnect occurs, or if the next data to be received is of a different type than that returned.
The length of time to wait for messages to be received, after which recvmmsg() returns.



Use the -l socket option to qcc to link against this library.


The recvmmsg() function receives multiple messages from a socket, s, whether or not it's connection-oriented.

The recvmmsg() function uses a mmsghdr structure to minimize the number of directly supplied parameters. This structure is defined in <sys/socket.h> as follows:

struct mmsghdr {
    struct msghdr   msg_hdr; /* the message to be sent */
    unsigned int    msg_len; /* number of bytes transmitted */

The msg_len member contains the number of bytes sent for each msg_hdr member. The array has vlen elements, but if there's an error, a number fewer than vlen may be returned. For a description of the msghdr structure, see recvmsg().


The number of messages received, or -1 if an error occurs (errno is set).


Not enough memory.



Cancellation point Yes
Interrupt handler No
Signal handler No
Thread Yes