sendmmsg Subroutine
Purpose
Sends multiple messages from a socket by using a message structure.
Syntax
#include <sys/types.h>
#include <sys/socketvar.h>
#include <sys/socket.h>
int sendmmsg (Socket, Messages, Flags)
int Socket;
struct mmsghdr Message [];
int Flags;
Description
The sendmmsg subroutine sends messages through the connected or unconnected
sockets by using the mmsghdr
message structure. The
/usr/include/sys/socket.h file contains the mmsghdr
message
structure and defines the structure members. This subroutine is an extension to the
sendmsg subroutine.
Parameters
- Socket
- Specifies the socket descriptor.
- Messages
- Points to an array of
mmsghdr
message structures that contain the messages to be sent. - Flags
- Allows the sender to control the message transmission. The Flags parameter that is used to send a call is formed by logically ORing the flag values. The sendmmsg subroutine accepts the same flag values as the sendmsg subroutine. The sys/socket.h file contains the Flags parameter.
Return values
Upon successful completion, the sendmmsg subroutine returns the number of sent messages.
The sendmmsg subroutine updates the msg_len attribute of
each mmsghdr
structure to indicate the number of bytes that are sent from the
corresponding message.
If the sendmmsg subroutine is unsuccessful, the system handler performs the following functions:
- Returns a value of -1 to the calling program.
- Moves an error code, which indicates the specific error, into the errno global variable.
Error codes
The sendmmsg subroutine is unsuccessful if any of the following errors occur:
Error | Description |
---|---|
EACCES | Write access to the named socket is denied, or the socket that is trying to send a broadcast packet does not have the broadcast capability. |
EADDRNOTAVAIL | The specified address is not a valid address. |
EAFNOSUPPORT | The specified address is not a valid address for the address family of the socket. |
EBADF | The Socket parameter is not valid. |
ECONNRESET | A connection was forcibly closed by a peer. |
EDESTADDRREQ | The socket is not in connection-mode and does not have its peer address set. |
EFAULT | The Address parameter is not in a writable part of the user address space. |
EHOSTUNREACH | The destination host cannot be reached. |
EINTR | A signal interrupted the sendmmsg subroutine before any data was transmitted. |
EINVAL | The length of the msghdr structure is invalid. |
EISCONN | The SOCK_DGRAM socket is already connected. |
EMSGSIZE | The message is too large to be sent together (as per the socket requirement), or the
msg_iovlen member of the msghdr structure pointed to by the
Messages parameter is less than or equal to 0 or is greater than the
IOV_MAX value. |
ENOENT | The path name does not point an existing file, or the path name is an empty string. |
ENETUNREACH | The destination network is not reachable. |
ENOBUFS | The system ran out of memory for an internal data structure. |
ENOMEM | The available data space in memory is not large enough to hold group information or access control list (ACL) information. |
ENOPROTOOPT | The protocol does not support 64 bits. |
ENOTCONN | The socket is in connection-mode but is not connected. |
ENOTSOCK | The Socket parameter refers to a file, not a socket. |
EOPNOTSUPP | The Socket argument is associated with a socket that does not support one or more of the values that are set in the Flags parameter. |
EPIPE | An attempt was made to send on a socket that was connected, but the connection is shut down either by the remote peer or by the socket side of the connection. If the socket is of type SOCK_STREAM, the SIGPIPE signal is generated to the calling process. |
EWOULDBLOCK | The socket is marked as nonblocking , and no connections are present to be
accepted. |