2004-11-03 13:51:07 +00:00
|
|
|
.\" Copyright (c) 1983, 1990, 1991 The Regents of the University of California.
|
|
|
|
.\" All rights reserved.
|
|
|
|
.\"
|
|
|
|
.\" Redistribution and use in source and binary forms, with or without
|
|
|
|
.\" modification, are permitted provided that the following conditions
|
|
|
|
.\" are met:
|
|
|
|
.\" 1. Redistributions of source code must retain the above copyright
|
|
|
|
.\" notice, this list of conditions and the following disclaimer.
|
|
|
|
.\" 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
.\" notice, this list of conditions and the following disclaimer in the
|
|
|
|
.\" documentation and/or other materials provided with the distribution.
|
|
|
|
.\" 3. All advertising materials mentioning features or use of this software
|
|
|
|
.\" must display the following acknowledgement:
|
|
|
|
.\" This product includes software developed by the University of
|
|
|
|
.\" California, Berkeley and its contributors.
|
|
|
|
.\" 4. Neither the name of the University nor the names of its contributors
|
|
|
|
.\" may be used to endorse or promote products derived from this software
|
|
|
|
.\" without specific prior written permission.
|
|
|
|
.\"
|
|
|
|
.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
|
|
|
.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
.\" SUCH DAMAGE.
|
|
|
|
.\"
|
|
|
|
.\" Modified 1993-07-24 by Rik Faith <faith@cs.unc.edu>
|
|
|
|
.\" Modified 1996-10-21 by Eric S. Raymond <esr@thyrsus.com>
|
|
|
|
.\" Modified 1998-2000 by Andi Kleen to match Linux 2.2 reality
|
|
|
|
.\" Modified 2002-04-23 by Roger Luethi <rl@hellgate.ch>
|
2007-09-20 06:52:22 +00:00
|
|
|
.\" Modified 2004-06-17 by Michael Kerrisk <mtk.manpages@gmail.com>
|
2008-12-04 15:01:54 +00:00
|
|
|
.\" 2008-12-04, mtk, Add documentation of accept4()
|
2004-11-03 13:51:07 +00:00
|
|
|
.\"
|
accept.2, clone.2, dup.2, fallocate.2, pipe.2, readahead.2, sched_setaffinity.2, unshare.2, CPU_SET.3, endian.3, euidaccess.3, fexecve.3, getpt.3, getpw.3, getumask.3, getutmp.3, gnu_get_libc_version.3, makedev.3, matherr.3, mbsnrtowcs.3, memfrob.3, pthread_attr_setaffinity_np.3, pthread_getattr_np.3, pthread_setaffinity_np.3, pthread_tryjoin_np.3, tcgetsid.3, wcscasecmp.3, wcsncasecmp.3, wcsnlen.3, wcsnrtombs.3, wcswidth.3, rtld-audit.7: SYNOPSIS: Add reference to feature_test_macros(7)
These pages specify feature test macros in the function
prototypes. Add a reference to feature_test_macros(7),
so that readers are pointed to the information that
feature test macros must be defined before including
*any* header file.
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2010-09-10 05:06:22 +00:00
|
|
|
.TH ACCEPT 2 2010-09-10 "Linux" "Linux Programmer's Manual"
|
2004-11-03 13:51:07 +00:00
|
|
|
.SH NAME
|
|
|
|
accept \- accept a connection on a socket
|
|
|
|
.SH SYNOPSIS
|
2008-12-04 15:01:54 +00:00
|
|
|
.nf
|
2007-06-10 18:08:27 +00:00
|
|
|
.BR "#include <sys/types.h>" " /* See NOTES */"
|
2004-11-03 13:51:07 +00:00
|
|
|
.B #include <sys/socket.h>
|
2008-12-04 15:01:54 +00:00
|
|
|
|
2005-06-30 10:16:11 +00:00
|
|
|
.BI "int accept(int " sockfd ", struct sockaddr *" addr ", socklen_t *" addrlen );
|
2008-12-04 15:01:54 +00:00
|
|
|
|
accept.2, clone.2, dup.2, fallocate.2, pipe.2, readahead.2, sched_setaffinity.2, unshare.2, CPU_SET.3, endian.3, euidaccess.3, fexecve.3, getpt.3, getpw.3, getumask.3, getutmp.3, gnu_get_libc_version.3, makedev.3, matherr.3, mbsnrtowcs.3, memfrob.3, pthread_attr_setaffinity_np.3, pthread_getattr_np.3, pthread_setaffinity_np.3, pthread_tryjoin_np.3, tcgetsid.3, wcscasecmp.3, wcsncasecmp.3, wcsnlen.3, wcsnrtombs.3, wcswidth.3, rtld-audit.7: SYNOPSIS: Add reference to feature_test_macros(7)
These pages specify feature test macros in the function
prototypes. Add a reference to feature_test_macros(7),
so that readers are pointed to the information that
feature test macros must be defined before including
*any* header file.
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2010-09-10 05:06:22 +00:00
|
|
|
.BR "#define _GNU_SOURCE" " /* See feature_test_macros(7) */"
|
2008-12-04 15:01:54 +00:00
|
|
|
.B #include <sys/socket.h>
|
|
|
|
|
|
|
|
.BI "int accept4(int " sockfd ", struct sockaddr *" addr ,
|
|
|
|
.BI " socklen_t *" addrlen ", int " flags );
|
|
|
|
.fi
|
2004-11-03 13:51:07 +00:00
|
|
|
.SH DESCRIPTION
|
|
|
|
The
|
2005-06-30 10:16:11 +00:00
|
|
|
.BR accept ()
|
|
|
|
system call is used with connection-based socket types
|
2004-11-03 13:51:07 +00:00
|
|
|
.RB ( SOCK_STREAM ,
|
2006-05-02 20:03:41 +00:00
|
|
|
.BR SOCK_SEQPACKET ).
|
2004-11-03 13:51:07 +00:00
|
|
|
It extracts the first connection request on the queue of pending
|
2008-07-04 15:23:23 +00:00
|
|
|
connections for the listening socket,
|
|
|
|
.IR sockfd ,
|
|
|
|
creates a new connected socket, and returns a new file
|
2005-06-30 10:16:11 +00:00
|
|
|
descriptor referring to that socket.
|
|
|
|
The newly created socket is not in the listening state.
|
2004-11-03 13:51:07 +00:00
|
|
|
The original socket
|
2005-06-30 10:16:11 +00:00
|
|
|
.I sockfd
|
|
|
|
is unaffected by this call.
|
2004-11-03 13:51:07 +00:00
|
|
|
.PP
|
|
|
|
The argument
|
2005-06-30 10:16:11 +00:00
|
|
|
.I sockfd
|
2004-11-03 13:51:07 +00:00
|
|
|
is a socket that has been created with
|
|
|
|
.BR socket (2),
|
|
|
|
bound to a local address with
|
|
|
|
.BR bind (2),
|
|
|
|
and is listening for connections after a
|
|
|
|
.BR listen (2).
|
|
|
|
|
|
|
|
The argument
|
|
|
|
.I addr
|
2007-04-12 22:42:49 +00:00
|
|
|
is a pointer to a
|
2005-06-30 10:16:11 +00:00
|
|
|
.I sockaddr
|
|
|
|
structure.
|
|
|
|
This structure is filled in with the address of the peer socket,
|
|
|
|
as known to the communications layer.
|
|
|
|
The exact format of the address returned
|
2004-11-03 13:51:07 +00:00
|
|
|
.I addr
|
2005-06-30 10:16:11 +00:00
|
|
|
is determined by the socket's address family (see
|
2007-04-12 22:42:49 +00:00
|
|
|
.BR socket (2)
|
2004-11-03 13:51:07 +00:00
|
|
|
and the respective protocol man pages).
|
2008-12-03 20:17:18 +00:00
|
|
|
When
|
|
|
|
.I addr
|
|
|
|
is NULL, nothing is filled in; in this case,
|
|
|
|
.I addrlen
|
|
|
|
is not used, and should also be NULL.
|
|
|
|
|
2004-11-03 13:51:07 +00:00
|
|
|
The
|
|
|
|
.I addrlen
|
2008-12-03 20:17:18 +00:00
|
|
|
argument is a value-result argument:
|
|
|
|
the caller must initialize it to contain the
|
|
|
|
size (in bytes) of the structure pointed to by
|
2004-11-03 13:51:07 +00:00
|
|
|
.IR addr ;
|
2008-12-03 20:17:18 +00:00
|
|
|
on return it will contain the actual size of the peer address.
|
|
|
|
|
|
|
|
The returned address is truncated if the buffer provided is too small;
|
|
|
|
in this case,
|
|
|
|
.I addrlen
|
|
|
|
will return a value greater than was supplied to the call.
|
2004-11-03 13:51:07 +00:00
|
|
|
.PP
|
|
|
|
If no pending
|
|
|
|
connections are present on the queue, and the socket is not marked as
|
accept.2, connect.2, eventfd.2, flock.2, open.2, posix_fadvise.2, read.2, recv.2, sched_setscheduler.2, select_tut.2, send.2, signalfd.2, splice.2, timerfd_create.2, write.2, flockfile.3, mkfifo.3, mq_notify.3, mq_open.3, pthread_tryjoin_np.3, scanf.3, random.4, ddp.7, epoll.7, fifo.7, ip.7, pipe.7, socket.7, spufs.7: Global fix: s/non-blocking/nonblocking/
The tendency in English, as prescribed in style guides like
Chicago MoS, is towards removing hyphens after prefixes
like "non-" etc.
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2010-01-16 16:43:10 +00:00
|
|
|
nonblocking,
|
2005-06-30 10:16:11 +00:00
|
|
|
.BR accept ()
|
2007-04-12 22:42:49 +00:00
|
|
|
blocks the caller until a connection is present.
|
|
|
|
If the socket is marked
|
accept.2, connect.2, eventfd.2, flock.2, open.2, posix_fadvise.2, read.2, recv.2, sched_setscheduler.2, select_tut.2, send.2, signalfd.2, splice.2, timerfd_create.2, write.2, flockfile.3, mkfifo.3, mq_notify.3, mq_open.3, pthread_tryjoin_np.3, scanf.3, random.4, ddp.7, epoll.7, fifo.7, ip.7, pipe.7, socket.7, spufs.7: Global fix: s/non-blocking/nonblocking/
The tendency in English, as prescribed in style guides like
Chicago MoS, is towards removing hyphens after prefixes
like "non-" etc.
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2010-01-16 16:43:10 +00:00
|
|
|
nonblocking and no pending connections are present on the queue,
|
2005-06-30 10:16:11 +00:00
|
|
|
.BR accept ()
|
2007-06-22 17:16:20 +00:00
|
|
|
fails with the error
|
2009-02-23 04:57:43 +00:00
|
|
|
.BR EAGAIN
|
|
|
|
or
|
|
|
|
.BR EWOULDBLOCK .
|
2004-11-03 13:51:07 +00:00
|
|
|
.PP
|
|
|
|
In order to be notified of incoming connections on a socket, you can use
|
|
|
|
.BR select (2)
|
|
|
|
or
|
|
|
|
.BR poll (2).
|
|
|
|
A readable event will be delivered when a new connection is attempted and you
|
|
|
|
may then call
|
2005-06-30 10:16:11 +00:00
|
|
|
.BR accept ()
|
2007-04-12 22:42:49 +00:00
|
|
|
to get a socket for that connection.
|
|
|
|
Alternatively, you can set the socket to deliver
|
2004-11-03 13:51:07 +00:00
|
|
|
.B SIGIO
|
|
|
|
when activity occurs on a socket; see
|
|
|
|
.BR socket (7)
|
|
|
|
for details.
|
|
|
|
.PP
|
|
|
|
For certain protocols which require an explicit confirmation,
|
|
|
|
such as
|
|
|
|
DECNet,
|
2005-06-30 10:16:11 +00:00
|
|
|
.BR accept ()
|
2004-11-03 13:51:07 +00:00
|
|
|
can be thought of as merely dequeuing the next connection request and not
|
2007-04-12 22:42:49 +00:00
|
|
|
implying confirmation.
|
|
|
|
Confirmation can be implied by
|
2004-11-03 13:51:07 +00:00
|
|
|
a normal read or write on the new file descriptor, and rejection can be
|
2007-04-12 22:42:49 +00:00
|
|
|
implied by closing the new socket.
|
|
|
|
Currently only
|
|
|
|
DECNet
|
|
|
|
has these semantics on Linux.
|
2008-12-04 15:01:54 +00:00
|
|
|
|
|
|
|
If
|
|
|
|
.IR flags
|
|
|
|
is 0, then
|
|
|
|
.BR accept4 ()
|
|
|
|
is the same as
|
|
|
|
.BR accept ().
|
|
|
|
The following values can be bitwise ORed in
|
|
|
|
.IR flags
|
|
|
|
to obtain different behavior:
|
|
|
|
.TP 16
|
|
|
|
.B SOCK_NONBLOCK
|
|
|
|
Set the
|
|
|
|
.BR O_NONBLOCK
|
|
|
|
file status flag on the new open file description.
|
|
|
|
Using this flag saves extra calls to
|
|
|
|
.BR fcntl (2)
|
|
|
|
to achieve the same result.
|
|
|
|
.TP
|
|
|
|
.B SOCK_CLOEXEC
|
|
|
|
Set the close-on-exec
|
|
|
|
.RB ( FD_CLOEXEC )
|
|
|
|
flag on the new file descriptor.
|
|
|
|
See the description of the
|
|
|
|
.B O_CLOEXEC
|
|
|
|
flag in
|
|
|
|
.BR open (2)
|
|
|
|
for reasons why this may be useful.
|
2004-11-03 13:51:07 +00:00
|
|
|
.SH "RETURN VALUE"
|
2004-12-20 12:24:06 +00:00
|
|
|
On success,
|
_syscall.2, accept.2, epoll_create.2, inotify_add_watch.2, ioctl.2, msgget.2, msgop.2, open.2, prctl.2, sched_setscheduler.2, semctl.2, semget.2, swapon.2, addseverity.3, cacosh.3, csqrt.3, dirfd.3, drand48.3, fputws.3, mq_send.3, posix_openpt.3, puts.3, sched_getcpu.3, shm_open.3, sqrt.3, sysconf.3, tgamma.3, ulimit.3, credentials.7, svipc.7: Global fix: s/non-negative/nonnegative/
The tendency in English, as prescribed in style guides like
Chicago MoS, is towards removing hyphens after prefixes
like "non-" etc.
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2010-01-16 16:44:48 +00:00
|
|
|
these system calls return a nonnegative integer that is a descriptor
|
2004-12-20 12:24:06 +00:00
|
|
|
for the accepted socket.
|
|
|
|
On error, \-1 is returned, and
|
|
|
|
.I errno
|
|
|
|
is set appropriately.
|
2007-05-16 02:45:55 +00:00
|
|
|
.SS "Error Handling"
|
2007-04-12 22:42:49 +00:00
|
|
|
Linux
|
2005-06-30 10:16:11 +00:00
|
|
|
.BR accept ()
|
2008-12-04 15:01:54 +00:00
|
|
|
(and
|
|
|
|
.BR accept4 ())
|
2007-04-12 22:42:49 +00:00
|
|
|
passes already-pending network errors on the new socket
|
|
|
|
as an error code from
|
|
|
|
.BR accept ().
|
2007-06-08 09:56:56 +00:00
|
|
|
This behavior differs from other BSD socket
|
2007-04-12 22:42:49 +00:00
|
|
|
implementations.
|
|
|
|
For reliable operation the application should detect
|
|
|
|
the network errors defined for the protocol after
|
2005-06-30 10:16:11 +00:00
|
|
|
.BR accept ()
|
2004-11-03 13:51:07 +00:00
|
|
|
and treat
|
2007-04-12 22:42:49 +00:00
|
|
|
them like
|
2007-09-20 16:26:31 +00:00
|
|
|
.B EAGAIN
|
2007-04-12 22:42:49 +00:00
|
|
|
by retrying.
|
2012-05-06 18:44:01 +00:00
|
|
|
In the case of TCP/IP, these are
|
2004-11-03 13:51:07 +00:00
|
|
|
.BR ENETDOWN ,
|
|
|
|
.BR EPROTO ,
|
|
|
|
.BR ENOPROTOOPT ,
|
|
|
|
.BR EHOSTDOWN ,
|
|
|
|
.BR ENONET ,
|
|
|
|
.BR EHOSTUNREACH ,
|
|
|
|
.BR EOPNOTSUPP ,
|
|
|
|
and
|
|
|
|
.BR ENETUNREACH .
|
|
|
|
.SH ERRORS
|
|
|
|
.TP
|
|
|
|
.BR EAGAIN " or " EWOULDBLOCK
|
2009-02-23 04:57:43 +00:00
|
|
|
.\" Actually EAGAIN on Linux
|
accept.2, connect.2, eventfd.2, flock.2, open.2, posix_fadvise.2, read.2, recv.2, sched_setscheduler.2, select_tut.2, send.2, signalfd.2, splice.2, timerfd_create.2, write.2, flockfile.3, mkfifo.3, mq_notify.3, mq_open.3, pthread_tryjoin_np.3, scanf.3, random.4, ddp.7, epoll.7, fifo.7, ip.7, pipe.7, socket.7, spufs.7: Global fix: s/non-blocking/nonblocking/
The tendency in English, as prescribed in style guides like
Chicago MoS, is towards removing hyphens after prefixes
like "non-" etc.
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2010-01-16 16:43:10 +00:00
|
|
|
The socket is marked nonblocking and no connections are
|
2004-11-03 13:51:07 +00:00
|
|
|
present to be accepted.
|
2009-02-23 04:57:43 +00:00
|
|
|
POSIX.1-2001 allows either error to be returned for this case,
|
|
|
|
and does not require these constants to have the same value,
|
|
|
|
so a portable application should check for both possibilities.
|
2004-11-03 13:51:07 +00:00
|
|
|
.TP
|
|
|
|
.B EBADF
|
|
|
|
The descriptor is invalid.
|
|
|
|
.TP
|
|
|
|
.B ECONNABORTED
|
|
|
|
A connection has been aborted.
|
|
|
|
.TP
|
2008-12-04 15:05:40 +00:00
|
|
|
.B EFAULT
|
|
|
|
The
|
|
|
|
.I addr
|
|
|
|
argument is not in a writable part of the user address space.
|
|
|
|
.TP
|
2004-11-03 13:51:07 +00:00
|
|
|
.B EINTR
|
|
|
|
The system call was interrupted by a signal that was caught
|
2008-07-04 15:50:36 +00:00
|
|
|
before a valid connection arrived; see
|
|
|
|
.BR signal (7).
|
2004-11-03 13:51:07 +00:00
|
|
|
.TP
|
|
|
|
.B EINVAL
|
2006-03-31 22:12:10 +00:00
|
|
|
Socket is not listening for connections, or
|
|
|
|
.I addrlen
|
|
|
|
is invalid (e.g., is negative).
|
2004-11-03 13:51:07 +00:00
|
|
|
.TP
|
2008-12-04 15:01:54 +00:00
|
|
|
.B EINVAL
|
|
|
|
.RB ( accept4 ())
|
|
|
|
invalid value in
|
|
|
|
.IR flags .
|
|
|
|
.TP
|
2004-11-03 13:51:07 +00:00
|
|
|
.B EMFILE
|
|
|
|
The per-process limit of open file descriptors has been reached.
|
|
|
|
.TP
|
|
|
|
.B ENFILE
|
|
|
|
The system limit on the total number of open files has been reached.
|
|
|
|
.TP
|
2008-12-04 15:05:40 +00:00
|
|
|
.BR ENOBUFS ", " ENOMEM
|
|
|
|
Not enough free memory.
|
|
|
|
This often means that the memory allocation is limited by the socket buffer
|
|
|
|
limits, not by the system memory.
|
|
|
|
.TP
|
2004-11-03 13:51:07 +00:00
|
|
|
.B ENOTSOCK
|
|
|
|
The descriptor references a file, not a socket.
|
|
|
|
.TP
|
|
|
|
.B EOPNOTSUPP
|
|
|
|
The referenced socket is not of type
|
2007-04-12 22:42:49 +00:00
|
|
|
.BR SOCK_STREAM .
|
2004-11-03 13:51:07 +00:00
|
|
|
.TP
|
|
|
|
.B EPROTO
|
|
|
|
Protocol error.
|
|
|
|
.PP
|
2008-12-04 15:05:40 +00:00
|
|
|
In addition, Linux
|
2005-06-30 10:16:11 +00:00
|
|
|
.BR accept ()
|
2004-11-03 13:51:07 +00:00
|
|
|
may fail if:
|
|
|
|
.TP
|
|
|
|
.B EPERM
|
|
|
|
Firewall rules forbid connection.
|
|
|
|
.PP
|
|
|
|
In addition, network errors for the new socket and as defined
|
2007-04-12 22:42:49 +00:00
|
|
|
for the protocol may be returned.
|
|
|
|
Various Linux kernels can
|
2004-11-03 13:51:07 +00:00
|
|
|
return other errors such as
|
|
|
|
.BR ENOSR ,
|
|
|
|
.BR ESOCKTNOSUPPORT ,
|
|
|
|
.BR EPROTONOSUPPORT ,
|
|
|
|
.BR ETIMEDOUT .
|
|
|
|
The value
|
|
|
|
.B ERESTARTSYS
|
|
|
|
may be seen during a trace.
|
2008-12-04 15:01:54 +00:00
|
|
|
.SH VERSIONS
|
|
|
|
The
|
|
|
|
.BR accept4 ()
|
|
|
|
system call is available starting with Linux 2.6.28;
|
|
|
|
support in glibc is available starting with version 2.10.
|
2004-11-03 13:51:07 +00:00
|
|
|
.SH "CONFORMING TO"
|
2008-12-04 15:01:54 +00:00
|
|
|
.BR accept ():
|
|
|
|
POSIX.1-2001,
|
2007-04-12 22:42:49 +00:00
|
|
|
SVr4, 4.4BSD,
|
2005-06-30 10:16:11 +00:00
|
|
|
.RB ( accept ()
|
2008-12-04 15:01:54 +00:00
|
|
|
first appeared in 4.2BSD).
|
2006-08-04 09:41:28 +00:00
|
|
|
.\" The BSD man page documents five possible error returns
|
|
|
|
.\" (EBADF, ENOTSOCK, EOPNOTSUPP, EWOULDBLOCK, EFAULT).
|
2007-04-12 22:42:49 +00:00
|
|
|
.\" POSIX.1-2001 documents errors
|
2006-08-04 09:41:28 +00:00
|
|
|
.\" EAGAIN, EBADF, ECONNABORTED, EINTR, EINVAL, EMFILE,
|
2007-04-12 22:42:49 +00:00
|
|
|
.\" ENFILE, ENOBUFS, ENOMEM, ENOTSOCK, EOPNOTSUPP, EPROTO, EWOULDBLOCK.
|
2006-08-04 09:41:28 +00:00
|
|
|
.\" In addition, SUSv2 documents EFAULT and ENOSR.
|
2008-12-04 15:01:54 +00:00
|
|
|
|
|
|
|
.BR accept4 ()
|
accept.2, execve.2, futimesat.2, getresuid.2, getrlimit.2, madvise.2, mq_getsetattr.2, msgctl.2, nice.2, open.2, poll.2, setresuid.2, shmctl.2, sigaction.2, times.2, utimensat.2, __setfpucw.3, atoi.3, endian.3, err.3, euidaccess.3, fenv.3, fopencookie.3, fpurge.3, getgrouplist.3, getutmp.3, j0.3, lgamma.3, netlink.3, pthread_attr_init.3, pthread_attr_setaffinity_np.3, pthread_cleanup_push_defer_np.3, pthread_getattr_np.3, pthread_kill_other_threads_np.3, pthread_setaffinity_np.3, pthread_tryjoin_np.3, pthread_yield.3, random_r.3, readdir.3, rtnetlink.3, scanf.3, setenv.3, significand.3, sigsetops.3, strerror.3, strstr.3, sysv_signal.3, termios.3, timegm.3, unlocked_stdio.3, y0.3, locale.5, bootparam.7, feature_test_macros.7, ip.7, locale.7, pthreads.7, rtld-audit.7, nscd.8: Global fix: s/non-standard/nonstandard/
The tendency in English, as prescribed in style guides like
Chicago MoS, is towards removing hyphens after prefixes
like "non-" etc.
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2010-01-16 16:37:52 +00:00
|
|
|
is a nonstandard Linux extension.
|
2004-11-03 13:51:07 +00:00
|
|
|
.LP
|
2005-06-30 10:16:11 +00:00
|
|
|
On Linux, the new socket returned by
|
2007-04-12 22:42:49 +00:00
|
|
|
.BR accept ()
|
2005-06-30 10:16:11 +00:00
|
|
|
does \fInot\fP inherit file status flags such as
|
2007-09-20 16:26:31 +00:00
|
|
|
.B O_NONBLOCK
|
2005-06-30 10:16:11 +00:00
|
|
|
and
|
2007-09-20 16:26:31 +00:00
|
|
|
.B O_ASYNC
|
2005-06-30 10:16:11 +00:00
|
|
|
from the listening socket.
|
2007-06-08 09:56:56 +00:00
|
|
|
This behavior differs from the canonical BSD sockets implementation.
|
2005-06-30 10:16:11 +00:00
|
|
|
.\" Some testing seems to show that Tru64 5.1 and HP-UX 11 also
|
|
|
|
.\" do not inherit file status flags -- MTK Jun 05
|
accept.2, access.2, acct.2, clock_nanosleep.2, mbind.2, mincore.2, remap_file_pages.2, sched_setscheduler.2, set_mempolicy.2, splice.2, stat.2, syslog.2, timer_create.2, timerfd_create.2, truncate.2, fenv.3, ferror.3, fflush.3, fgetwc.3, fgetws.3, flockfile.3, fputwc.3, fputws.3, fread.3, getopt.3, gets.3, getwchar.3, glob.3, iconv.3, longjmp.3, pow.3, printf.3, puts.3, putwchar.3, regex.3, rpc.3, scanf.3, setjmp.3, termios.3, unlocked_stdio.3, wcswidth.3, hd.4, rtc.4, st.4, core.5, dir_colors.5, elf.5, proc.5, arp.7, ascii.7, boot.7, bootparam.7, charsets.7, futex.7, ip.7, iso_8859-11.7, man-pages.7, man.7, mdoc.samples.7, path_resolution.7, pipe.7, posixoptions.7, unicode.7, unix.7, uri.7, utf-8.7, ld.so.8: s/non-/non/
The tendency in English, as prescribed in style guides like
Chicago MoS, is towards removing hyphens after prefixes
like "non-" etc.
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2010-01-16 17:20:12 +00:00
|
|
|
Portable programs should not rely on inheritance or noninheritance
|
2007-04-12 22:42:49 +00:00
|
|
|
of file status flags and always explicitly set all required flags on
|
|
|
|
the socket returned from
|
2005-06-30 10:16:11 +00:00
|
|
|
.BR accept ().
|
2007-05-16 02:54:18 +00:00
|
|
|
.SH NOTES
|
2007-06-10 18:08:27 +00:00
|
|
|
POSIX.1-2001 does not require the inclusion of
|
|
|
|
.IR <sys/types.h> ,
|
|
|
|
and this header file is not required on Linux.
|
|
|
|
However, some historical (BSD) implementations required this header
|
|
|
|
file, and portable applications are probably wise to include it.
|
|
|
|
|
2007-05-18 16:06:42 +00:00
|
|
|
There may not always be a connection waiting after a
|
|
|
|
.B SIGIO
|
|
|
|
is delivered or
|
|
|
|
.BR select (2)
|
|
|
|
or
|
|
|
|
.BR poll (2)
|
|
|
|
return a readability event because the connection might have been
|
|
|
|
removed by an asynchronous network error or another thread before
|
|
|
|
.BR accept ()
|
|
|
|
is called.
|
|
|
|
If this happens then the call will block waiting for the next
|
|
|
|
connection to arrive.
|
|
|
|
To ensure that
|
|
|
|
.BR accept ()
|
|
|
|
never blocks, the passed socket
|
|
|
|
.I sockfd
|
|
|
|
needs to have the
|
|
|
|
.B O_NONBLOCK
|
|
|
|
flag set (see
|
|
|
|
.BR socket (7)).
|
|
|
|
.SS The socklen_t type
|
2004-11-03 13:51:07 +00:00
|
|
|
The third argument of
|
2005-06-30 10:16:11 +00:00
|
|
|
.BR accept ()
|
2007-06-12 21:19:16 +00:00
|
|
|
was originally declared as an \fIint *\fP (and is that under libc4 and libc5
|
2006-08-03 13:57:17 +00:00
|
|
|
and on many other systems like 4.x BSD, SunOS 4, SGI); a POSIX.1g draft
|
2007-06-12 21:19:16 +00:00
|
|
|
standard wanted to change it into a \fIsize_t *\fP, and that is what it is
|
2004-11-03 13:51:07 +00:00
|
|
|
for SunOS 5.
|
2007-06-12 21:19:16 +00:00
|
|
|
Later POSIX drafts have \fIsocklen_t *\fP,
|
intro.1, time.1, accept.2, bind.2, connect.2, execve.2, flock.2, getdents.2, getpriority.2, getuid.2, intro.2, ioctl.2, mincore.2, mknod.2, personality.2, ptrace.2, read.2, recv.2, select_tut.2, send.2, sendfile.2, shmctl.2, sigaction.2, signal.2, stat.2, times.2, truncate.2, umask.2, wait.2, MB_CUR_MAX.3, MB_LEN_MAX.3, argz_add.3, btowc.3, clearenv.3, clock.3, cmsg.3, end.3, endian.3, errno.3, exit.3, fgetwc.3, fgetws.3, fopen.3, fputwc.3, fputws.3, fseek.3, fwide.3, getfsent.3, getgrnam.3, gethostid.3, getipnodebyname.3, getmntent.3, getpwnam.3, getwchar.3, grantpt.3, iconv.3, iconv_close.3, iconv_open.3, insque.3, intro.3, iswalnum.3, iswalpha.3, iswblank.3, iswcntrl.3, iswctype.3, iswdigit.3, iswgraph.3, iswlower.3, iswprint.3, iswpunct.3, iswspace.3, iswupper.3, iswxdigit.3, malloc.3, mblen.3, mbrlen.3, mbrtowc.3, mbsinit.3, mbsnrtowcs.3, mbsrtowcs.3, mbstowcs.3, mbtowc.3, mkstemp.3, mktemp.3, nl_langinfo.3, openpty.3, posix_openpt.3, printf.3, ptsname.3, putwchar.3, qecvt.3, rcmd.3, readdir.3, rexec.3, rpc.3, setnetgrent.3, shm_open.3, sigpause.3, stdin.3, stpcpy.3, strftime.3, strptime.3, syslog.3, towctrans.3, towlower.3, towupper.3, ttyslot.3, ungetwc.3, unlocked_stdio.3, wcpcpy.3, wcpncpy.3, wcrtomb.3, wcscasecmp.3, wcscat.3, wcschr.3, wcscmp.3, wcscpy.3, wcscspn.3, wcsdup.3, wcslen.3, wcsncasecmp.3, wcsncat.3, wcsncmp.3, wcsncpy.3, wcsnlen.3, wcsnrtombs.3, wcspbrk.3, wcsrchr.3, wcsrtombs.3, wcsspn.3, wcsstr.3, wcstok.3, wcstombs.3, wcswidth.3, wctob.3, wctomb.3, wctrans.3, wctype.3, wcwidth.3, wmemchr.3, wmemcmp.3, wmemcpy.3, wmemmove.3, wmemset.3, wprintf.3, console_ioctl.4, pts.4, elf.5, filesystems.5, hosts.5, proc.5, ttytype.5, boot.7, capabilities.7, credentials.7, epoll.7, glob.7, koi8-r.7, path_resolution.7, pty.7, signal.7, suffixes.7, time.7, unicode.7, unix.7, uri.7, utf-8.7: global fix: s/Unix/UNIX/
The man pages were rather inconsistent in the use of "Unix"
versus "UNIX". Let's go with the trademark usage.
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2010-10-12 04:45:38 +00:00
|
|
|
and so do the Single UNIX Specification and glibc2.
|
2004-11-03 13:51:07 +00:00
|
|
|
Quoting Linus Torvalds:
|
|
|
|
|
|
|
|
.\" .I fails: only italicizes a single line
|
|
|
|
"_Any_ sane library _must_ have "socklen_t" be the same size
|
2007-04-12 22:42:49 +00:00
|
|
|
as int.
|
|
|
|
Anything else breaks any BSD socket layer stuff.
|
2006-03-20 00:52:31 +00:00
|
|
|
POSIX initially \fIdid\fP make it a size_t, and I (and hopefully others, but
|
2007-04-12 22:42:49 +00:00
|
|
|
obviously not too many) complained to them very loudly indeed.
|
|
|
|
Making it a size_t is completely broken, exactly because size_t very
|
|
|
|
seldom is the same size as "int" on 64-bit architectures, for example.
|
|
|
|
And it
|
2006-03-20 00:52:31 +00:00
|
|
|
\fIhas\fP to be the same size as "int" because that's what the BSD socket
|
2007-04-12 22:42:49 +00:00
|
|
|
interface is.
|
|
|
|
Anyway, the POSIX people eventually got a clue, and created "socklen_t".
|
2004-11-03 13:51:07 +00:00
|
|
|
They shouldn't have touched it in the first place, but once they did
|
|
|
|
they felt it had to have a named type for some unfathomable reason
|
|
|
|
(probably somebody didn't like losing face over having done the original
|
|
|
|
stupid thing, so they silently just renamed their blunder)."
|
2007-05-28 10:40:39 +00:00
|
|
|
.SH EXAMPLE
|
|
|
|
See
|
|
|
|
.BR bind (2).
|
2004-11-03 13:51:07 +00:00
|
|
|
.SH "SEE ALSO"
|
|
|
|
.BR bind (2),
|
|
|
|
.BR connect (2),
|
|
|
|
.BR listen (2),
|
|
|
|
.BR select (2),
|
2008-12-01 15:26:37 +00:00
|
|
|
.BR socket (2),
|
|
|
|
.BR socket (7)
|