-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
std.posix: adding getsockopt #22335
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
std.posix: adding getsockopt #22335
Conversation
Hi @alexrp I made the changes you suggested above. |
Okay, so I made a patch moving from opaque pointers: pub fn getsockopt(fd: socket_t, level: i32, optname: u32, noalias optval: ?*anyopaque, noalias optlen: *socklen_t) GetSockOptError!void { to slices: pub fn getsockopt(fd: socket_t, level: i32, optname: u32, opt: []u8) GetSockOptError!void { And to use it, you do this var bytes = std.mem.toBytes(@as(c_int, 0));
try std.posix.getsockopt(socket, std.posix.SOL.SOCKET, std.posix.SO.SNDBUF, &bytes);
std.debug.print("send buffer size: {}\n", .{std.mem.bytesToValue(c_int, &bytes)}); I dunno if I like it, although it is a safer interface maybe. It almost feels like it would be nicer to do something like passing the type in, but probably doesn't work for all sockopts const size = try std.posix.getsockopt(socket, std.posix.SOL.SOCKET, std.posix.SO.SNDBUF, c_int); |
There's definitely room for discussion around |
CI is failing due to formatting issues. |
@alexrp ok i pushed a zig fmt patch, CI is restarting, thank you. |
I noticed that
std.posix.setsockopt
exists but notstd.posix.getsockopt
.I tried to add it, but I'm not sure if the anyopaque / optlen approach is a good one.
https://linux.die.net/man/3/getsockopt