Skip to content

std.posix: recvmsg #24603

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions lib/std/posix.zig
Original file line number Diff line number Diff line change
Expand Up @@ -6577,6 +6577,36 @@ pub fn recvfrom(
}
}

pub const RecvMsgError = error{
InputOutput,
} || RecvFromError;

pub fn recvmsg(sockfd: socket_t, msg: *msghdr, flags: u32) RecvMsgError!usize {
while (true) {
const rc = system.recvmsg(sockfd, msg, flags);
switch (errno(rc)) {
.SUCCESS => return @intCast(rc),

.AGAIN => return error.WouldBlock,
.CONNREFUSED => return error.ConnectionRefused,
.CONNRESET => return error.ConnectionResetByPeer,
.IO => return error.InputOutput,
.MSGSIZE => return error.MessageTooBig,
.NOBUFS => return error.SystemResources,
.NOMEM => return error.SystemResources,
.NOTCONN => return error.SocketNotConnected,
.TIMEDOUT => return error.ConnectionTimedOut,
.INTR => continue,
.BADF => unreachable,
.FAULT => unreachable,
.INVAL => unreachable,
.NOTSOCK => unreachable, // the socket descriptor does not refer to a socket
.OPNOTSUPP => unreachable, // Some bit in the flags argument is inappropriate for the socket type.
else => |err| return unexpectedErrno(err),
}
}
}

pub const DnExpandError = error{InvalidDnsPacket};

pub fn dn_expand(
Expand Down