accept4 man page on SmartOS

Man page or keyword search:  
man Server   16655 pages
apropos Keyword Search (all sections)
Output format
SmartOS logo
[printable version]


       accept - accept a connection on a socket

       cc [ flag ... ] file ... -lsocket  -lnsl	 [ library ... ]
       #include <sys/types.h>
       #include <sys/socket.h>

       int accept(int s, struct sockaddr *addr, socklen_t *addrlen);

       int accept4(int s, struct sockaddr *addr, socklen_t *addrlen,
	   int flags);

       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, cre‐
       ates  a	new  socket with the properties of s, and allocates a new file
       descriptor, ns, for the socket. If no pending connections  are  present
       on  the	queue  and  the socket is not marked as non-blocking, accept()
       blocks the caller until a connection  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, ns, is used to read
       and write data to and from the socket that connected to ns. It  is  not
       used  to	 accept more connections. The original socket (s) remains open
       for accepting further connections.

       The argument addr 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 addr parameter  is  determined  by  the
       domain in which the communication occurs.

       The  argument  addrlen  is a value-result parameter. Initially, it con‐
       tains the amount of space pointed to by addr; on return it contains the
       length in bytes of the address returned.

       The  accept() function is used with connection-based socket types, cur‐
       rently with SOCK_STREAM.

       The accept4() function allows flags that control the behavior of a suc‐
       cessfully  accepted  socket.  If flags is 0, accept4() acts identically
       to accept(). Values for flags are constructed by a bitwise-inclusive-OR
       of flags from the following list, defined in <sys/socketvar.h>.

		   The accepted socket will have the FD_CLOEXEC flag set as if
		   fcntl() was called on it.  This  flag  is  set  before  the
		   socket  is passed to the caller thus avoiding the race con‐
		   dition between accept() and	fcntl().   See,	 O_CLOEXEC  in
		   open(2) for more details.

		   The	accepted  socket will have the O_NDELAY flag set as if
		   fcntl() was called on it.  This sets the socket  into  non-
		   blocking  mode.   See  O_NDELAY  in fcntl.h(3HEAD) for more

		   The accepted socket will have the O_NONBLOCK flag set as if
		   fcntl()  was	 called on it.	This sets the socket into non-
		   blocking mode (POSIX; see standards(5)).  See O_NONBLOCK in
		   fcntl.h(3HEAD) for more details.

       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 indication is pending; it is still necessary to
       call accept().

       The accept() function returns −1 on error. If it succeeds, it returns a
       non-negative integer that is a descriptor for the accepted socket.

       accept() and accept4() will fail if:

		       The descriptor is invalid.

		       The  remote  side  aborted  the	connection  before the
		       accept() operation completed.

		       The addr parameter or the addrlen parameter is invalid.

		       The accept() attempt was interrupted by the delivery of
		       a signal.

		       The per-process descriptor table is full.

		       The  protocol family and type corresponding to  s could
		       not be found in the netconfig file.

		       There was insufficient user memory  available  to  com‐
		       plete the operation.

		       There  were insufficient STREAMS resources available to
		       complete the operation.

		       The descriptor does not reference a socket.

		       The referenced socket is not of type SOCK_STREAM.

		       A protocol error has occurred; for example, the STREAMS
		       protocol	 stack has not been initialized or the connec‐
		       tion has already been released.

		       The socket is marked as non-blocking and no connections
		       are present to be accepted.

       Additionally, accept4() will fail if:

		       The flags value is invalid. The flags argument can only
		       be the bitwise inclusive-OR of SOCK_CLOEXEC,  SOCK_NON‐
		       BLOCK, and SOCK_NDELAY.

       See attributes(5) for descriptions of the following attributes:

       │MT-Level       │ Safe		 │

       poll(2),	 bind(3SOCKET), connect(3SOCKET), listen(3SOCKET), select(3C),
       socket.h(3HEAD),	   socket(3SOCKET),    netconfig(4),	attributes(5),
       fcntl.h(3HEAD), fcntl(2), standards(5)

				 Apr 19, 2013		       ACCEPT(3SOCKET)

List of man pages available for SmartOS

Copyright (c) for man pages and the logo by the respective OS vendor.

For those who want to learn more, the polarhome community provides shell access and support.

[legal] [privacy] [GNU] [policy] [cookies] [netiquette] [sponsors] [FAQ]
Polarhome, production since 1999.
Member of Polarhome portal.
Based on Fawad Halim's script.
Vote for polarhome
Free Shell Accounts :: the biggest list on the net