1accept(3XNET)    X/Open Networking Services Library Functions    accept(3XNET)
2
3
4

NAME

6       accept - accept a new connection on a socket
7

SYNOPSIS

9       cc [ flag ... ] file ... -lxnet [ library ... ]
10       #include <sys/socket.h>
11
12
13       int accept(int socket, struct sockaddr *restrict address,
14            socklen_t *restrict address_len);
15
16

DESCRIPTION

18       The  accept()  function  extracts  the first connection on the queue of
19       pending connections, creates a new socket with  the  same  socket  type
20       protocol  and  address  family as the specified socket, and allocates a
21       new file descriptor for that socket.
22
23
24       The function takes the following arguments:
25
26       socket         Specifies a socket that was created with  socket(3XNET),
27                      has  been  bound to an address with bind(3XNET), and has
28                      issued a successful call to listen(3XNET).
29
30
31       address        Either a null pointer, or a pointer to a sockaddr struc‐
32                      ture  where the address of the connecting socket will be
33                      returned.
34
35
36       address_len    Points to a  socklen_t  which  on  input  specifies  the
37                      length of the supplied sockaddr structure, and on output
38                      specifies the length of the stored address.
39
40
41
42       If address is not a null pointer, the  address  of  the  peer  for  the
43       accepted  connection  is stored in the sockaddr structure pointed to by
44       address, and the length of this address is stored in the object pointed
45       to by address_len.
46
47
48       If  the  actual length of the address is greater than the length of the
49       supplied sockaddr structure, the stored address will be truncated.
50
51
52       If the protocol permits connections by unbound clients, and the peer is
53       not bound, then the value stored in the object pointed to by address is
54       unspecified.
55
56
57       If the listen queue is empty of connection requests and  O_NONBLOCK  is
58       not  set  on  the  file  descriptor for the socket, accept() will block
59       until a connection is present. If the listen(3XNET) queue is  empty  of
60       connection  requests  and  O_NONBLOCK is set on the file descriptor for
61       the socket, accept() will fail and set errno to EAGAIN or EWOULDBLOCK.
62
63
64       The accepted socket cannot itself accept more connections.  The  origi‐
65       nal socket remains open and can accept more connections.
66

USAGE

68       When  a connection is available, select(3C) will indicate that the file
69       descriptor for the socket is ready for reading.
70

RETURN VALUES

72       Upon successful  completion,  accept()  returns  the  nonnegative  file
73       descriptor of the accepted socket.  Otherwise, −1 is returned and errno
74       is set to indicate the error.
75

ERRORS

77       The accept() function will fail if:
78
79       EAGAIN          O_NONBLOCK is set for the socket file descriptor and no
80       EWOULDBLOCK     connections are present to be accepted.
81
82
83       EBADF           The socket argument is not a valid file descriptor.
84
85
86       ECONNABORTED    A connection has been aborted.
87
88
89       EFAULT          The   address  or   address_len  parameter  can  not be
90                       accessed or written.
91
92
93       EINTR           The accept() function was interrupted by a signal  that
94                       was caught before a valid connection arrived.
95
96
97       EINVAL          The socket is not accepting connections.
98
99
100       EMFILE          OPEN_MAX  file  descriptors  are  currently open in the
101                       calling process.
102
103
104       ENFILE          The maximum number of file descriptors  in  the  system
105                       are already open.
106
107
108       ENOTSOCK        The socket argument does not refer to a socket.
109
110
111       EOPNOTSUPP      The  socket  type of the specified socket does not sup‐
112                       port accepting connections.
113
114
115
116       The accept() function may fail if:
117
118       ENOBUFS    No buffer space is available.
119
120
121       ENOMEM     There was insufficient  memory  available  to  complete  the
122                  operation.
123
124
125       ENOSR      There  was  insufficient STREAMS resources available to com‐
126                  plete the operation.
127
128
129       EPROTO     A protocol error has occurred; for example, the STREAMS pro‐
130                  tocol stack has not been initialized.
131
132

ATTRIBUTES

134       See attributes(5) for descriptions of the following attributes:
135
136
137
138
139       ┌─────────────────────────────┬─────────────────────────────┐
140       │      ATTRIBUTE TYPE         │      ATTRIBUTE VALUE        │
141       ├─────────────────────────────┼─────────────────────────────┤
142       │Interface Stability          │Standard                     │
143       ├─────────────────────────────┼─────────────────────────────┤
144       │MT-Level                     │MT-Safe                      │
145       └─────────────────────────────┴─────────────────────────────┘
146

SEE ALSO

148       bind(3XNET),      connect(3XNET),     listen(3XNET),     socket(3XNET),
149       attributes(5), standards(5)
150
151
152
153SunOS 5.11                        1 Nov 2003                     accept(3XNET)
Impressum