Zig 0.17.0-dev (Split by item) This is an example of documentation generated by
ZigDoc , an alternative to Zig's built-in
Auto Doc feature. See also
examples in other modes/formats . The project being documented here (as the example) is the Zig standard library.
std › Io › net › HostName › connect Public Function connect Doc Source Public Function std.Io.net.HostName.connect
pub fn connect (
host_name : HostName ,
io : Io ,
port : u16 ,
options : IpAddress .ConnectOptions ,
) ConnectError !Stream Params File Io/net/HostName.zig: 301
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348 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 => {
// There was no successful connection attempt. If there was a lookup error, return that.
try connect_many .await (io );
// Otherwise, return the error from a failed IP connection attempt.
return ip_connect_error orelse
return error .UnknownHostName ;
},
}
}