DOC HOME SITE MAP MAN PAGES GNU INFO SEARCH PRINT BOOK
 

accept(SSC-osr5)


accept -- accept a connection on a socket

Syntax

cc ... -lsocket

#include <sys/types.h>
#include <sys/socket.h>

int accept(s, addr, addrlen) int s; struct sockaddr *addr; int *addrlen;

Description

accept( ) accepts a connection on a socket. The s argument is a socket that has been created with socket(SSC-osr5), bound to an address with bind(SSC-osr5), and is listening for connections after a listen(SSC-osr5). accept( ) extracts the first connection on the queue of pending connections, creates a new socket with the same properties of s and allocates a new file descriptor for the socket. If no pending connections are present on the queue, and the socket is not marked as non-blocking, 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 as described below. The accepted socket, ns, may not be used to accept more connections. The original socket s remains open.

The addr argument is a result parameter that is filled in with the address of the connecting entity, as known to the communications layer. The exact format of the addr parameter is determined by the "communications domain". (See protocols(SFF) for more information.) The addrlen is a value-result parameter; it should initially contain the amount of space pointed to by addr; on return it will contain the actual length (in bytes) of the address returned. This call is used with connection-based socket types, currently with SOCK_STREAM.

Return values

The call returns -1 on error. If it succeeds it returns a non-negative integer which is a descriptor for the accepted socket (ns, described above).

Diagnostics

accept( ) will fail if:

[EFAULT]
addr is not readable or writable

[EINVAL]
Socket is not in a state that can accept connections

[EWOULDBLOCK]
The I/O request is non-blocking but needs to block to wait for resources to become available.

[ENOTCONN]
Socket is not connected.

[EPROTO]
Protocol error. This is either a bad connection indiation or accept disconnection with a bad ack.

[ENOSR]
Out of STREAMS resources (an allocb( ) failure).

[ENXIO]
The socket number specified by s is greater than the maximum number of configured sockets.

[ENXIO]
Cannot allocate inode for socket.

[EALREADY]
The socket is already in the process of disconnecting.

[EINTR]
Unexpected interrupt received.

See also

Intro(SSC-osr5), bind(SSC-osr5), connect(SSC-osr5), listen(SSC-osr5), socket(SSC-osr5), Intro(ADMP)
© 2005 The SCO Group, Inc. All rights reserved.
SCO OpenServer Release 6.0.0 -- 02 June 2005