Commit | Line | Data |
---|---|---|
da268306 KB |
1 | .\" Copyright (c) 1983 The Regents of the University of California. |
2 | .\" All rights reserved. | |
95f52c01 | 3 | .\" |
da268306 KB |
4 | .\" Redistribution and use in source and binary forms are permitted |
5 | .\" provided that the above copyright notice and this paragraph are | |
6 | .\" duplicated in all such forms and that any documentation, | |
7 | .\" advertising materials, and other materials related to such | |
8 | .\" distribution and use acknowledge that the software was developed | |
9 | .\" by the University of California, Berkeley. The name of the | |
10 | .\" University may not be used to endorse or promote products derived | |
11 | .\" from this software without specific prior written permission. | |
12 | .\" THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR | |
13 | .\" IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED | |
14 | .\" WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | |
15 | .\" | |
16 | .\" @(#)accept.2 6.4 (Berkeley) %G% | |
95f52c01 | 17 | .\" |
f850922e | 18 | .TH ACCEPT 2 "" |
95f52c01 KM |
19 | .UC 5 |
20 | .SH NAME | |
21 | accept \- accept a connection on a socket | |
22 | .SH SYNOPSIS | |
23 | .ft B | |
24 | .nf | |
25 | #include <sys/types.h> | |
26 | #include <sys/socket.h> | |
27 | .PP | |
28 | .ft B | |
29 | ns = accept(s, addr, addrlen) | |
30 | int ns, s; | |
31 | struct sockaddr *addr; | |
32 | int *addrlen; | |
33 | .fi | |
34 | .SH DESCRIPTION | |
35 | The argument | |
36 | .I s | |
a9f72a26 | 37 | is a socket that has been created with |
95f52c01 KM |
38 | .IR socket (2), |
39 | bound to an address with | |
40 | .IR bind (2), | |
41 | and is listening for connections after a | |
42 | .IR listen (2). | |
43 | .I Accept | |
44 | extracts the first connection | |
45 | on the queue of pending connections, creates | |
46 | a new socket with the same properties of | |
47 | .I s | |
48 | and allocates a new file descriptor, | |
49 | .IR ns , | |
50 | for the socket. If no pending connections are | |
51 | present on the queue, and the socket is not marked | |
52 | as non-blocking, | |
53 | .I accept | |
54 | blocks the caller until a connection is present. | |
55 | If the socket is marked non-blocking and no pending | |
56 | connections are present on the queue, | |
57 | .I accept | |
58 | returns an error as described below. | |
59 | The accepted socket, | |
60 | .IR ns , | |
61 | may not be used | |
62 | to accept more connections. The original socket | |
63 | .I s | |
64 | remains open. | |
65 | .PP | |
66 | The argument | |
67 | .I addr | |
a9f72a26 | 68 | is a result parameter that is filled in with |
95f52c01 KM |
69 | the address of the connecting entity, |
70 | as known to the communications layer. | |
71 | The exact format of the | |
72 | .I addr | |
73 | parameter is determined by the domain in which the communication | |
74 | is occurring. | |
75 | The | |
76 | .I addrlen | |
77 | is a value-result parameter; it should initially contain the | |
78 | amount of space pointed to by | |
79 | .IR addr ; | |
80 | on return it will contain the actual length (in bytes) of the | |
81 | address returned. | |
82 | This call | |
83 | is used with connection-based socket types, currently with SOCK_STREAM. | |
84 | .PP | |
85 | It is possible to | |
86 | .IR select (2) | |
87 | a socket for the purposes of doing an | |
88 | .I accept | |
89 | by selecting it for read. | |
90 | .SH "RETURN VALUE | |
bdad3a5a | 91 | The call returns \-1 on error. If it succeeds, it returns a non-negative |
a9f72a26 | 92 | integer that is a descriptor for the accepted socket. |
95f52c01 KM |
93 | .SH ERRORS |
94 | The \fIaccept\fP will fail if: | |
95 | .TP 20 | |
96 | [EBADF] | |
97 | The descriptor is invalid. | |
98 | .TP 20 | |
99 | [ENOTSOCK] | |
100 | The descriptor references a file, not a socket. | |
101 | .TP 20 | |
102 | [EOPNOTSUPP] | |
103 | The referenced socket is not of type SOCK_STREAM. | |
104 | .TP 20 | |
105 | [EFAULT] | |
106 | The \fIaddr\fP parameter is not in a writable part of the | |
107 | user address space. | |
108 | .TP 20 | |
109 | [EWOULDBLOCK] | |
110 | The socket is marked non-blocking and no connections | |
111 | are present to be accepted. | |
112 | .SH SEE ALSO | |
113 | bind(2), connect(2), listen(2), select(2), socket(2) |