Accepts a connection on a passive socket. The $QIO equivalent is the IO$_ACCESS system service with the IO$M_ACCEPT modifier. Format #include <types.h> #include <socket.h> int accept ( int s, struct sockaddr *addr, int *addrlen ); (_DECC_V4_SOURCE) int accept ( int s, struct sockaddr *addr, size_t *addrlen ); (not_DECC_V4_SOURCE)
1 – Arguments
s A socket descriptor returned by socket(), subsequently bound to an address with bind(), which is listening for connections after a listen(). addr A result argument filled in with the address of the connecting entity, as known to the TCP/IP kernel. The exact format of the structure to which the address parameter points is determined by the address family. Specify either the IPv4 address family (AF_ INET) or the IPv6 address family (AF_INET6). addrlen A value/result argument. It should initially contain the size of the structure pointed to by addr. On return it will contain the actual length, in bytes, of the sockaddr structure that has been filled in by the TCP/IP kernel.
2 – Description
This function completes the first connection on the queue of pending connections, creates a new socket with the same properties as s, and allocates and returns a new descriptor for the socket. If no pending connections are present on the queue and the socket is not marked as nonblocking, accept() blocks the caller until a connection request is present. If the socket is marked nonblocking by using a setsockopt() call and no pending connections are present on the queue, accept() returns an error. You cannot use the accepted socket to accept subsequent connections. The original socket s remains open (listening) for other connection requests. This call is used with connection- based socket types (SOCK_STREAM). You can select a socket for the purposes of performing an accept by selecting it for a read. Related Functions See also bind(), connect(), listen(), select(), and socket().
3 – Return Values
x A positive integer that is a descriptor for the accepted socket. -1 Error; errno is set to indicate the error.
4 – Errors
EBADF The socket descriptor is invalid. ECONNABORTED A connection has been aborted. EFAULT The addr argument is not in a writable part of the user address space. EINTR The accept() function was interrupted by a signal before a valid connection arrived. EINVAL The socket is not accepting connections. EMFILE There are too many open file descriptors. ENFILE The maximum number of file descriptors in the system is already open. ENETDOWN TCP/IP Services was not started. ENOBUFS The system has insufficient resources to complete the call. ENOMEM The system was unable to allocate kernel memory. ENOTSOCK The socket descriptor is invalid. EOPNOTSUPP The reference socket is not of type SOCK_ STREAM. EPROTO A protocol error occurred. EWOULDBLOCK The socket is marked nonblocking, and no connections are present to be accepted.