Provided by: manpages-zh_1.5.2-1_all
int accept(int s, struct sockaddr *addr, socklen_t *addrlen);
accept (SOCK_STREAM, SOCK_SEQPACKET SOCK_RDM). , s ,, .. s . ( fcntl
F_SETFL ,) accept. .
s socket(2) , bind(2) , listen(2). . addr sockaddr.. ,. addr . (
socket(2) ). addrlen : addr ; . addr NULL,addrlenNULL.
,, accept . , accept EAGAIN.
select(2) poll(2). . , accept ., SIGIO; socket(7)
, DECNet, accept . , .LinuxDECNet .
SIGIO select(2) poll(2) , accept ., . accept , s O_NONBLOCK (
Linux accept accept . BSD., accept ,, EAGAIN .TCP/IP ENETDOWN,
EPROTO, ENOPROTOOPT, EHOSTDOWN, ENONET, EHOSTUNREACH, EOPNOTSUPP,
EFAULT addr .
. , .
,. Linux EMFILE, EINVAL, ENOSR, ENOBUFS, EPERM, ECONNABORTED,
ESOCKTNOSUPPORT, EPROTONOSUPPORT, ETIMEDOUT, ERESTARTSYS.
SVr4,4.4BSD( accept BSD 4.2). BSD (EBADF, ENOTSOCK, EOPNOTSUPP,
EWOULDBLOCK, EFAULT). SUSv2EAGAIN, EBADF, ECONNABORTED, EFAULT, EINTR,
EINVAL, EMFILE, ENFILE, ENOBUFS, ENOMEM, ENOSR, ENOTSOCK, EOPNOTSUPP,
Linux accept O_NONBLOCK . BSD. ,accept.
accept 'int *'(libc4libc5, BSD 4.*,SunOS 4, SGI);POSIX 1003.1g `size_t
*',SunOS 5. POSIXSingle Unix Specificationglibc2 `socklen_t *'.
Quoting Linus Torvalds: Linus Torvalds (:Linux,, ): I fails: only
italicizes a single line _Any_ sane library _must_ have "socklen_t" be
the same size as int. Anything else breaks any BSD socket layer stuff.
POSIX initially _did_ make it a size_t, and I (and hopefully others,
but 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 _has_ to be the same size as "int" because that's what the BSD
socket interface is. Anyway, the POSIX people eventually got a clue,
and created "socklen_t". 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
"socklen_t"int. BSD.POSIXsize_t, Linus Torvalds(,) size_t,64
size_tint,(accept )int,BSD .POSIX, "socklen_t".Linux Torvalds , .
bind(2), connect(2), listen(2), select(2), socket(2)
byeyear <email@example.com >