Listen
Jump to navigation
Jump to search
Description
The listen function places a socket in a state in which it is listening for an incoming connection.
Syntax
int listen(
_In_ SOCKET s,
_In_ int backlog
);
Parameters
- s [in]
- A descriptor identifying a bound, unconnected socket.
- backlog [in]
- The maximum length of the queue of pending connections. If set to SOMAXCONN, the underlying service provider responsible for socket s will set the backlog to a maximum reasonable value. If set to SOMAXCONN_HINT(N) (where N is a number), the backlog value will be N, adjusted to be within the range (200, 65535). Note that SOMAXCONN_HINT can be used to set the backlog to a larger value than possible with SOMAXCONN.
- SOMAXCONN_HINT is only supported by the Microsoft TCP/IP service provider. There is no standard provision to obtain the actual backlog value.
Return value
If no error occurs, listen returns zero. Otherwise, a value of SOCKET_ERROR is returned, and a specific error code can be retrieved by calling WSAGetLastError.
Error code | Meaning |
---|---|
WSANOTINITIALISED | A successful WSAStartup call must occur before using this function. |
WSAENETDOWN | The network subsystem has failed. |
WSAEADDRINUSE | The socket's local address is already in use and the socket was not marked to allow address reuse with SO_REUSEADDR. This error usually occurs during execution of the bind function, but could be delayed until this function if the bind was to a partially wildcard address (involving ADDR_ANY) and if a specific address needs to be committed at the time of this function. |
WSAEINPROGRESS | A blocking Windows Sockets 1.1 call is in progress, or the service provider is still processing a callback function. |
WSAEINVAL | The socket has not been bound with bind. |
WSAEISCONN | The socket is already connected. |
WSAEMFILE | No more socket descriptors are available. |
WSAENOBUFS | No buffer space is available. |
WSAENOTSOCK | The descriptor is not a socket. |
WSAEOPNOTSUPP | The referenced socket is not of a type that supports the listen operation. |