COHERENT manpages
This page displays the COHERENT manpage for accept() [Accept a connection on a socket].
List of available manpages
Index
accept() -- Sockets Function (libsocket) Accept a connection on a socket #include <sys/types.h> #include <sys/socket.h> int accept(socket, address, addrlen) int socket, *addrlen; struct sockaddr *address; accept() accepts a connection on a socket. It extracts the first connection request on the queue of pending connections, creates a new socket with the same properties as socket, and allocates a file descriptor for the newly created socket. It is used with connection-based types of sockets, currently with SOCK_STREAM. socket gives a file descriptor that identifies a socket. It must have been returned by a call to socket(), have been bound to an address by a call to bind(), and be listening for connections after a call to listen(). If no connections are pending on the queue and socket is not marked as non- blocking, accept() blocks the calling process until it can establish a connection. If socket is marked non-blocking and no connections are pending on the queue, accept() returns an error, as described below. The accepted socket may not be used to accept more connections; however, the original socket remains open. address gives the address of the connecting entity, as known to the ``communications layer''. Its exact format is dictated by the domain in which communication occurs. addrlen points to an integer that gives the number of bytes available at address. Upon return, that integer contains the number of bytes to which address actually points. The function select() can perform the same action as accept(): simply select the socket for reading. If all goes well, accept() returns the file descriptor for the accepted socket, which is a non-negative integer. If something goes wrong, accept() returns -1 and set errno to an appropriate value. The following lists the errors that can occur, by the value to which accept() sets errno: EBADF socket is somehow invalid. ENOTSOCK socket references a file, not a socket. EOPNOTSUPP socket references a socket that is not of type SOCK_STREAM. EFAULT addr contains an illegal address. EWOULDBLOCK The socket is marked non-blocking, and no connections are present to be accepted. Example For an example of this function, see the Lexicon entry for libsocket. See Also bind(), connect(), libsocket, listen(), select()