Receive multiple messages and their headers from a
socket
Synopsis:
#include <sys/types.h>
#include <sys/socket.h>
int recvmmsg( int s,
struct mmsghdr * mmsg,
unsigned int vlen,
unsigned int flags,
struct timespec * timeout );
Arguments:
-
s
- The descriptor for the socket; see
socket()
.
-
mmsg
- A pointer to an array of mmsghdr structures where the function can store the message
headers; see below.
-
vlen
- The length of the mmsg array; limited to
1024 elements.
-
flags
- A combination formed by ORing one or more of the values:
-
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.
-
timeout
- The length of time to wait for messages to be received, after which
recvmmsg() returns.
Library:
libsocket
Use the -l socket option to
qcc
to link against this library.
Description:
The recvmmsg() function receives
multiple messages from a socket, s, whether or
not it's connection-oriented.
The recvmmsg() call uses a mmsghdr structure to minimize the number of directly
supplied parameters. This structure, defined in <sys/socket.h>, has the following form:
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 is an error, a number fewer than vlen may
be returned. For a description of the msghdr
structure, see
recvmsg()
.
Returns:
The number of messages received, or -1 if an error occurs (
errno
is set).
Errors:
-
ENOMEM
- Not enough memory.
Classification:
Unix
| Safety: |
|
| Cancellation point |
Yes |
| Interrupt handler |
No |
| Signal handler |
No |
| Thread |
Yes |