accept(2) System Calls Manual accept(2) accept, accept4 - LIBRARY Standard C library (libc, -lc) #include int accept(int sockfd, struct sockaddr *_Nullable restrict addr, socklen_t *_Nullable restrict addrlen); #define _GNU_SOURCE /* feature_test_macros(7) */ #include int accept4(int sockfd, struct sockaddr *_Nullable restrict addr, socklen_t *_Nullable restrict addrlen, int flags); accept() , (SOCK_STREAM, SOCK_SEQPACKET). , sockfd, , . . sockfd . sockfd -- , socket(2), bind(2), listen(2). addr -- sockaddr. , . , addr, (. socket(2) ). addr NULL, ; addrlen NULL. addrlen : ( ) , addr; . , ; addrlen . , , accept() . , , accept() EAGAIN EWOULDBLOCK. , , select(2), poll(2) epoll(7). , accept(), . , SIGIO, - ; socket(7). flags 0, accept4() accept(). flags : SOCK_NONBLOCK O_NONBLOCK ( open(2)), . fcntl(2) . SOCK_CLOEXEC close-on-exec (FD_CLOEXEC) . O_CLOEXEC open(2) , . On success, these system calls return a file descriptor for the accepted socket (a nonnegative integer). On error, -1 is returned, errno is set to indicate the error, and addrlen is left unchanged. Linux accept() ( accept4()) , accept(). BSD-. , accept() EAGAIN . TCP/IP ENETDOWN, EPROTO, ENOPROTOOPT, EHOSTDOWN, ENONET, EHOSTUNREACH, EOPNOTSUPP ENETUNREACH. EAGAIN EWOULDBLOCK , . POSIX.1-2001 POSIX.1-2008 , , . EBADF sockfd . ECONNABORTED . EFAULT addr . EINTR , ; . signal(7). EINVAL addrlen (, ). EINVAL (accept4()) flags. EMFILE . ENFILE . ENOBUFS ENOMEM . , , . ENOTSOCK sockfd . EOPNOTSUPP , , SOCK_STREAM. EPERM . EPROTO . , , . Linux , , ENOSR, ESOCKTNOSUPPORT, EPROTONOSUPPORT, ETIMEDOUT. ERESTARTSYS . Linux , accept(), O_NONBLOCK O_ASYNC . BSD. , accept(), . accept() POSIX.1-2008. accept4() Linux. accept() POSIX.1-2001, SVr4, 4.4BSD (accept() first appeared in 4.2BSD). accept4() Linux 2.6.28, glibc 2.10. SIGIO; select(2), poll(2) epoll(7) , - accept(). , , . , accept() , sockfd O_NONBLOCK (. socket(7)). , , , DECnet, accept() , . , , , . , Linux DECnet. socklen_t BSD ( ) accept() int *. POSIX.1g size_t *. POSIX glibc 2.x socklen_t *. . bind(2). bind(2), connect(2), listen(2), select(2), socket(2), socket(7) Dmitry Bolkhovskikh Yuri Kozlov ; GNU (GNU General Public License - GPL, 3 ) , - . - , , <>. Linux man-pages 6.8 2 2024 . accept(2)