feature. See also
. The project being documented here (as the example) is the Zig library itself.
Threaded.netAcceptWindows
fn netAcceptWindows(userdata: ?*anyopaque, listen_handle: net.Socket.Handle, options: net.Server.AcceptOptions) net.Server.AcceptError!net.Socket
File
Code
fn netAcceptWindows(userdata: ?*anyopaque, listen_handle: net.Socket.Handle, options: net.Server.AcceptOptions) net.Server.AcceptError!net.Socket {
if (!have_networking) return error.NetworkDown;
const t: *Threaded = @ptrCast(@alignCast(userdata));
const Storage = extern struct {
Info: windows.AFD.LISTEN_RESPONSE_INFO,
RemoteAddress: extern union { posix: PosixAddress, unix: UnixAddress },
};
var storage: Storage = undefined;
switch ((try deviceIoControl(&.{
.file = .{ .handle = listen_handle, .flags = .{ .nonblocking = true } },
.code = windows.IOCTL.AFD.WAIT_FOR_LISTEN,
.out = @ptrCast(&storage),
})).u.Status) {
.SUCCESS => {},
.CANCELLED => unreachable,
.INSUFFICIENT_RESOURCES => return error.SystemResources,
else => |status| return windows.unexpectedStatus(status),
}
errdefer t.deferAcceptAfd(listen_handle, storage.Info);
const accept_handle = openSocketAfd(
storage.RemoteAddress.posix.any.family,
.{ .mode = options.mode, .protocol = options.protocol },
) catch |err| switch (err) {
error.AddressFamilyUnsupported => return error.Unexpected,
error.ProtocolUnsupportedByAddressFamily => return error.Unexpected,
else => |e| return e,
};
errdefer windows.CloseHandle(accept_handle);
switch ((try deviceIoControl(&.{
.file = .{ .handle = listen_handle, .flags = .{ .nonblocking = true } },
.code = windows.IOCTL.AFD.ACCEPT,
.in = @ptrCast(&windows.AFD.ACCEPT_INFO{
.UseSAN = .FALSE,
.Sequence = storage.Info.Sequence,
.AcceptHandle = accept_handle,
}),
})).u.Status) {
.SUCCESS => {},
.CANCELLED => unreachable,
.INSUFFICIENT_RESOURCES => return error.SystemResources,
else => |status| return windows.unexpectedStatus(status),
}
return .{ .handle = accept_handle, .address = addressFromPosix(&storage.RemoteAddress.posix) };
}