commit 829afe98d16d72a9a3af3ae30622ce6576c8b27f (tree)
parent 02c260dd06988f6acd8a1cbfbacb306d9c367ced
Author: Andrew Kelley <andrew@ziglang.org>
Date: Wed, 7 Jan 2026 14:49:00 -0800
std.posix: remove getsockopt, getsockoptError
see #6600
Diffstat:
| M | lib/std/posix.zig | | | 65 | ----------------------------------------------------------------- |
1 file changed, 0 insertions(+), 65 deletions(-)
diff --git a/lib/std/posix.zig b/lib/std/posix.zig
@@ -773,71 +773,6 @@ pub fn connect(sock: socket_t, sock_addr: *const sockaddr, len: socklen_t) Conne
}
}
-pub const GetSockOptError = error{
- /// The calling process does not have the appropriate privileges.
- AccessDenied,
-
- /// The option is not supported by the protocol.
- InvalidProtocolOption,
-
- /// Insufficient resources are available in the system to complete the call.
- SystemResources,
-} || UnexpectedError;
-
-pub fn getsockopt(fd: socket_t, level: i32, optname: u32, opt: []u8) GetSockOptError!void {
- var len: socklen_t = @intCast(opt.len);
- switch (errno(system.getsockopt(fd, level, optname, opt.ptr, &len))) {
- .SUCCESS => {
- std.debug.assert(len == opt.len);
- },
- .BADF => unreachable,
- .NOTSOCK => unreachable,
- .INVAL => unreachable,
- .FAULT => unreachable,
- .NOPROTOOPT => return error.InvalidProtocolOption,
- .NOMEM => return error.SystemResources,
- .NOBUFS => return error.SystemResources,
- .ACCES => return error.AccessDenied,
- else => |err| return unexpectedErrno(err),
- }
-}
-
-pub fn getsockoptError(sockfd: fd_t) ConnectError!void {
- var err_code: i32 = undefined;
- var size: u32 = @sizeOf(u32);
- const rc = system.getsockopt(sockfd, SOL.SOCKET, SO.ERROR, @ptrCast(&err_code), &size);
- assert(size == 4);
- switch (errno(rc)) {
- .SUCCESS => switch (@as(E, @enumFromInt(err_code))) {
- .SUCCESS => return,
- .ACCES => return error.AccessDenied,
- .PERM => return error.PermissionDenied,
- .ADDRINUSE => return error.AddressInUse,
- .ADDRNOTAVAIL => return error.AddressUnavailable,
- .AFNOSUPPORT => return error.AddressFamilyUnsupported,
- .AGAIN => return error.SystemResources,
- .ALREADY => return error.ConnectionPending,
- .BADF => unreachable, // sockfd is not a valid open file descriptor.
- .CONNREFUSED => return error.ConnectionRefused,
- .FAULT => unreachable, // The socket structure address is outside the user's address space.
- .ISCONN => return error.AlreadyConnected, // The socket is already connected.
- .HOSTUNREACH => return error.NetworkUnreachable,
- .NETUNREACH => return error.NetworkUnreachable,
- .NOTSOCK => unreachable, // The file descriptor sockfd does not refer to a socket.
- .PROTOTYPE => unreachable, // The socket type does not support the requested communications protocol.
- .TIMEDOUT => return error.Timeout,
- .CONNRESET => return error.ConnectionResetByPeer,
- else => |err| return unexpectedErrno(err),
- },
- .BADF => unreachable, // The argument sockfd is not a valid file descriptor.
- .FAULT => unreachable, // The address pointed to by optval or optlen is not in a valid part of the process address space.
- .INVAL => unreachable,
- .NOPROTOOPT => unreachable, // The option is unknown at the level indicated.
- .NOTSOCK => unreachable, // The file descriptor sockfd does not refer to a socket.
- else => |err| return unexpectedErrno(err),
- }
-}
-
pub const FStatError = std.Io.File.StatError;
/// Return information about a file descriptor.