06.08.2013 Views

pSOSystem System Calls - Read

pSOSystem System Calls - Read

pSOSystem System Calls - Read

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

accept pNA+ <strong>System</strong> <strong>Calls</strong><br />

accept Accepts a connection on a socket.<br />

#include <br />

long accept(<br />

int s, /* socket descriptor */<br />

struct sockaddr_in *addr, /* socket structure */<br />

int *addrlen /* socket structure size */<br />

)<br />

Description<br />

Arguments<br />

This call is used to accept a connection request that the specified socket receives<br />

from a foreign socket. Servers use accept() with connection-oriented or stream<br />

(TCP) sockets.<br />

Before accept() is called, the socket must be set up to receive a connection<br />

request by issuing the listen() system call. accept() extracts the first<br />

connection request on the queue of pending connections; creates a new socket with<br />

the same properties as the original socket; completes the connection between the<br />

foreign socket and the new socket; and returns a descriptor for the new socket. The<br />

new returned socket descriptor is used to read from and write data to the foreign<br />

socket. It is not used to accept more connections. The original socket remains open<br />

for accepting further connections.<br />

If no pending connections exist on the queue and the socket is not marked as nonblocking,<br />

accept() blocks the caller until a connection is present. If the socket is<br />

marked non-blocking and no pending connections are present on the queue,<br />

accept() returns an error.<br />

Upon return, accept() stores the address of the connected socket in the specified<br />

socket address structure.<br />

s Specifies the socket on which to accept a connection request.<br />

4-2 <strong>pSO<strong>System</strong></strong> <strong>System</strong> <strong>Calls</strong>

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!