authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2026-01-07 14:49:00-08:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2026-01-07 17:33:07-08:00
log829afe98d16d72a9a3af3ae30622ce6576c8b27f
tree51844be7b45897cd447a5a0aa78b1303f08e35bc
parent02c260dd06988f6acd8a1cbfbacb306d9c367ced

std.posix: remove getsockopt, getsockoptError

see #6600

1 files changed, 0 insertions(+), 65 deletions(-)

lib/std/posix.zig-65
...@@ -773,71 +773,6 @@ pub fn connect(sock: socket_t, sock_addr: *const sockaddr, len: socklen_t) Conne...@@ -773,71 +773,6 @@ pub fn connect(sock: socket_t, sock_addr: *const sockaddr, len: socklen_t) Conne
773 }773 }
774}774}
775775
776pub const GetSockOptError = error{
777 /// The calling process does not have the appropriate privileges.
778 AccessDenied,
779
780 /// The option is not supported by the protocol.
781 InvalidProtocolOption,
782
783 /// Insufficient resources are available in the system to complete the call.
784 SystemResources,
785} || UnexpectedError;
786
787pub fn getsockopt(fd: socket_t, level: i32, optname: u32, opt: []u8) GetSockOptError!void {
788 var len: socklen_t = @intCast(opt.len);
789 switch (errno(system.getsockopt(fd, level, optname, opt.ptr, &len))) {
790 .SUCCESS => {
791 std.debug.assert(len == opt.len);
792 },
793 .BADF => unreachable,
794 .NOTSOCK => unreachable,
795 .INVAL => unreachable,
796 .FAULT => unreachable,
797 .NOPROTOOPT => return error.InvalidProtocolOption,
798 .NOMEM => return error.SystemResources,
799 .NOBUFS => return error.SystemResources,
800 .ACCES => return error.AccessDenied,
801 else => |err| return unexpectedErrno(err),
802 }
803}
804
805pub fn getsockoptError(sockfd: fd_t) ConnectError!void {
806 var err_code: i32 = undefined;
807 var size: u32 = @sizeOf(u32);
808 const rc = system.getsockopt(sockfd, SOL.SOCKET, SO.ERROR, @ptrCast(&err_code), &size);
809 assert(size == 4);
810 switch (errno(rc)) {
811 .SUCCESS => switch (@as(E, @enumFromInt(err_code))) {
812 .SUCCESS => return,
813 .ACCES => return error.AccessDenied,
814 .PERM => return error.PermissionDenied,
815 .ADDRINUSE => return error.AddressInUse,
816 .ADDRNOTAVAIL => return error.AddressUnavailable,
817 .AFNOSUPPORT => return error.AddressFamilyUnsupported,
818 .AGAIN => return error.SystemResources,
819 .ALREADY => return error.ConnectionPending,
820 .BADF => unreachable, // sockfd is not a valid open file descriptor.
821 .CONNREFUSED => return error.ConnectionRefused,
822 .FAULT => unreachable, // The socket structure address is outside the user's address space.
823 .ISCONN => return error.AlreadyConnected, // The socket is already connected.
824 .HOSTUNREACH => return error.NetworkUnreachable,
825 .NETUNREACH => return error.NetworkUnreachable,
826 .NOTSOCK => unreachable, // The file descriptor sockfd does not refer to a socket.
827 .PROTOTYPE => unreachable, // The socket type does not support the requested communications protocol.
828 .TIMEDOUT => return error.Timeout,
829 .CONNRESET => return error.ConnectionResetByPeer,
830 else => |err| return unexpectedErrno(err),
831 },
832 .BADF => unreachable, // The argument sockfd is not a valid file descriptor.
833 .FAULT => unreachable, // The address pointed to by optval or optlen is not in a valid part of the process address space.
834 .INVAL => unreachable,
835 .NOPROTOOPT => unreachable, // The option is unknown at the level indicated.
836 .NOTSOCK => unreachable, // The file descriptor sockfd does not refer to a socket.
837 else => |err| return unexpectedErrno(err),
838 }
839}
840
841pub const FStatError = std.Io.File.StatError;776pub const FStatError = std.Io.File.StatError;
842777
843/// Return information about a file descriptor.778/// Return information about a file descriptor.