zig

fork of https://codeberg.org/ziglang/zig
Log | Files | Refs | README | LICENSE

commit cbd75b484f783e4b388ef4b0fb3662fb4c43bbfa (tree)
parent d96d7353387e10a2306f05d98955ac22db6e89e7
Author: Andrew Kelley <andrew@ziglang.org>
Date:   Wed,  7 Jan 2026 15:08:00 -0800

std.posix: remove recvfrom, recvmsg

see #6600

Diffstat:
Mlib/std/posix.zig | 133-------------------------------------------------------------------------------
1 file changed, 0 insertions(+), 133 deletions(-)

diff --git a/lib/std/posix.zig b/lib/std/posix.zig @@ -1608,139 +1608,6 @@ pub fn ppoll(fds: []pollfd, timeout: ?*const timespec, mask: ?*const sigset_t) P } } -pub const RecvFromError = error{ - /// The socket is marked nonblocking and the requested operation would block, and - /// there is no global event loop configured. - WouldBlock, - - /// A remote host refused to allow the network connection, typically because it is not - /// running the requested service. - ConnectionRefused, - - /// Could not allocate kernel memory. - SystemResources, - - ConnectionResetByPeer, - Timeout, - - /// The socket has not been bound. - SocketNotBound, - - /// The UDP message was too big for the buffer and part of it has been discarded - MessageOversize, - - /// The network subsystem has failed. - NetworkDown, - - /// The socket is not connected (connection-oriented sockets only). - SocketUnconnected, - - /// The other end closed the socket unexpectedly or a read is executed on a shut down socket - BrokenPipe, -} || UnexpectedError; - -pub fn recv(sock: socket_t, buf: []u8, flags: u32) RecvFromError!usize { - return recvfrom(sock, buf, flags, null, null); -} - -/// If `sockfd` is opened in non blocking mode, the function will -/// return error.WouldBlock when EAGAIN is received. -pub fn recvfrom( - sockfd: socket_t, - buf: []u8, - flags: u32, - src_addr: ?*sockaddr, - addrlen: ?*socklen_t, -) RecvFromError!usize { - while (true) { - const rc = system.recvfrom(sockfd, buf.ptr, buf.len, flags, src_addr, addrlen); - if (native_os == .windows) { - if (rc == windows.ws2_32.SOCKET_ERROR) { - switch (windows.ws2_32.WSAGetLastError()) { - .NOTINITIALISED => unreachable, - .ECONNRESET => return error.ConnectionResetByPeer, - .EINVAL => return error.SocketNotBound, - .EMSGSIZE => return error.MessageOversize, - .ENETDOWN => return error.NetworkDown, - .ENOTCONN => return error.SocketUnconnected, - .EWOULDBLOCK => return error.WouldBlock, - .ETIMEDOUT => return error.Timeout, - // TODO: handle more errors - else => |err| return windows.unexpectedWSAError(err), - } - } else { - return @intCast(rc); - } - } else { - switch (errno(rc)) { - .SUCCESS => return @intCast(rc), - .BADF => unreachable, // always a race condition - .FAULT => unreachable, - .INVAL => unreachable, - .NOTCONN => return error.SocketUnconnected, - .NOTSOCK => unreachable, - .INTR => continue, - .AGAIN => return error.WouldBlock, - .NOMEM => return error.SystemResources, - .CONNREFUSED => return error.ConnectionRefused, - .CONNRESET => return error.ConnectionResetByPeer, - .TIMEDOUT => return error.Timeout, - .PIPE => return error.BrokenPipe, - else => |err| return unexpectedErrno(err), - } - } - } -} - -pub const RecvMsgError = RecvFromError || error{ - /// 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) - SystemFdQuotaExceeded, - - /// 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) - ProcessFdQuotaExceeded, -}; - -/// If `sockfd` is opened in non blocking mode, the function will -/// return error.WouldBlock when EAGAIN is received. -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.SocketUnconnected, - .NOTSOCK => unreachable, // The file descriptor sockfd does not refer to a socket. - .MSGSIZE => return error.MessageOversize, - .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.NetworkDown, - else => |err| return unexpectedErrno(err), - } - } -} - pub const SetSockOptError = error{ /// The socket is already connected, and a specified option cannot be set while the socket is connected. AlreadyConnected,