server/sock.c
/* accept a socket (creates a new fd) */
accept a socket (creates a new fd)
accept a socket ( creates a new fd )
static struct sock *accept_socket( obj_handle_t handle )
{
    struct sock *acceptsock;
    struct sock *sock;
    int	acceptfd;
    sock = (struct sock *)get_handle_obj( current->process, handle, FILE_READ_DATA, &sock_ops );
    if (!sock)
        return NULL;
    if ( sock->deferred )
    {
        acceptsock = sock->deferred;
        sock->deferred = NULL;
    }
    else
    {
        if ((acceptfd = accept_new_fd( sock )) == -1)
        {
            release_object( sock );
            return NULL;
        }
        if (!(acceptsock = alloc_object( &sock_ops )))
        {
            close( acceptfd );
            release_object( sock );
            return NULL;
        }
        init_sock( acceptsock );
        acceptsock->state  = FD_WINE_CONNECTED|FD_READ|FD_WRITE;
        if (sock->state & FD_WINE_NONBLOCKING)
            acceptsock->state |= FD_WINE_NONBLOCKING;
        acceptsock->mask    = sock->mask;
        acceptsock->type    = sock->type;
        acceptsock->family  = sock->family;
        acceptsock->window  = sock->window;
        acceptsock->message = sock->message;
        if (sock->event) acceptsock->event = (struct event *)grab_object( sock->event );
        acceptsock->flags = sock->flags;
        if (!(acceptsock->fd = create_anonymous_fd( &sock_fd_ops, acceptfd, &acceptsock->obj,
                                                    get_fd_options( sock->fd ) )))
        {
            release_object( acceptsock );
            release_object( sock );
            return NULL;
        }
    }
    clear_error();
    sock->pmask &= ~FD_ACCEPT;
    sock->hmask &= ~FD_ACCEPT;
    sock_reselect( sock );
    release_object( sock );
    return acceptsock;
}
static struct sock * accept_socket ( obj_handle_t handle ) { struct sock * acceptsock ; struct sock * sock ; int acceptfd ; sock = ( struct sock * ) get_handle_obj ( current -> process , handle , FILE_READ_DATA , & sock_ops ) ; if ( ! sock ) return NULL ; if ( sock -> deferred ) { acceptsock = sock -> deferred ; sock -> deferred = NULL ; } else { if ( ( acceptfd = accept_new_fd ( sock ) ) == -1 ) { release_object ( sock ) ; return NULL ; } if ( ! ( acceptsock = alloc_object ( & sock_ops ) ) ) { close ( acceptfd ) ; release_object ( sock ) ; return NULL ; } init_sock ( acceptsock ) ; acceptsock -> state = FD_WINE_CONNECTED | FD_READ | FD_WRITE ; if ( sock -> state & FD_WINE_NONBLOCKING ) acceptsock -> state |= FD_WINE_NONBLOCKING ; acceptsock -> mask = sock -> mask ; acceptsock -> type = sock -> type ; acceptsock -> family = sock -> family ; acceptsock -> window = sock -> window ; acceptsock -> message = sock -> message ; if ( sock -> event ) acceptsock -> event = ( struct event * ) grab_object ( sock -> event ) ; acceptsock -> flags = sock -> flags ; if ( ! ( acceptsock -> fd = create_anonymous_fd ( & sock_fd_ops , acceptfd , & acceptsock -> obj , get_fd_options ( sock -> fd ) ) ) ) { release_object ( acceptsock ) ; release_object ( sock ) ; return NULL ; } } clear_error ( ) ; sock -> pmask &= ~ FD_ACCEPT ; sock -> hmask &= ~ FD_ACCEPT ; sock_reselect ( sock ) ; release_object ( sock ) ; return acceptsock ; }
accept a socket (creates a new fd)
accept a socket ( creates a new fd )
/* newly created socket gets the same properties of the listening socket */