Open System Services System Calls Reference Manual (G06.25+, H06.03+)
accept(2) OSS System Calls Reference Manual
NAME
accept - Accepts a new connection on a socket
LIBRARY
G-series native OSS processes: system library
H-series OSS processes: implicit libraries
SYNOPSIS
#include <sys/socket.h>
int accept(
int socket,
struct sockaddr *address,
size_t *address_len
);
PARAMETERS
socket Specifies the file descriptor for a socket that was created with the socket() func-
tion, has been bound to an address with the bind() function, and has issued a
successful call to the listen() function.
address Specifies either a null pointer or a pointer to the sockaddr structure where the
address of the peer socket that requested the connection should be returned. The
length and format of the address depend on the address family of the socket.
For AF_INET sockets, a pointer to the address structure sockaddr_in must be
cast as a struct sockaddr.ForAF_INET6 sockets, a pointer to the address
structure sockaddr_in6 must be cast as a struct sockaddr.ForAF_UNIX sock-
ets, a pointer to the address structure sockaddr_un must be cast as a struct
sockaddr.
address_len Points to a size_t data item, which, on input, specifies the length of the sockaddr
structure pointed to by the address parameter, and, on output, specifies the length
of the address returned.
DESCRIPTION
The accept() function extracts the first connection on the queue of pending connections, creates
a new socket with the same socket type, protocol, and address family as the specified socket, and
allocates a new file descriptor for that socket.
When the accept() function is called using a value for the address parameter that is null, suc-
cessful completion of the call returns a socket file descriptor without modifying the value pointed
to by the address_len parameter. When the accept() function is called using a value for the
address parameter that is not null, a successful call places the address of the peer socket in the
sockaddr structure pointed to by the address parameter, and places the length of the peer
socket’s address in the location pointed to by the address_len parameter.
If the length of the socket address is greater than the length of the supplied sockaddr structure,
the address is truncated when stored.
If the queue of pending connections is empty of connection requests and the socket’s file
descriptor is blocking (O_NONBLOCK is not set), the accept() function blocks until a connec-
tion is present. If the socket’s file descriptor is marked nonblocking (O_NONBLOCK is set) and
the queue of pending connections is empty, the accept() function call fails and sets errno to
[EWOULDBLOCK].
1−2 Hewlett-Packard Company 527186-003