The listen() socket call completes the binding necessary for a socket to accept connections and creates a connection request queue for incoming requests.
Syntax
#include <types.h> #include <sys\socket.h> #include <netinet\in.h> int listen(s, backlog) int s; int backlog;
Parameters
s
Description
The listen() call performs two tasks:
The listen() call indicates a readiness to accept client connection requests. It transforms an active socket into a passive socket. After listen() is called, s can never be used as an active socket to initiate connection requests. listen() is called after allocating a socket with socket() and after binding a name to s with bind(). listen() must be called before calling accept().
listen() can only be called on connection-oriented sockets.
If the backlog parameter is less than 0, then listen() interprets backlog as 0. If the backlog parameter is greater than SOMAXCONN, as defined in <SYS\SOCKET.H>, then listen() interprets backlog as SOMAXCONN.
Return Values
The value 0 indicates success, the value -1 indicates an error. You can get the specific error code by calling sock_errno() or psock_errno().
Error Code
Related Calls