listen
The Windows Sockets
listen function establishes a socket to listen for an incoming connection.
int listen (
Parameters
s
[in] A descriptor identifying a bound, unconnected socket.
backlog
[in] The maximum length to which the queue of pending connections can GROW. If
this value is SOMAXCONN, then the underlying service provider responsible for
socket
s will set the backlog to a maximum "reasonable" value.
Remarks
To accept connections, a socket is first created with
socket, a backlog for incoming connections is specified with
listen, and then the connections are accepted with
accept.
listen applies only to sockets that are connection oriented, for example, those of
type SOCK_STREAM. The socket
s is put into "passive'' mode where incoming connection requests are
acknowledged and queued pending acceptance by the process.
This function is typically used by servers that could have more than one
connection request at a time: if a connection request arrives with the queue full,
the client will receive an error with an indication of WSAECONNREFUSED.
listen attempts to continue to function rationally when there are no available
descriptors. It will accept connections until the queue is emptied. If descriptors
become available, a later call to
listen or
accept will refill the queue to the current or most recent "backlog'', if possible,
and resume listening for incoming connections.
An application can call
listen more than once on the same socket. This has the effect of updating the
current backlog for the listening socket. Should there be more pending connections
than the new
backlog value, the excess pending connections will be reset and dropped.
Compatibility
The
backlog parameter is limited (silently) to a reasonable value as determined by the
underlying service provider. Illegal values are replaced by the nearest legal
value.
Return Values
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 Codes
WSANOTINITIALISED
| A successful WSAStartup must occur before using this function.
|
WSAENETDOWN
| The network subsystem has failed.
|
WSAEADDRINUSE
| An attempt has been made to listen on an address in use.
|
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.
|
See Also
accept,
connect,
socket
- Software for developers
-
Delphi Components
.Net Components
Software for Android Developers
- More information resources
-
MegaDetailed.Net
Unix Manual Pages
Delphi Examples
- Databases for Amazon shops developers
-
Amazon Categories Database
Browse Nodes Database