feature. See also
. The project being documented here (as the example) is the Zig library itself.
HostName.connect
pub fn connect(
host_name: HostName,
io: Io,
port: u16,
options: IpAddress.ConnectOptions,
) ConnectError!Stream
File
Code
pub fn connect(
host_name: HostName,
io: Io,
port: u16,
options: IpAddress.ConnectOptions,
) ConnectError!Stream {
var connect_many_buffer: [32]IpAddress.ConnectError!Stream = undefined;
var connect_many_queue: Io.Queue(IpAddress.ConnectError!Stream) = .init(&connect_many_buffer);
var connect_many = io.async(connectMany, .{ host_name, io, port, &connect_many_queue, options });
defer {
connect_many.cancel(io) catch {};
while (connect_many_queue.getOneUncancelable(io)) |loser| {
if (loser) |s| s.close(io) else |_| {}
} else |err| switch (err) {
error.Closed => {},
}
}
var ip_connect_error: ?IpAddress.ConnectError = null;
while (connect_many_queue.getOne(io)) |result| {
if (result) |stream| {
return stream;
} else |err| switch (err) {
error.Canceled => unreachable,
error.SystemResources,
error.OptionUnsupported,
error.ProcessFdQuotaExceeded,
error.SystemFdQuotaExceeded,
=> |e| return e,
error.WouldBlock => return error.Unexpected,
else => |e| ip_connect_error = e,
}
} else |err| switch (err) {
error.Canceled => |e| return e,
error.Closed => {
try connect_many.await(io);
return ip_connect_error orelse
return error.UnknownHostName;
},
}
}