authorgravatar for mrjbq7@gmail.comJohn Benediktsson <mrjbq7@gmail.com> 2025-01-30 08:09:29-08:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2025-01-30 16:09:29+00:00
log53598e36e8fd51a4bb0c97ae560a25f5c343b478
treec89ad56bced3e93f2b852a1e0e874a4689ef6118
parentc0d85cda53fd9ea056641d5e91cc8f736b34c0e7
signaturebadge-check Signed by PGP key B5690EEEBB952194

std.posix: adding getsockopt (#22335)


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

lib/std/posix.zig+29
...@@ -4276,6 +4276,35 @@ pub fn connect(sock: socket_t, sock_addr: *const sockaddr, len: socklen_t) Conne...@@ -4276,6 +4276,35 @@ pub fn connect(sock: socket_t, sock_addr: *const sockaddr, len: socklen_t) Conne
4276 }4276 }
4277}4277}
42784278
4279pub const GetSockOptError = error{
4280 /// The calling process does not have the appropriate privileges.
4281 AccessDenied,
4282
4283 /// The option is not supported by the protocol.
4284 InvalidProtocolOption,
4285
4286 /// Insufficient resources are available in the system to complete the call.
4287 SystemResources,
4288} || UnexpectedError;
4289
4290pub fn getsockopt(fd: socket_t, level: i32, optname: u32, opt: []u8) GetSockOptError!void {
4291 var len: socklen_t = undefined;
4292 switch (errno(system.getsockopt(fd, level, optname, opt.ptr, &len))) {
4293 .SUCCESS => {
4294 std.debug.assert(len == opt.len);
4295 },
4296 .BADF => unreachable,
4297 .NOTSOCK => unreachable,
4298 .INVAL => unreachable,
4299 .FAULT => unreachable,
4300 .NOPROTOOPT => return error.InvalidProtocolOption,
4301 .NOMEM => return error.SystemResources,
4302 .NOBUFS => return error.SystemResources,
4303 .ACCES => return error.AccessDenied,
4304 else => |err| return unexpectedErrno(err),
4305 }
4306}
4307
4279pub fn getsockoptError(sockfd: fd_t) ConnectError!void {4308pub fn getsockoptError(sockfd: fd_t) ConnectError!void {
4280 var err_code: i32 = undefined;4309 var err_code: i32 = undefined;
4281 var size: u32 = @sizeOf(u32);4310 var size: u32 = @sizeOf(u32);