1 <!-- Copyright (C) 2003 Red Hat, Inc. -->
2 <!-- This material may be distributed only subject to the terms -->
3 <!-- and conditions set forth in the Open Publication License, v1.0 -->
4 <!-- or later (the latest version is presently available at -->
5 <!-- http://www.opencontent.org/openpub/). -->
6 <!-- Distribution of the work or derivative of the work in any -->
7 <!-- standard (paper) book form is prohibited unless prior -->
8 <!-- permission is obtained from the copyright holder. -->
13 ><meta name="MSSmartTagsPreventParsing" content="TRUE">
16 CONTENT="Modular DocBook HTML Stylesheet Version 1.76b+
19 TITLE="eCos Reference Manual"
20 HREF="ecos-ref.html"><LINK
22 TITLE="TCP/IP Library Reference"
23 HREF="tcpip-library-reference.html"><LINK
26 HREF="net-common-tcpip-manpages-resolver.html"><LINK
29 HREF="net-common-tcpip-manpages-bind.html"></HEAD
40 SUMMARY="Header navigation table"
49 >eCos Reference Manual</TH
57 HREF="net-common-tcpip-manpages-resolver.html"
65 >Chapter 38. TCP/IP Library Reference</TD
71 HREF="net-common-tcpip-manpages-bind.html"
85 NAME="NET-COMMON-TCPIP-MANPAGES-ACCEPT">accept</H1
94 >ACCEPT(2) System Calls Manual ACCEPT(2)
97 accept - accept a connection on a socket
100 #include <sys/types.h>
101 #include <sys/socket.h>
104 accept(int s, struct sockaddr *addr, socklen_t *addrlen);
107 The argument s is a socket that has been created with socket(2), bound to
108 an address with bind(2), and is listening for connections after a
109 listen(2). The accept() argument extracts the first connection request
110 on the queue of pending connections, creates a new socket with the same
111 properties of s, and allocates a new file descriptor for the socket. If
112 no pending connections are present on the queue, and the socket is not
113 marked as non-blocking, accept() blocks the caller until a connection is
114 present. If the socket is marked non-blocking and no pending connections
115 are present on the queue, accept() returns an error as described below.
116 The accepted socket may not be used to accept more connections. The
117 original socket s remains open.
119 The argument addr is a result parameter that is filled in with the
120 address of the connecting entity as known to the communications layer.
121 The exact format of the addr parameter is determined by the domain in
122 which the communication is occurring. The addrlen is a value-result
123 parameter; it should initially contain the amount of space pointed to by
124 addr; on return it will contain the actual length (in bytes) of the
125 address returned. This call is used with connection-based socket types,
126 currently with SOCK_STREAM.
128 It is possible to select(2) or poll(2) a socket for the purposes of doing
129 an accept() by selecting it for read.
131 For certain protocols which require an explicit confirmation, such as ISO
132 or DATAKIT, accept() can be thought of as merely dequeuing the next con-
133 nection request and not implying confirmation. Confirmation can be
134 implied by a normal read or write on the new file descriptor, and rejec-
135 tion can be implied by closing the new socket.
137 One can obtain user connection request data without confirming the con-
138 nection by issuing a recvmsg(2) call with an msg_iovlen of 0 and a non-
139 zero msg_controllen, or by issuing a getsockopt(2) request. Similarly,
140 one can provide user connection rejection information by issuing a
141 sendmsg(2) call with providing only the control information, or by call-
145 The call returns -1 on error. If it succeeds, it returns a non-negative
146 integer that is a descriptor for the accepted socket.
149 The accept() will fail if:
151 [EBADF] The descriptor is invalid.
153 [ENOTSOCK] The descriptor references a file, not a socket.
155 [EOPNOTSUPP] The referenced socket is not of type SOCK_STREAM.
157 [EINVAL] The referenced socket is not listening for connections
158 (that is, listen(2) has not yet been called).
160 [EFAULT] The addr parameter is not in a writable part of the
163 [EWOULDBLOCK] The socket is marked non-blocking and no connections
164 are present to be accepted.
166 [EMFILE] The per-process descriptor table is full.
168 [ENFILE] The system file table is full.
170 [ECONNABORTED] A connection has been aborted.
173 bind(2), connect(2), listen(2), poll(2), select(2), poll(2), socket(2)
176 The accept() function appeared in 4.2BSD.
178 BSD February 15, 1999 BSD
189 SUMMARY="Footer navigation table"
200 HREF="net-common-tcpip-manpages-resolver.html"
218 HREF="net-common-tcpip-manpages-bind.html"
234 HREF="tcpip-library-reference.html"