logo

oasis-root

Compiled tree of Oasis Linux based on own branch at <https://hacktivis.me/git/oasis/> git clone https://anongit.hacktivis.me/git/oasis-root.git

accept.3p (5450B)


  1. '\" et
  2. .TH ACCEPT "3P" 2017 "IEEE/The Open Group" "POSIX Programmer's Manual"
  3. .\"
  4. .SH PROLOG
  5. This manual page is part of the POSIX Programmer's Manual.
  6. The Linux implementation of this interface may differ (consult
  7. the corresponding Linux manual page for details of Linux behavior),
  8. or the interface may not be implemented on Linux.
  9. .\"
  10. .SH NAME
  11. accept
  12. \(em accept a new connection on a socket
  13. .SH SYNOPSIS
  14. .LP
  15. .nf
  16. #include <sys/socket.h>
  17. .P
  18. int accept(int \fIsocket\fP, struct sockaddr *restrict \fIaddress\fP,
  19. socklen_t *restrict \fIaddress_len\fP);
  20. .fi
  21. .SH DESCRIPTION
  22. The
  23. \fIaccept\fR()
  24. function shall extract the first connection on the queue of pending
  25. connections, create a new socket with the same socket type protocol
  26. and address family as the specified socket, and allocate a new file
  27. descriptor for that socket. The file descriptor shall be allocated
  28. as described in
  29. .IR "Section 2.14" ", " "File Descriptor Allocation".
  30. .P
  31. The
  32. \fIaccept\fR()
  33. function takes the following arguments:
  34. .IP "\fIsocket\fR" 12
  35. Specifies a socket that was created with
  36. \fIsocket\fR(),
  37. has been bound to an address with
  38. \fIbind\fR(),
  39. and has issued a successful call to
  40. \fIlisten\fR().
  41. .IP "\fIaddress\fR" 12
  42. Either a null pointer, or a pointer to a
  43. .BR sockaddr
  44. structure where the address of the connecting socket shall be returned.
  45. .IP "\fIaddress_len\fR" 12
  46. Either a null pointer, if
  47. .IR address
  48. is a null pointer, or a pointer to a
  49. .BR socklen_t
  50. object which on input specifies the length of the supplied
  51. .BR sockaddr
  52. structure, and on output specifies the length of the stored address.
  53. .P
  54. If
  55. .IR address
  56. is not a null pointer, the address of the peer for the accepted
  57. connection shall be stored in the
  58. .BR sockaddr
  59. structure pointed to by
  60. .IR address ,
  61. and the length of this address shall be stored in the object pointed to
  62. by
  63. .IR address_len .
  64. .P
  65. If the actual length of the address is greater than the length of the
  66. supplied
  67. .BR sockaddr
  68. structure, the stored address shall be truncated.
  69. .P
  70. If the protocol permits connections by unbound clients, and the peer is
  71. not bound, then the value stored in the object pointed to by
  72. .IR address
  73. is unspecified.
  74. .P
  75. If the listen queue is empty of connection requests and O_NONBLOCK is
  76. not set on the file descriptor for the socket,
  77. \fIaccept\fR()
  78. shall block until a connection is present. If the
  79. \fIlisten\fR()
  80. queue is empty of connection requests and O_NONBLOCK is set on the file
  81. descriptor for the socket,
  82. \fIaccept\fR()
  83. shall fail and set
  84. .IR errno
  85. to
  86. .BR [EAGAIN]
  87. or
  88. .BR [EWOULDBLOCK] .
  89. .P
  90. The accepted socket cannot itself accept more connections. The original
  91. socket remains open and can accept more connections.
  92. .SH "RETURN VALUE"
  93. Upon successful completion,
  94. \fIaccept\fR()
  95. shall return the non-negative file descriptor of the accepted socket.
  96. Otherwise, \-1 shall be returned,
  97. .IR errno
  98. shall be set to indicate the error, and any object pointed to by
  99. .IR address_len
  100. shall remain unchanged.
  101. .SH ERRORS
  102. The
  103. \fIaccept\fR()
  104. function shall fail if:
  105. .TP
  106. .BR EAGAIN " or " EWOULDBLOCK
  107. .br
  108. O_NONBLOCK is set for the socket file descriptor and no connections are
  109. present to be accepted.
  110. .TP
  111. .BR EBADF
  112. The
  113. .IR socket
  114. argument is not a valid file descriptor.
  115. .TP
  116. .BR ECONNABORTED
  117. .br
  118. A connection has been aborted.
  119. .TP
  120. .BR EINTR
  121. The
  122. \fIaccept\fR()
  123. function was interrupted by a signal that was caught before a valid
  124. connection arrived.
  125. .TP
  126. .BR EINVAL
  127. The
  128. .IR socket
  129. is not accepting connections.
  130. .TP
  131. .BR EMFILE
  132. All file descriptors available to the process are currently open.
  133. .TP
  134. .BR ENFILE
  135. The maximum number of file descriptors in the system are already open.
  136. .TP
  137. .BR ENOBUFS
  138. No buffer space is available.
  139. .TP
  140. .BR ENOMEM
  141. There was insufficient memory available to complete the operation.
  142. .TP
  143. .BR ENOTSOCK
  144. The
  145. .IR socket
  146. argument does not refer to a socket.
  147. .TP
  148. .BR EOPNOTSUPP
  149. The socket type of the specified socket does not support accepting
  150. connections.
  151. .P
  152. The
  153. \fIaccept\fR()
  154. function may fail if:
  155. .TP
  156. .BR EPROTO
  157. A protocol error has occurred;
  158. for example, the STREAMS protocol stack has not been initialized.
  159. .LP
  160. .IR "The following sections are informative."
  161. .SH EXAMPLES
  162. None.
  163. .SH "APPLICATION USAGE"
  164. When a connection is available,
  165. \fIselect\fR()
  166. indicates that the file descriptor for the socket is ready for reading.
  167. .SH RATIONALE
  168. None.
  169. .SH "FUTURE DIRECTIONS"
  170. None.
  171. .SH "SEE ALSO"
  172. .IR "Section 2.14" ", " "File Descriptor Allocation",
  173. .IR "\fIbind\fR\^(\|)",
  174. .IR "\fIconnect\fR\^(\|)",
  175. .IR "\fIlisten\fR\^(\|)",
  176. .IR "\fIsocket\fR\^(\|)"
  177. .P
  178. The Base Definitions volume of POSIX.1\(hy2017,
  179. .IR "\fB<sys_socket.h>\fP"
  180. .\"
  181. .SH COPYRIGHT
  182. Portions of this text are reprinted and reproduced in electronic form
  183. from IEEE Std 1003.1-2017, Standard for Information Technology
  184. -- Portable Operating System Interface (POSIX), The Open Group Base
  185. Specifications Issue 7, 2018 Edition,
  186. Copyright (C) 2018 by the Institute of
  187. Electrical and Electronics Engineers, Inc and The Open Group.
  188. In the event of any discrepancy between this version and the original IEEE and
  189. The Open Group Standard, the original IEEE and The Open Group Standard
  190. is the referee document. The original Standard can be obtained online at
  191. http://www.opengroup.org/unix/online.html .
  192. .PP
  193. Any typographical or formatting errors that appear
  194. in this page are most likely
  195. to have been introduced during the conversion of the source files to
  196. man page format. To report such errors, see
  197. https://www.kernel.org/doc/man-pages/reporting_bugs.html .