Function recvmsg [src]
Prototype
pub fn recvmsg( sockfd: socket_t, msg: *msghdr, flags: u32, ) RecvMsgError!usize Parameters
sockfd: socket_tThe file descriptor of the sending socket.
msg: *msghdrMessage header and iovecs
flags: u32 Possible Errors
The other end closed the socket unexpectedly or a read is executed on a shut down socket
A remote host refused to allow the network connection, typically because it is not running the requested service.
The UDP message was too big for the buffer and part of it has been discarded
The network subsystem has failed.
Reception of SCM_RIGHTS fds via ancillary data in msg.control would exceed some process limit (generally this is retryable by trying to receive fewer fds, closing some existing fds, or changing the ulimit)
The socket has not been bound.
The socket is not connected (connection-oriented sockets only).
Reception of SCM_RIGHTS fds via ancillary data in msg.control would exceed some system limit (generally this is retryable by trying to receive fewer fds or closing some existing fds)
Could not allocate kernel memory.
The Operating System returned an undocumented error code.
This error is in theory not possible, but it would be better to handle this error than to invoke undefined behavior.
When this error code is observed, it usually means the Zig Standard Library needs a small patch to add the error code to the error set for the respective function.
The socket is marked nonblocking and the requested operation would block, and there is no global event loop configured.
Source
pub fn recvmsg(
/// The file descriptor of the sending socket.
sockfd: socket_t,
/// Message header and iovecs
msg: *msghdr,
flags: u32,
) RecvMsgError!usize {
if (@TypeOf(system.recvmsg) == void)
@compileError("recvmsg() not supported on this OS");
while (true) {
const rc = system.recvmsg(sockfd, msg, flags);
switch (errno(rc)) {
.SUCCESS => return @intCast(rc),
.AGAIN => return error.WouldBlock,
.BADF => unreachable, // always a race condition
.NFILE => return error.SystemFdQuotaExceeded,
.MFILE => return error.ProcessFdQuotaExceeded,
.INTR => continue,
.FAULT => unreachable, // An invalid user space address was specified for an argument.
.INVAL => unreachable, // Invalid argument passed.
.ISCONN => unreachable, // connection-mode socket was connected already but a recipient was specified
.NOBUFS => return error.SystemResources,
.NOMEM => return error.SystemResources,
.NOTCONN => return error.SocketNotConnected,
.NOTSOCK => unreachable, // The file descriptor sockfd does not refer to a socket.
.MSGSIZE => return error.MessageTooBig,
.PIPE => return error.BrokenPipe,
.OPNOTSUPP => unreachable, // Some bit in the flags argument is inappropriate for the socket type.
.CONNRESET => return error.ConnectionResetByPeer,
.NETDOWN => return error.NetworkSubsystemFailed,
else => |err| return unexpectedErrno(err),
}
}
}