feature. See also
. The project being documented here (as the example) is the Zig library itself.
Threaded.netListenIpWindows
fn netListenIpWindows(
userdata: ?*anyopaque,
address: *const IpAddress,
options: IpAddress.ListenOptions,
) IpAddress.ListenError!net.Socket
File
Code
fn netListenIpWindows(
userdata: ?*anyopaque,
address: *const IpAddress,
options: IpAddress.ListenOptions,
) IpAddress.ListenError!net.Socket {
if (!have_networking) return error.NetworkDown;
const t: *Threaded = @ptrCast(@alignCast(userdata));
_ = t;
const family = posixAddressFamily(address);
const socket_handle = try openSocketAfd(family, .{ .mode = options.mode, .protocol = options.protocol });
errdefer windows.CloseHandle(socket_handle);
if (options.reuse_address) try setSocketOptionAfd(socket_handle, ws2_32.SOL.SOCKET, ws2_32.SO.REUSEADDR, true);
const bound_address = try bindSocketIpAfd(socket_handle, address, .Passive);
switch ((try deviceIoControl(&.{
.file = .{ .handle = socket_handle, .flags = .{ .nonblocking = true } },
.code = windows.IOCTL.AFD.START_LISTEN,
.in = @ptrCast(&windows.AFD.LISTEN_INFO{
.UseSAN = .FALSE,
.MaximumConnectionQueue = options.kernel_backlog,
.UseDelayedAcceptance = .FALSE,
}),
})).u.Status) {
.SUCCESS => {},
.CANCELLED => unreachable,
.INSUFFICIENT_RESOURCES => return error.SystemResources,
else => |status| return windows.unexpectedStatus(status),
}
return .{ .handle = socket_handle, .address = bound_address };
}