Download pSOSystem System Calls

Transcript
psc.book Page 5 Monday, January 11, 1999 1:50 PM
pSOSystem System Calls
accept
pNA+ System Calls
Accepts a connection on a socket.
#include <pna.h>
long accept(
int s,
struct sockaddr *addr,
int *addrlen
)
/* socket descriptor */
/* socket structure */
/* socket structure size */
NOTE: In the above structure, sockaddr_in can be used in place of sockaddr if
the following compile option is specified on the command line (the -D
option is valid for most compilers. Consult your compiler manual.):
6
-D_PNA_30_BACK
The structure for sockaddr is located in the include/sys directory in
sockcom.h.
Description
This call is used to accept a connection request that the specified socket receives
from a foreign socket. Servers use accept() with connection-oriented or stream
(TCP) sockets.
Before accept() is called, the socket must be set up to receive a connection request by issuing the listen() system call. accept() extracts the first connection
request on the queue of pending connections; creates a new socket with the same
properties as the original socket; completes the connection between the foreign
socket and the new socket; and returns a descriptor for the new socket. The new returned socket descriptor is used to read from and write data to the foreign socket. It
is not used to accept more connections. The original socket remains open for
accepting further connections.
If no pending connections exist on the queue and the socket is not marked as nonblocking, accept() blocks the caller until a connection is present. If the socket is
marked non-blocking and no pending connections are present on the queue,
accept() returns an error.
Upon return, accept() stores the address of the connected socket in the specified
socket address structure.
accept
6-5