-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathaccept.3
More file actions
143 lines (143 loc) · 3.05 KB
/
Copy pathaccept.3
File metadata and controls
143 lines (143 loc) · 3.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
.TH accept 3 "MiNT-Net"
.SH NAME
accept \- accept a connection on a socket
.SH SYNOPSIS
.B #include <sys/socket.h>
.SS \s-1AF_UNIX\s0 only:
.B #include <sys/un.h>
.PP
.B "int accept(int s, struct sockaddr \(**addr, size_t \(**addrlen);"
.SH DESCRIPTION
This call is used with connection-based socket types, such as
.SM SOCK_STREAM.
The argument
.I s
is a socket descriptor created with
.IR socket (3),
bound to an address with
.IR bind (3),
and listening for connections after a
.IR listen (3).
.I accept
extracts the first connection on the queue of pending connections,
creates a new socket with the same properties as
.IR s ,
and allocates a new file descriptor,
.IR ns ,
for the socket.
If no pending connections are present on the queue
and non-blocking mode has not been enabled using the
.SM O_NDELAY
.I fcntl
flag,
.I accept
blocks the caller until a connection is present.
.SM O_NDELAY
is defined in
.RB < fcntl.h >\s0.
If the socket is marked non-blocking and no pending
connections are present on the queue,
.I accept
returns an error as described below.
The accepted socket,
.IR ns ,
cannot be used to accept more connections.
The original socket
.I s
remains open.
It is possible to determine if a listening socket
has pending connection requests ready for an
.I accept
call by using
.IR select (3)
for reading.
.PP
The argument
.I addr
should point to a local socket address structure.
The
.I accept
call fills in this structure with the address of the connecting entity,
as known to the underlying protocol.
The format of the address depends upon the protocol
and the address-family of the socket
.IR s .
The
.I addrlen
is a pointer to an argument of type size_t;
it should initially contain the size
of the structure pointed to by
.IR addr .
On return, it contains the actual length (in bytes)
of the address returned.
If the memory pointed to by
.I addr
is not large enough to contain the entire address, only the first
.I addrlen
bytes of the address are returned.
.SH RETURN VALUE
The call returns \-1 on error.
If successful, it returns a non-negative integer
which is a descriptor for the accepted socket.
.SH DIAGNOSTICS
.I accept
fails if:
.TP 25
.SM [EBADF]
The file descriptor
.I s
is invalid.
.TP
.SM [EOPNOTSUPP]
The socket referenced by
.I s
is not of type
.SM SOCK_STREAM.
.TP
.SM [EWOULDBLOCK]
Non-blocking
.SM I/O
is enabled using
.SM O_NDELAY
and no connections are present to be accepted.
.TP
.SM [EMFILE]
The maximum number of file descriptors for this process
are already currently open.
.TP
.SM [ENOMEM]
No buffer space is available.
The
.I accept
cannot complete.
The queued socket connect request is aborted.
.TP
.SM [ECONNABORTED]
The socket referenced by
.I s
has been
.IR shutdown
for reading.
.TP
.SM [EINVAL]
The socket referenced by
.I s
is not currently a listening socket or has been fully
.IR shutdown .
A
.I listen
must be done before an
.I accept
is allowed.
The file descriptor
.I s
references a file, not a socket.
.TP
.SM [EINTR]
The call was interrupted by a signal before a valid connection arrived.
.SH SEE ALSO
bind(3),
connect(3),
listen(3),
select(3),
socket(3).