Skip to content

ListenerOpen

Description

Open + bind + listen on the given address.

Parameters

Name Direction Description
out out Listener to populate. Untouched on failure.
kind in SOCKET_KIND_TCP (UDP listeners do not call listen() but the same entry point applies — see notes in the implementation).
addr in Address to bind to.
backlog in listen() backlog. Use 128 if you are unsure.

Success

returns true; out is ready for ListenerAccept.

Failure

returns false; logs the failing syscall.

Usage example (Cross-references)

Usage examples (Cross-references)
    // ---------------------------------------------------------------------------
    
    bool ListenerOpen(Listener *out, SocketKind kind, const SocketAddr *addr, i32 backlog) {
        if (!out || !addr) {
            LOG_FATAL("ListenerOpen: NULL argument");
    bool ListenerOpen(Listener *out, SocketKind kind, const SocketAddr *addr, i32 backlog) {
        if (!out || !addr) {
            LOG_FATAL("ListenerOpen: NULL argument");
        }
        MemSet(out, 0, sizeof(*out));
        i32 proto    = sock_kind_to_protocol(kind);
        if (af == AF_UNSPEC || socktype < 0) {
            LOG_ERROR("ListenerOpen: invalid family/kind combination");
            return false;
        }
    
            Listener listener;
            if (!ListenerOpen(&listener, SOCKET_KIND_TCP, &listen_addr, 128)) {
                LOG_ERROR("failed to open listener on {}", listen_spec);
                return 1;
    
        Listener listener;
        if (!ListenerOpen(&listener, SOCKET_KIND_TCP, &bind_addr, 16)) {
            DefaultAllocatorDeinit(&alloc);
            return false;
        }
    
        if (!ListenerOpen(&listener, SOCKET_KIND_TCP, &bind_addr, 16)) {
            DefaultAllocatorDeinit(&alloc);
            return false;
            return p;
    
        if (!ListenerOpen(&p.listener, SOCKET_KIND_TCP, &bind_addr, 16))
            return p;
    
        Listener listener;
        if (!ListenerOpen(&listener, SOCKET_KIND_TCP, &bind_addr, 16)) {
            // Port may be in use by a stale TIME_WAIT from a prior run; treat as
            // environmental, not a mutation kill. Fall back to ephemeral check.
    
        Listener listener;
        if (!ListenerOpen(&listener, SOCKET_KIND_TCP, &bind_addr, 16)) {
            DefaultAllocatorDeinit(&alloc);
            return false;
    
        Listener listener;
        if (!ListenerOpen(&listener, SOCKET_KIND_TCP, &bind_addr, 16)) {
            DefaultAllocatorDeinit(&alloc);
            return false;
    
        Listener listener;
        bool     opened = ListenerOpen(&listener, SOCKET_KIND_TCP, &bad, 16);
        return opened == false;
    }
    
        Listener listener;
        if (!ListenerOpen(&listener, SOCKET_KIND_TCP, &bind_addr, 16)) {
            return false;
        }
            return false;
    
        if (!ListenerOpen(listener, SOCKET_KIND_TCP, &bind_addr, 16))
            return false;
Last updated on