std.os.setsockopt appears to be broken when compiling with libc.
Example:
usingnamespace @import("std");
pub fn main() !void {
const fd = try os.socket(os.AF_INET, os.SOCK_STREAM, 0);
_ = try os.setsockopt(fd, os.SOL_SOCKET, os.SO_REUSEADDR, &mem.toBytes(@as(c_int, 1)));
// The same bug breaks StreamServer:
var server = net.StreamServer.init(.{});
try server.listen(try net.Address.parseIp4("127.0.0.1", 12345));
}
This compiles fine with zig build-exe main.zig but gives the following error when compiling with --library c:
/nix/store/syj90d418f63szyinbklp69zvv10v8qy-zig-5acc8afb5f9674b9b7b290635e9c2837872b8a93/lib/zig/std/os.zig:4228:60: error: cast discards const qualifier
switch (errno(system.setsockopt(fd, level, optname, opt.ptr, @intCast(socklen_t, opt.len)))) {
^
I got around this issue by removing the const qualifier in my copy of the standard library:
- pub fn setsockopt(fd: fd_t, level: u32, optname: u32, opt: []const u8) SetSockOptError!void {
+ pub fn setsockopt(fd: fd_t, level: u32, optname: u32, opt: []u8) SetSockOptError!void {
I'm not sure if that's an ok fix though so I did not open a PR.
std.os.setsockoptappears to be broken when compiling with libc.Example:
This compiles fine with
zig build-exe main.zigbut gives the following error when compiling with--library c:I got around this issue by removing the const qualifier in my copy of the standard library:
I'm not sure if that's an ok fix though so I did not open a PR.