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 › Threaded › netListenIpPosix Private Function netListenIpPosix Doc Source Private Function std.Io.Threaded.netListenIpPosix
fn netListenIpPosix (
userdata : ?*anyopaque ,
address : *const IpAddress ,
options : IpAddress .ListenOptions ,
) IpAddress .ListenError !net .Socket Params File Io/Threaded.zig: 11953
11953
11954
11955
11956
11957
11958
11959
11960
11961
11962
11963
11964
11965
11966
11967
11968
11969
11970
11971
11972
11973
11974
11975
11976
11977
11978
11979
11980
11981
11982
11983
11984
11985
11986
11987
11988
11989
11990
11991
11992
11993
11994 fn netListenIpPosix (
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_fd = try openSocketPosix (family , .{ .mode = options .mode , .protocol = options .protocol });
errdefer closeFd (socket_fd );
if (options .reuse_address ) {
try setSocketOptionPosix (socket_fd , posix .SOL .SOCKET , posix .SO .REUSEADDR , 1 );
if (@hasDecl (posix .SO , "REUSEPORT" ))
try setSocketOptionPosix (socket_fd , posix .SOL .SOCKET , posix .SO .REUSEPORT , 1 );
}
var storage : PosixAddress = undefined ;
var addr_len = addressToPosix (address , &storage );
try posixBind (socket_fd , &storage .any , addr_len );
const syscall : Syscall = try .start ();
while (true ) {
switch (posix .errno (posix .system .listen (socket_fd , options .kernel_backlog ))) {
.SUCCESS => {
syscall .finish ();
break ;
},
.INTR => {
try syscall .checkCancel ();
continue ;
},
.ADDRINUSE => return syscall .fail (error .AddressInUse ),
.BADF => |err | return syscall .errnoBug (err ), // File descriptor used after closed.
else => |err | return syscall .unexpectedErrno (err ),
}
}
try posixGetSockName (socket_fd , &storage .any , &addr_len );
return .{ .handle = socket_fd , .address = addressFromPosix (&storage ) };
}