NetSock_Accept

Wait for new socket connections on a listening server socket (see function NetSock_Listen()). When a new connection arrives and the TCP handshake has successfully completed, a new socket ID is returned for the new connection with the remote host’s address and port number returned in the socket address structure.

Files

net_sock.h/net_sock.c
net_bsd.h/net_bsd.c

Prototypes

          NET_SOCK_ID NetSock_Accept(NET_SOCK_ID        sock_id,
                                     NET_SOCK_ADDR     *p_addr_remote,
                                     NET_SOCK_ADDR_LEN *p_addr_len,
                                     NET_ERR           *p_err);
           
          int         accept        (       int         sock_id,
                                     struct sockaddr   *p_addr_remote,
                                            socklen_t  *p_addr_len);

Arguments

sock_id

This is the socket ID returned by NetSock_Open()/socket() when the socket was created. This socket is assumed to be bound to an address and listening for new connections (see function NetSock_Listen()).

p_addr_remote

Pointer to a socket address structure (see section 9-1 “Network Socket Data Structures”) to return the remote host address of the new accepted connection.

p_addr_len

Pointer to the size of the socket address structure which must be passed the size of the socket address structure [e.g., sizeof(NET_SOCK_ADDR_IPv4)]. Returns size of the accepted connection’s socket address structure, if no errors; returns 0, otherwise.

p_err

Pointer to variable that will receive the return error code from this function:

NET_SOCK_ERR_NONE
NET_ERR_FAULT_NULL_PTR
NET_SOCK_ERR_NONE_AVAIL
NET_SOCK_ERR_NOT_USED
NET_SOCK_ERR_CLOSED
NET_SOCK_ERR_INVALID_SOCK
NET_SOCK_ERR_INVALID_FAMILY
NET_SOCK_ERR_INVALID_TYPE
NET_SOCK_ERR_INVALID_STATE
NET_SOCK_ERR_INVALID_OP
NET_SOCK_ERR_CONN_ACCEPT_Q_NONE_AVAIL
NET_SOCK_ERR_CONN_SIGNAL_TIMEOUT
NET_SOCK_ERR_CONN_FAIL
NET_SOCK_ERR_FAULT
NET_INIT_ERR_NOT_COMPLETED
NET_ERR_FAULT_LOCK_ACQUIRE

Returned Value

Returns a non-negative socket descriptor ID for the new accepted connection, if successful; NET_SOCK_BSD_ERR_ACCEPT/-1, otherwise.

If the socket is configured for non-blocking, a return value of NET_SOCK_BSD_ERR_ACCEPT/-1 may indicate that the no requests for connection were queued when NetSock_Accept()/accept() was called. In this case, the server can “poll” for a new connection at a later time.

Required Configuration

Available only if NET_TCP_CFG_EN is enabled (see section TCP Layer Configuration).

Notes / Warnings

See section Network Sockets Concepts for socket address structure formats.