I am on Windows 11
const std = @import("std");
const builtin = @import("builtin");
const fs = std.fs;
const net = std.net;
const is_windows = builtin.os.tag == .windows;
pub fn main() !void {
std.debug.print("START\n", .{});
if (!net.has_unix_sockets) {
std.debug.print("This system does not support Unix domain sockets\n", .{});
std.process.exit(1);
}
// var gpa = std.heap.GeneralPurposeAllocator(.{}){};
// defer _ = gpa.deinit();
// const allocator = gpa.allocator();
const socket_path = if (is_windows)
"\\\\.\\pipe\\example-socket"
else
"/tmp/example.sock";
std.debug.print("get addr\n", .{});
const address = try net.Address.initUnix(socket_path);
// std.debug.print("unix socket addr: {s}\n", .{address.path});
std.debug.print("listen call\n", .{});
var srv = try address.listen(.{
//.kernel_backlog = 2,
// .reuse_address = true,
// .reuse_port = true,
//.force_nonblocking = true,
});
if (!is_windows) {
fs.deleteFileAbsolute(socket_path) catch |err| {
if (err != error.FileNotFound) {
return err;
}
};
}
srv.deinit();
std.debug.print("LISTENING\n", .{});
}
output
PS C:\Users\pseud\zigzog> zig build
PS C:\Users\pseud\zigzog> .\zig-out\bin\zigzog.exe
START
get addr
listen call
error: NetworkSubsystemFailed
C:\Users\pseud\zig\lib\std\posix.zig:3645:33: 0xdf3b15 in bind (zigzog.exe.obj)
.WSAENETDOWN => return error.NetworkSubsystemFailed,
^
C:\Users\pseud\zig\lib\std\net.zig:263:9: 0xdf1dcc in listen (zigzog.exe.obj)
try posix.bind(sockfd, &address.any, socklen);
^
C:\Users\pseud\zigzog\src\main.zig:51:15: 0xdf14c2 in main (zigzog.exe.obj)
var srv = try address.listen(.{
wth ? Why ? I don't get this..