ACCEPT(2) | System Calls Manual | ACCEPT(2) |
int
accept(int s, struct sockaddr * restrict addr, socklen_t * restrict addrlen);
int
paccept(int s, struct sockaddr * restrict addr, socklen_t * restrict addrlen, const sigset_t * restrict sigmask, int flags);
The argument addr is a result parameter that is filled in with the address of the connecting entity, as known to the communications layer. The exact format of the addr parameter is determined by the domain in which the communication is occurring. The addrlen is a value-result parameter; it should initially contain the amount of space pointed to by addr; on return it will contain the actual length (in bytes) of the address returned. This call is used with connection-based socket types, currently with SOCK_STREAM.
It is possible to select(2) or poll(2) a socket for the purposes of doing an accept() by selecting or polling it for read.
For certain protocols which require an explicit confirmation, such as ISO or DATAKIT, accept() can be thought of as merely dequeuing the next connection request and not implying confirmation. Confirmation can be implied by a normal read or write on the new file descriptor, and rejection can be implied by closing the new socket.
One can obtain user connection request data without confirming the connection by issuing a recvmsg(2) call with an msg_iovlen of 0 and a non-zero msg_controllen, or by issuing a getsockopt(2) request. Similarly, one can provide user connection rejection information by issuing a sendmsg(2) call with providing only the control information, or by calling setsockopt(2).
The paccept() function behaves exactly like accept(), but it also allows to set the following flags on the returned file descriptor:
SOCK_CLOEXEC Set the close on exec property. |
SOCK_NONBLOCK Sets non-blocking I/O. |
It can also temporarily replace the signal mask of the calling thread if sigmask is a non-NULL pointer, then the paccept() function shall replace the signal mask of the caller by the set of signals pointed to by sigmask before waiting for a connection, and shall restore the signal mask of the calling thread before returning.
June 2, 2011 | NetBSD 6.1 |