Skip to content
ListenerAccept

ListenerAccept

Description

Accept the next pending connection on a listener.

Parameters

Name Direction Description
self in,out Listener to accept on.
out_conn out Populated with the new connected Socket on success.

Success

returns true; out_conn->fd is the new socket fd.

Failure

returns false; logs the failing syscall. On EINTR / EAGAIN the caller should retry.

Usage example (Cross-references)

Usage examples (Cross-references)
        }
    
        if (!ListenerAccept(&listener, &server)) {
            SocketClose(&client);
            ListenerClose(&listener);
    }
    
    bool ListenerAccept(Listener *self, Socket *out_conn) {
        if (!self || !out_conn) {
            LOG_ERROR("ListenerAccept: NULL argument");
    bool ListenerAccept(Listener *self, Socket *out_conn) {
        if (!self || !out_conn) {
            LOG_ERROR("ListenerAccept: NULL argument");
            return false;
        }
        i32                     cfd      = accept(self->fd, (struct sockaddr *)&peer, &peer_len);
        if (cfd < 0) {
            LOG_SYS_ERROR("ListenerAccept: accept() failed");
            return false;
        }
    
                Socket client;
                if (!ListenerAccept(&listener, &client)) {
                    continue;
                }
Last updated on