Asynchronously establishes a connection to all IP addresses associated with a host name, adding them to a results queue upon completion.
error.Canceled will never be added to the queue, but other errors may be.
Closes results before return, even on error.
Asserts results is not closed until this call returns.
pub fn connectMany(
host_name: HostName,
io: Io,
port: u16,
results: *Io.Queue(IpAddress.ConnectError!Stream),
options: IpAddress.ConnectOptions,
) LookupError!void
pub fn connectMany(
host_name: HostName,
io: Io,
port: u16,
results: *Io.Queue(IpAddress.ConnectError!Stream),
options: IpAddress.ConnectOptions,
) LookupError!void {
defer results.close(io);
var canonical_name_buffer: [max_len]u8 = undefined;
var lookup_buffer: [32]HostName.LookupResult = undefined;
var lookup_queue: Io.Queue(LookupResult) = .init(&lookup_buffer);
var lookup_future = io.async(lookup, .{ host_name, io, &lookup_queue, .{
.port = port,
.canonical_name_buffer = &canonical_name_buffer,
} });
defer lookup_future.cancel(io) catch {};
var group: Io.Group = .init;
defer group.cancel(io);
while (lookup_queue.getOne(io)) |dns_result| switch (dns_result) {
.address => |address| group.async(io, enqueueConnection, .{ address, io, results, options }),
.canonical_name => continue,
} else |err| switch (err) {
error.Canceled => |e| return e,
error.Closed => {
try group.await(io);
return lookup_future.await(io);
},
}
}