Interprocess communication using UNIX domain sockets

Accepting a connection (UNIX domain)

With the socket marked as listening, the server can now accept a connection:

fromlen = sizeof (from);
snew = accept(s, (struct sockaddr *) &from, &fromlen);

The accept returns a new socket that can be used by the server for communication with the client. If the server wishes to find out who its client is, it may supply a buffer for the client socket's name. The fromlen argument is a value-result parameter initialized by the server to indicate how much space is associated with from (the client). It is modified on return to reflect the true size of the name. The accept call is only used by passive processes.

The call to accept will not return until a connection is available or the system call is interrupted by a signal to the process. This is called ``blocking''. The accept call cannot screen for connections from certain sources only. A user processes must provide its own screening, if required, by identifying the source of the connection and and closing down the connection if it does not wish to speak to the other process.

Servers often bind multiple sockets. When a server accepts a connection, it usually spins off (forks) a process which will use the socket returned by accept. The parent then goes back to listening on the same local socket.

Next topic: Connection errors (UNIX domain)
Previous topic: The server (UNIX domain)

© 2003 Caldera International, Inc. All rights reserved.
SCO OpenServer Release 5.0.7 -- 11 February 2003