Sockets Library Functions accept(3SOCKET) NAME accept - accept a connection on a socket SYNOPSIS cc [ _f_l_a_g ... ] _f_i_l_e ... -lsocket -lnsl [ _l_i_b_r_a_r_y ... ] #include #include int accept(int s, struct sockaddr *addr, socklen_t *addrlen); DESCRIPTION The argument _s is a socket that has been created with socket(3SOCKET) and bound to an address with bind(3SOCKET), and that is listening for connections after a call to listen(3SOCKET). The accept() function extracts the first connection on the queue of pending connections, creates a new socket with the properties of _s, and allocates a new file descriptor, _n_s, for the socket. If no pending connec- tions are present on the queue and the socket is not marked as non-blocking, accept() blocks the caller until a connec- tion is present. If the socket is marked as non-blocking and no pending connections are present on the queue, accept() returns an error as described below. The accept() function uses the netconfig(4) file to determine the STREAMS device file name associated with _s. This is the device on which the connect indication will be accepted. The accepted socket, _n_s, is used to read and write data to and from the socket that connected to _n_s; it is not used to accept more connections. The original socket (_s) remains open for accepting further connections. The argument _a_d_d_r is a result parameter that is filled in with the address of the connecting entity as it is known to the communications layer. The exact format of the _a_d_d_r parameter is determined by the domain in which the communi- cation occurs. The argument _a_d_d_r_l_e_n is a value-result parameter. Initially, it contains the amount of space pointed to by _a_d_d_r; on return it contains the length in bytes of the address returned. The accept() function is used with connection-based socket types, currently with SOCK_STREAM. It is possible to select(3C) or poll(2) a socket for the purpose of an accept() by selecting or polling it for a read. However, this will only indicate when a connect indi- cation is pending; it is still necessary to call accept(). SunOS 5.8 Last change: 16 May 1997 1 Sockets Library Functions accept(3SOCKET) RETURN VALUES The accept() function returns -1 on error. If it succeeds, it returns a non-negative integer that is a descriptor for the accepted socket. ERRORS accept() will fail if: EBADF The descriptor is invalid. EINTR The accept attempt was interrupted by the delivery of a signal. EMFILE The per-process descriptor table is full. ENODEV The protocol family and type corresponding to _s could not be found in the netconfig file. ENOMEM There was insufficient user memory available to com- plete the operation. ENOSR There were insufficient STREAMS resources available to complete the operation. ENOTSOCK The descriptor does not reference a socket. EOPNOTSUPP The referenced socket is not of type SOCK_STREAM. EPROTO A protocol error has occurred; for example, the STREAMS protocol stack has not been initialized or the connection has already been released. EWOULDBLOCK The socket is marked as non-blocking and no connec- tions are present to be accepted. ATTRIBUTES See attributes(5) for descriptions of the following attri- butes: ____________________________________________________________ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | |______________________________|______________________________| | MT-Level | Safe | |______________________________|______________________________| SunOS 5.8 Last change: 16 May 1997 2 Sockets Library Functions accept(3SOCKET) SEE ALSO poll(2), bind(3SOCKET), connect(3SOCKET), listen(3SOCKET), select(3C), socket(3SOCKET), netconfig(4), attributes(5), socket(3HEAD) SunOS 5.8 Last change: 16 May 1997 3