server/sock.c
/* create a new and unconnected socket */
create a new and unconnected socket
create a new and unconnected socket
static struct object *create_socket( int family, int type, int protocol, unsigned int flags )
{
    struct sock *sock;
    int sockfd;
    sockfd = socket( family, type, protocol );
    if (debug_level)
        fprintf(stderr,"socket(%d,%d,%d)=%d\n",family,type,protocol,sockfd);
    if (sockfd == -1)
    {
        sock_set_error();
        return NULL;
    }
    fcntl(sockfd, F_SETFL, O_NONBLOCK); 
    if (!(sock = alloc_object( &sock_ops )))
    {
        close( sockfd );
        return NULL;
    }
    init_sock( sock );
    sock->state  = (type != SOCK_STREAM) ? (FD_READ|FD_WRITE) : 0;
    sock->flags  = flags;
    sock->type   = type;
    sock->family = family;
    if (!(sock->fd = create_anonymous_fd( &sock_fd_ops, sockfd, &sock->obj,
                            (flags & WSA_FLAG_OVERLAPPED) ? 0 : FILE_SYNCHRONOUS_IO_NONALERT )))
    {
        release_object( sock );
        return NULL;
    }
    sock_reselect( sock );
    clear_error();
    return &sock->obj;
}
static struct object * create_socket ( int family , int type , int protocol , unsigned int flags ) { struct sock * sock ; int sockfd ; sockfd = socket ( family , type , protocol ) ; if ( debug_level ) fprintf ( stderr , " \n " , family , type , protocol , sockfd ) ; if ( sockfd == -1 ) { sock_set_error ( ) ; return NULL ; } fcntl ( sockfd , F_SETFL , O_NONBLOCK ) ; if ( ! ( sock = alloc_object ( & sock_ops ) ) ) { close ( sockfd ) ; return NULL ; } init_sock ( sock ) ; sock -> state = ( type != SOCK_STREAM ) ? ( FD_READ | FD_WRITE ) : 0 ; sock -> flags = flags ; sock -> type = type ; sock -> family = family ; if ( ! ( sock -> fd = create_anonymous_fd ( & sock_fd_ops , sockfd , & sock -> obj , ( flags & WSA_FLAG_OVERLAPPED ) ? 0 : FILE_SYNCHRONOUS_IO_NONALERT ) ) ) { release_object ( sock ) ; return NULL ; } sock_reselect ( sock ) ; clear_error ( ) ; return & sock -> obj ; }
create a new and unconnected socket
create a new and unconnected socket
/* make socket nonblocking */