1accept(3SOCKET) Sockets Library Functions accept(3SOCKET)
2
3
4
6 accept - accept a connection on a socket
7
9 cc [ flag ... ] file ... -lsocket -lnsl [ library ... ]
10 #include <sys/types.h>
11 #include <sys/socket.h>
12
13 int accept(int s, struct sockaddr *addr, socklen_t *addrlen);
14
15
17 The argument s is a socket that has been created with socket(3SOCKET)
18 and bound to an address with bind(3SOCKET), and that is listening for
19 connections after a call to listen(3SOCKET). The accept() function
20 extracts the first connection on the queue of pending connections, cre‐
21 ates a new socket with the properties of s, and allocates a new file
22 descriptor, ns, for the socket. If no pending connections are present
23 on the queue and the socket is not marked as non-blocking, accept()
24 blocks the caller until a connection is present. If the socket is
25 marked as non-blocking and no pending connections are present on the
26 queue, accept() returns an error as described below. The accept()
27 function uses the netconfig(4) file to determine the STREAMS device
28 file name associated with s. This is the device on which the connect
29 indication will be accepted. The accepted socket, ns, is used to read
30 and write data to and from the socket that connected to ns. It is not
31 used to accept more connections. The original socket (s) remains open
32 for accepting further connections.
33
34
35 The argument addr is a result parameter that is filled in with the
36 address of the connecting entity as it is known to the communications
37 layer. The exact format of the addr parameter is determined by the
38 domain in which the communication occurs.
39
40
41 The argument addrlen is a value-result parameter. Initially, it con‐
42 tains the amount of space pointed to by addr; on return it contains the
43 length in bytes of the address returned.
44
45
46 The accept() function is used with connection-based socket types, cur‐
47 rently with SOCK_STREAM.
48
49
50 It is possible to select(3C) or poll(2) a socket for the purpose of an
51 accept() by selecting or polling it for a read. However, this will only
52 indicate when a connect indication is pending; it is still necessary to
53 call accept().
54
56 The accept() function returns −1 on error. If it succeeds, it returns a
57 non-negative integer that is a descriptor for the accepted socket.
58
60 accept() will fail if:
61
62 EBADF The descriptor is invalid.
63
64
65 ECONNABORTED The remote side aborted the connection before the
66 accept() operation completed.
67
68
69 EFAULT The addr parameter or the addrlen parameter is invalid.
70
71
72 EINTR The accept() attempt was interrupted by the delivery of
73 a signal.
74
75
76 EMFILE The per-process descriptor table is full.
77
78
79 ENODEV The protocol family and type corresponding to s could
80 not be found in the netconfig file.
81
82
83 ENOMEM There was insufficient user memory available to com‐
84 plete the operation.
85
86
87 ENOSR There were insufficient STREAMS resources available to
88 complete the operation.
89
90
91 ENOTSOCK The descriptor does not reference a socket.
92
93
94 EOPNOTSUPP The referenced socket is not of type SOCK_STREAM.
95
96
97 EPROTO A protocol error has occurred; for example, the STREAMS
98 protocol stack has not been initialized or the connec‐
99 tion has already been released.
100
101
102 EWOULDBLOCK The socket is marked as non-blocking and no connections
103 are present to be accepted.
104
105
107 See attributes(5) for descriptions of the following attributes:
108
109
110
111
112 ┌─────────────────────────────┬─────────────────────────────┐
113 │ ATTRIBUTE TYPE │ ATTRIBUTE VALUE │
114 ├─────────────────────────────┼─────────────────────────────┤
115 │MT-Level │Safe │
116 └─────────────────────────────┴─────────────────────────────┘
117
119 poll(2), bind(3SOCKET), connect(3SOCKET), listen(3SOCKET), select(3C),
120 socket.h(3HEAD), socket(3SOCKET), netconfig(4), attributes(5)
121
122
123
124SunOS 5.11 24 Jan 2002 accept(3SOCKET)