accept(2)accept(2)NAMEaccept - accept a connection on a socket
SYNOPSIS
AF_CCITT only
UNIX 03 only (X/Open Sockets)
Obsolescent UNIX 95 only (X/Open Sockets)
DESCRIPTION
The system call is used with connection-based socket types, such as The
argument, s, is a socket descriptor created with bound to a local
address by and listening for connections after a extracts the first
connection on the queue of pending connections, creates a new socket
with the same properties as s, and returns a new file descriptor, ns,
for the socket.
If no pending connections are present on the queue and nonblocking mode
has not been enabled with the or flags or the request, blocks the call‐
er until a connection is present. and are defined in (see fcntl(2),
fcntl(5), and socket(7)). and the equivalent request are defined in
although use of is not recommended (see ioctl(2), ioctl(5), and
socket(7)).
If the socket has nonblocking mode enabled and no pending connections
are present on the queue, returns an error as described below. The
accepted socket, ns, cannot be used to accept more connections. The
original socket s remains open for incoming connection requests. To
determine whether a listening socket has pending connection requests
ready for an call, use for reading.
The argument addr should point to a socket address structure. The call
fills in this structure with the address of the connecting entity, as
known to the underlying protocol. In the case of AF_UNIX sockets, the
peer's address is filled in only if the peer had done an explicit
before doing a Therefore, for AF_UNIX sockets, in the common case, when
the peer had not done an explicit before doing a the structure is
filled with a string of nulls for the address. The format of the
address depends upon the protocol and the address-family of the socket
s.
The argument addrlen is a pointer to a variable. Initially, the vari‐
able should contain the size of the structure pointed to by addr. On
return, it contains the actual length (in bytes) of the address
returned. If the memory pointed to by addr is not large enough to con‐
tain the entire address, only the first addrlen bytes of the address
are returned. If addr is NULL or addrlen contains 0, the connecting
entity's address will not be returned.
The and flags and request are all supported. These features interact
as follows:
· If the or flag has been set, requests behave accordingly, regard‐
less of any requests.
· If neither the flag nor the flag has been set, requests control
the behavior of
AF_CCITT only
The addr parameter to returns addressing information for the connecting
entity, except for the field of addr which contains the name of the
local X.25 interface through which the connection request arrived.
Call-acceptance can be controlled with the request.
X/Open Sockets Compilation Environment
See xopen_networking(7).
RETURN VALUE
Upon successful completion, returns a nonnegative integer which is a
descriptor for the accepted socket.
If an error occurs, returns and sets to indicate the cause.
ERRORS
If fails, is set to one of the following values:
Nonblocking I/O is enabled using
and no connections are present to be accepted.
The argument, s, is not a valid file descriptor.
The socket is being shutdown due to a request by software. This
is usually caused by a system call.
The addr parameter is not a valid pointer.
The call was interrupted by a signal before a valid connection arrived.
The socket referenced by
s is not currently a listen socket or has been shut
down with A must be done before an is allowed.
The maximum number of file descriptors for this process
are currently open.
The system's table of open files is full and no more
calls can be processed at this time.
No buffer space is available.
The cannot complete. The queued socket connect
request is aborted.
No memory is available.
The cannot complete. The queued socket connect
request is aborted.
The argument, s, is a valid file descriptor, but it is not a
socket.
The socket referenced by
s does not support
Nonblocking I/O is enabled using
or and no connections are present to be accepted.
OBSOLESCENCE
Currently, the and types are the same size. This is compatible with
the UNIX 95 and UNIX 03 profiles. However, in a future release, might
be a different size. In that case, passing a pointer will evoke com‐
pile-time warnings, which must be corrected in order for the applica‐
tion to behave correctly. Applications that use now, where appropri‐
ate, will avoid such migration problems. On the other hand, applica‐
tions that need to be portable to the UNIX 95 profile should follow the
X/Open specification (see xopen_networking(7)).
WARNINGS
Linking binary objects compiled to specification and binary objects
compiled to specification to the same executable may result in unex‐
pected behavior, including application abnormal termination and unex‐
pected socket errors. See xopen_networking(7) for details and remedy.
FUTURE DIRECTION
Currently, the default behavior is the however, it might be changed to
in a future release. At that time, any behavior that is incompatible
with might be obsoleted. Applications that conform to the X/Open spec‐
ification now will avoid migration problems (see xopen_networking(7)).
AUTHOR
was developed by HP and the University of California, Berkeley.
SEE ALSObind(2), connect(2), listen(2), select(2), socket(2), privileges(5),
thread_safety(5), xopen_networking(7).
STANDARDS CONFORMANCEaccept(2)