UDT Reference

UDT Reference: Functions

#### accept

The accept method retrieves an incoming connection.

UDTSOCKET accept(
UDTSOCKET u,
struct sockaddr* addr,
int* addrlen
);

##### Parameters

u
  [in] Descriptor identifying a listening socket.
addr
  [out] Address of the peer side of the new accepted connection.
addrlen
  [out] Length of the addr structure.

##### Return Value

If no error occurs, accept returns the UDT socket descriptor of the new connection; otherwise, it returns UDT::INVALID_SOCK.

On a successful return, the address of the peer side of the connection is written into addr, and its length is in addrlen, if the addr parameter is not NULL.

If an error is returned, the error information can be retrieved by getlasterror. One of the following error can cause an accept error:

Error Name | Error Code | Comment
EINVSOCK | 5004 | u is an invalid UDT socket.
ENOLISTEN | 5006 | u is not in the listening state.
ERDVNOSERV | 5007 | u is set up to support rendezvous connection.
EASYNCRCV | 6002 | u is non-blocking (UDT_RCVSYN = false) but there is no connection available.

##### Description

Once a UDT socket is in listening state, it accepts new connections and maintains the pending connections in a queue. An accept call retrieves the first connection in the queue, removes it from the queue, and returns the associate socket descriptor.

If there is no connections in the queue when accept is called, a blocking socket will wait until a new connection is set up, whereas a non-blocking socket will return immediately with an error.

The accepted sockets will inherit all proper attributes from the listening socket.

##### See Also

listen, connect, setsockopt, getsockopt