Go to main content

man pages section 3: Basic Library Functions

Exit Print View

Updated: Wednesday, July 27, 2022
 
 

recvmmsg(3C)

Name

recvmmsg - receive multiple messages from a socket

Synopsis

#include <sys/socket.h>

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

Parameters

s

The socket descriptor. For more information, see the socket(3C) man page.

msgvec

Pointer to an array of mmsghdr structures

vlen

The number of elements in the array of mmsghdr structures

flags

Flags for receiving as in the recvmsg(3C) function. In addition the following flag is defined:

MSG_WAITFORONE

Turns on MSG_DONTWAIT after the first message has been received.

timeout

Pointer to a struct timespec defining a timeout for the receive operation. The specified timeout is subjected to rounding, based on system clock resolution.

Description

The recvmmsg() function is an extension to the recvmsg(3C) function that allows the caller to receive multiple messages on a socket in a single invocation.

A blocking recvmmsg() function call blocks until the vlen messages have been received or until the timeout expires. A non-blocking call receives as many messages as possible, up to vlen, and returns immediately.

The mmsghdr structure is defined as:

struct mmsghdr {
    struct msghdr   msg_hdr;  /* Message header */
    ssize_t         msg_len;  /* Number of bytes received */
};
msg_hdr

msghdr structure as described in socket.h(3HEAD)

msg_len

Is used to return the number of bytes received in the message described in the msg_hdr. This is equivalent to the return value from a single recvmsg() function call.

The contents of the msghdr structure differ depending on whether or not __USE_SUNOS_SOCKETS__ is defined before including the <sys/socket.h> header. All source files accessing msghdr structures or calling the recvmmsg() function must be compiled with either __USE_SUNOS_SOCKETS__ defined or all with it undefined — mixing and matching will not work. See the socket.h(3HEAD) manual page for details.

Return Values

Upon successful completion, the recvmmsg() function returns the number of messages received. The number of bytes received is the arithmetic sum of the msg_len members of each valid mmsghdr structure.

The function returns -1 if an error occurs and errno is set to indicate the error.

Errors

Errors are the same as per the recvmsg() function. In addition, the following error is also returned:

EINVAL

The timeout argument is invalid

For more information, see the recvmsg(3C) man page.

Attributes

See attributes(7) for descriptions of the following attributes:

ATTRIBUTE TYPE
ATTRIBUTE VALUE
Interface Stability
Committed
MT-Level
Async-Signal-Safe

See Also

fcntl(2), poll(2), sendmmsg(3C), select(3C), socket(3C), recvmsg(3C), socket.h(3HEAD), attributes(7)

History

The recvmmsg() function was added to Oracle Solaris in the 11.3 SRU 32 release.