DoxigAlpha

getOsSockLen

Function parameters

Parameters

#

Type definitions in this namespace

Types

#

Functions in this namespace

Functions

#
tcpConnectToHost
All memory allocated with `allocator` will be freed before this function returns.
getAddressList
Call `AddressList.deinit` on the result.

Error sets in this namespace

Error Sets

#

= switch (native_os) { .windows => builtin.os.version_range.windows.isAtLeast(.win10_rs4) orelse false, .wasi => false, else => true, }

Values

#
has_unix_sockets
= switch (native_os) { .windows => builtin.os.version_range.windows.isAtLeast(.win10_rs4) orelse false, .wasi => false, else => true, }

Source

Implementation

#
pub fn getOsSockLen(self: Address) posix.socklen_t {
    switch (self.any.family) {
        posix.AF.INET => return self.in.getOsSockLen(),
        posix.AF.INET6 => return self.in6.getOsSockLen(),
        posix.AF.UNIX => {
            if (!has_unix_sockets) {
                unreachable;
            }

            // Using the full length of the structure here is more portable than returning
            // the number of bytes actually used by the currently stored path.
            // This also is correct regardless if we are passing a socket address to the kernel
            // (e.g. in bind, connect, sendto) since we ensure the path is 0 terminated in
            // initUnix() or if we are receiving a socket address from the kernel and must
            // provide the full buffer size (e.g. getsockname, getpeername, recvfrom, accept).
            //
            // To access the path, std.mem.sliceTo(&address.un.path, 0) should be used.
            return @as(posix.socklen_t, @intCast(@sizeOf(posix.sockaddr.un)));
        },

        else => unreachable,
    }
}