|
|
A completed connection is identified by a unique pair of
sockets, each socket being an endpoint associated with one of the
reciprocating processes.
For the server to receive a client's
connection, the server must issue two system calls after binding
its socket.
The first is to indicate a willingness to
listen for incoming connection requests.
The second is to accept the client's connect.
Consider this example:
listen(s,5);
The second parameter, 5, indicates the maximum number of outstanding connections which can be queued awaiting the acceptance of the server. This limit prevents processes from tying up system resources. Should a connection be requested while the queue is full, the server does not refuse the connection, but ignores the messages which comprise the request. This forces the client to retry the connection request and gives the server time to make room in its queue. The listen call itself does not make the server process wait; it only specifies the maximum number of outstanding connection requests that can be queued.
Had the connection been returned with the ECONNREFUSED error, the
client would be unable to tell if the server was up or not.
See
``Connection errors (Internet domain)''
for the list of errors.
As it is, now it is still possible to get the ETIMEDOUT error back,
though this is unlikely.
The backlog figure supplied with the
listen call is limited by the system to a maximum of five pending
connections on any one queue.
This avoids the problem of
processes tying up system resources by setting an infinite
backlog and then ignoring all connection requests.