ACCEPT(2,L) AIX Technical Reference ACCEPT(2,L)
-------------------------------------------------------------------------------
accept
PURPOSE
Accepts a connection on a socket.
SYNTAX
#include <sys/types.h>
#include <sys/socket.h>
int accept (s, addr, addrlen)
int s;
struct sockaddr *addr;
int *addrlen;
DESCRIPTION
The accept system call extracts the first connection on the queue of pending
connections, creates a new socket with the same properties as s, and allocates
a new file descriptor for that socket. If no pending connections are present
on the queue and the calling socket is not marked as nonblocking, accept blocks
the caller until a connection is present. If the socket specified by s is
marked nonblocking and there are no connections pending on the queue, accept
returns an error as described below. The accepted socket cannot be used to
accept more connections. The original socket, s, remains open and can accept
more connections.
The s parameter is a socket that was created with the socket system call, was
bound to an address with the bind system call, and has issued a successful call
to the listen system call.
The addr parameter 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 addr is determined by the domain in which the communication occurs. The
addrlen parameter initially contains the amount of space pointed to by the addr
parameter. On return, it contains the actual length (in bytes) of the address
returned. This system call is used with connection-based socket types, such as
SOCK_STREAM.
Before calling the accept system call, you can find out if the socket is ready
to accept the connection by doing a read select with the select system call.
RETURN VALUE
Upon successful completion, the nonnegative socket descriptor of the accepted
socket is returned. A socket marked nonblocking with the O_NONBLOCK flag or
the FIONBIO ioctl returns a value of -1 and sets errno to EAGAIN in the
situation where is would otherwise have blocked.
Processed November 7, 1990 ACCEPT(2,L) 1
ACCEPT(2,L) AIX Technical Reference ACCEPT(2,L)
A socket marked with the O_NDELAY flag returns ZERO in the situation where it
would otherwise have blocked.
ERROR CONDITIONS
The system call fails if one or more of the following are true:
EBADF The s parameter is not valid.
ENOTSOCK The s parameter refers to a file, not a socket.
EOPNOTSUPP The referenced socket is not of type SOCK_STREAM.
EFAULT The addr parameter is not in a writable part of the user address
space.
EAGAIN The socket is marked nonblocking with the O_NONBLOCK flag or the
FIONBIO ioctl in the situation where it would otherwise have
blocked.
RELATED INFORMATION
In this book: "bind," "connect," "listen," "select," and "socket."
Processed November 7, 1990 ACCEPT(2,L) 2