]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | // |
2 | // detail/socket_ops.hpp | |
3 | // ~~~~~~~~~~~~~~~~~~~~~ | |
4 | // | |
f67539c2 | 5 | // Copyright (c) 2003-2020 Christopher M. Kohlhoff (chris at kohlhoff dot com) |
7c673cae FG |
6 | // |
7 | // Distributed under the Boost Software License, Version 1.0. (See accompanying | |
8 | // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) | |
9 | // | |
10 | ||
11 | #ifndef BOOST_ASIO_DETAIL_SOCKET_OPS_HPP | |
12 | #define BOOST_ASIO_DETAIL_SOCKET_OPS_HPP | |
13 | ||
14 | #if defined(_MSC_VER) && (_MSC_VER >= 1200) | |
15 | # pragma once | |
16 | #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) | |
17 | ||
18 | #include <boost/asio/detail/config.hpp> | |
19 | ||
20 | #include <boost/system/error_code.hpp> | |
b32b8144 | 21 | #include <boost/asio/detail/memory.hpp> |
7c673cae | 22 | #include <boost/asio/detail/socket_types.hpp> |
7c673cae FG |
23 | |
24 | #include <boost/asio/detail/push_options.hpp> | |
25 | ||
26 | namespace boost { | |
27 | namespace asio { | |
28 | namespace detail { | |
29 | namespace socket_ops { | |
30 | ||
31 | // Socket state bits. | |
32 | enum | |
33 | { | |
34 | // The user wants a non-blocking socket. | |
35 | user_set_non_blocking = 1, | |
36 | ||
37 | // The socket has been set non-blocking. | |
38 | internal_non_blocking = 2, | |
39 | ||
40 | // Helper "state" used to determine whether the socket is non-blocking. | |
41 | non_blocking = user_set_non_blocking | internal_non_blocking, | |
42 | ||
43 | // User wants connection_aborted errors, which are disabled by default. | |
44 | enable_connection_aborted = 4, | |
45 | ||
46 | // The user set the linger option. Needs to be checked when closing. | |
47 | user_set_linger = 8, | |
48 | ||
49 | // The socket is stream-oriented. | |
50 | stream_oriented = 16, | |
51 | ||
52 | // The socket is datagram-oriented. | |
53 | datagram_oriented = 32, | |
54 | ||
55 | // The socket may have been dup()-ed. | |
56 | possible_dup = 64 | |
57 | }; | |
58 | ||
59 | typedef unsigned char state_type; | |
60 | ||
61 | struct noop_deleter { void operator()(void*) {} }; | |
62 | typedef shared_ptr<void> shared_cancel_token_type; | |
63 | typedef weak_ptr<void> weak_cancel_token_type; | |
64 | ||
65 | #if !defined(BOOST_ASIO_WINDOWS_RUNTIME) | |
66 | ||
67 | BOOST_ASIO_DECL socket_type accept(socket_type s, socket_addr_type* addr, | |
68 | std::size_t* addrlen, boost::system::error_code& ec); | |
69 | ||
70 | BOOST_ASIO_DECL socket_type sync_accept(socket_type s, | |
71 | state_type state, socket_addr_type* addr, | |
72 | std::size_t* addrlen, boost::system::error_code& ec); | |
73 | ||
74 | #if defined(BOOST_ASIO_HAS_IOCP) | |
75 | ||
76 | BOOST_ASIO_DECL void complete_iocp_accept(socket_type s, | |
77 | void* output_buffer, DWORD address_length, | |
78 | socket_addr_type* addr, std::size_t* addrlen, | |
79 | socket_type new_socket, boost::system::error_code& ec); | |
80 | ||
81 | #else // defined(BOOST_ASIO_HAS_IOCP) | |
82 | ||
83 | BOOST_ASIO_DECL bool non_blocking_accept(socket_type s, | |
84 | state_type state, socket_addr_type* addr, std::size_t* addrlen, | |
85 | boost::system::error_code& ec, socket_type& new_socket); | |
86 | ||
87 | #endif // defined(BOOST_ASIO_HAS_IOCP) | |
88 | ||
89 | BOOST_ASIO_DECL int bind(socket_type s, const socket_addr_type* addr, | |
90 | std::size_t addrlen, boost::system::error_code& ec); | |
91 | ||
92 | BOOST_ASIO_DECL int close(socket_type s, state_type& state, | |
93 | bool destruction, boost::system::error_code& ec); | |
94 | ||
95 | BOOST_ASIO_DECL bool set_user_non_blocking(socket_type s, | |
96 | state_type& state, bool value, boost::system::error_code& ec); | |
97 | ||
98 | BOOST_ASIO_DECL bool set_internal_non_blocking(socket_type s, | |
99 | state_type& state, bool value, boost::system::error_code& ec); | |
100 | ||
101 | BOOST_ASIO_DECL int shutdown(socket_type s, | |
102 | int what, boost::system::error_code& ec); | |
103 | ||
104 | BOOST_ASIO_DECL int connect(socket_type s, const socket_addr_type* addr, | |
105 | std::size_t addrlen, boost::system::error_code& ec); | |
106 | ||
107 | BOOST_ASIO_DECL void sync_connect(socket_type s, const socket_addr_type* addr, | |
108 | std::size_t addrlen, boost::system::error_code& ec); | |
109 | ||
110 | #if defined(BOOST_ASIO_HAS_IOCP) | |
111 | ||
112 | BOOST_ASIO_DECL void complete_iocp_connect(socket_type s, | |
113 | boost::system::error_code& ec); | |
114 | ||
115 | #endif // defined(BOOST_ASIO_HAS_IOCP) | |
116 | ||
117 | BOOST_ASIO_DECL bool non_blocking_connect(socket_type s, | |
118 | boost::system::error_code& ec); | |
119 | ||
120 | BOOST_ASIO_DECL int socketpair(int af, int type, int protocol, | |
121 | socket_type sv[2], boost::system::error_code& ec); | |
122 | ||
123 | BOOST_ASIO_DECL bool sockatmark(socket_type s, boost::system::error_code& ec); | |
124 | ||
125 | BOOST_ASIO_DECL size_t available(socket_type s, boost::system::error_code& ec); | |
126 | ||
127 | BOOST_ASIO_DECL int listen(socket_type s, | |
128 | int backlog, boost::system::error_code& ec); | |
129 | ||
130 | #if defined(BOOST_ASIO_WINDOWS) || defined(__CYGWIN__) | |
131 | typedef WSABUF buf; | |
132 | #else // defined(BOOST_ASIO_WINDOWS) || defined(__CYGWIN__) | |
133 | typedef iovec buf; | |
134 | #endif // defined(BOOST_ASIO_WINDOWS) || defined(__CYGWIN__) | |
135 | ||
136 | BOOST_ASIO_DECL void init_buf(buf& b, void* data, size_t size); | |
137 | ||
138 | BOOST_ASIO_DECL void init_buf(buf& b, const void* data, size_t size); | |
139 | ||
140 | BOOST_ASIO_DECL signed_size_type recv(socket_type s, buf* bufs, | |
141 | size_t count, int flags, boost::system::error_code& ec); | |
142 | ||
20effc67 TL |
143 | BOOST_ASIO_DECL signed_size_type recv1(socket_type s, |
144 | void* data, size_t size, int flags, boost::system::error_code& ec); | |
145 | ||
7c673cae FG |
146 | BOOST_ASIO_DECL size_t sync_recv(socket_type s, state_type state, buf* bufs, |
147 | size_t count, int flags, bool all_empty, boost::system::error_code& ec); | |
148 | ||
20effc67 TL |
149 | BOOST_ASIO_DECL size_t sync_recv1(socket_type s, state_type state, |
150 | void* data, size_t size, int flags, boost::system::error_code& ec); | |
151 | ||
7c673cae FG |
152 | #if defined(BOOST_ASIO_HAS_IOCP) |
153 | ||
154 | BOOST_ASIO_DECL void complete_iocp_recv(state_type state, | |
155 | const weak_cancel_token_type& cancel_token, bool all_empty, | |
156 | boost::system::error_code& ec, size_t bytes_transferred); | |
157 | ||
158 | #else // defined(BOOST_ASIO_HAS_IOCP) | |
159 | ||
160 | BOOST_ASIO_DECL bool non_blocking_recv(socket_type s, | |
161 | buf* bufs, size_t count, int flags, bool is_stream, | |
162 | boost::system::error_code& ec, size_t& bytes_transferred); | |
163 | ||
20effc67 TL |
164 | BOOST_ASIO_DECL bool non_blocking_recv1(socket_type s, |
165 | void* data, size_t size, int flags, bool is_stream, | |
166 | boost::system::error_code& ec, size_t& bytes_transferred); | |
167 | ||
7c673cae FG |
168 | #endif // defined(BOOST_ASIO_HAS_IOCP) |
169 | ||
170 | BOOST_ASIO_DECL signed_size_type recvfrom(socket_type s, buf* bufs, | |
171 | size_t count, int flags, socket_addr_type* addr, | |
172 | std::size_t* addrlen, boost::system::error_code& ec); | |
173 | ||
20effc67 TL |
174 | BOOST_ASIO_DECL signed_size_type recvfrom1(socket_type s, void* data, |
175 | size_t size, int flags, socket_addr_type* addr, | |
176 | std::size_t* addrlen, boost::system::error_code& ec); | |
177 | ||
7c673cae FG |
178 | BOOST_ASIO_DECL size_t sync_recvfrom(socket_type s, state_type state, |
179 | buf* bufs, size_t count, int flags, socket_addr_type* addr, | |
180 | std::size_t* addrlen, boost::system::error_code& ec); | |
181 | ||
20effc67 TL |
182 | BOOST_ASIO_DECL size_t sync_recvfrom1(socket_type s, state_type state, |
183 | void* data, size_t size, int flags, socket_addr_type* addr, | |
184 | std::size_t* addrlen, boost::system::error_code& ec); | |
185 | ||
7c673cae FG |
186 | #if defined(BOOST_ASIO_HAS_IOCP) |
187 | ||
188 | BOOST_ASIO_DECL void complete_iocp_recvfrom( | |
189 | const weak_cancel_token_type& cancel_token, | |
190 | boost::system::error_code& ec); | |
191 | ||
192 | #else // defined(BOOST_ASIO_HAS_IOCP) | |
193 | ||
194 | BOOST_ASIO_DECL bool non_blocking_recvfrom(socket_type s, | |
195 | buf* bufs, size_t count, int flags, | |
196 | socket_addr_type* addr, std::size_t* addrlen, | |
197 | boost::system::error_code& ec, size_t& bytes_transferred); | |
198 | ||
20effc67 TL |
199 | BOOST_ASIO_DECL bool non_blocking_recvfrom1(socket_type s, |
200 | void* data, size_t size, int flags, | |
201 | socket_addr_type* addr, std::size_t* addrlen, | |
202 | boost::system::error_code& ec, size_t& bytes_transferred); | |
203 | ||
7c673cae FG |
204 | #endif // defined(BOOST_ASIO_HAS_IOCP) |
205 | ||
206 | BOOST_ASIO_DECL signed_size_type recvmsg(socket_type s, buf* bufs, | |
207 | size_t count, int in_flags, int& out_flags, | |
208 | boost::system::error_code& ec); | |
209 | ||
210 | BOOST_ASIO_DECL size_t sync_recvmsg(socket_type s, state_type state, | |
211 | buf* bufs, size_t count, int in_flags, int& out_flags, | |
212 | boost::system::error_code& ec); | |
213 | ||
214 | #if defined(BOOST_ASIO_HAS_IOCP) | |
215 | ||
216 | BOOST_ASIO_DECL void complete_iocp_recvmsg( | |
217 | const weak_cancel_token_type& cancel_token, | |
218 | boost::system::error_code& ec); | |
219 | ||
220 | #else // defined(BOOST_ASIO_HAS_IOCP) | |
221 | ||
222 | BOOST_ASIO_DECL bool non_blocking_recvmsg(socket_type s, | |
223 | buf* bufs, size_t count, int in_flags, int& out_flags, | |
224 | boost::system::error_code& ec, size_t& bytes_transferred); | |
225 | ||
226 | #endif // defined(BOOST_ASIO_HAS_IOCP) | |
227 | ||
228 | BOOST_ASIO_DECL signed_size_type send(socket_type s, const buf* bufs, | |
229 | size_t count, int flags, boost::system::error_code& ec); | |
230 | ||
20effc67 TL |
231 | BOOST_ASIO_DECL signed_size_type send1(socket_type s, |
232 | const void* data, size_t size, int flags, boost::system::error_code& ec); | |
233 | ||
7c673cae FG |
234 | BOOST_ASIO_DECL size_t sync_send(socket_type s, state_type state, |
235 | const buf* bufs, size_t count, int flags, | |
236 | bool all_empty, boost::system::error_code& ec); | |
237 | ||
20effc67 TL |
238 | BOOST_ASIO_DECL size_t sync_send1(socket_type s, state_type state, |
239 | const void* data, size_t size, int flags, boost::system::error_code& ec); | |
240 | ||
7c673cae FG |
241 | #if defined(BOOST_ASIO_HAS_IOCP) |
242 | ||
243 | BOOST_ASIO_DECL void complete_iocp_send( | |
244 | const weak_cancel_token_type& cancel_token, | |
245 | boost::system::error_code& ec); | |
246 | ||
247 | #else // defined(BOOST_ASIO_HAS_IOCP) | |
248 | ||
249 | BOOST_ASIO_DECL bool non_blocking_send(socket_type s, | |
250 | const buf* bufs, size_t count, int flags, | |
251 | boost::system::error_code& ec, size_t& bytes_transferred); | |
252 | ||
20effc67 TL |
253 | BOOST_ASIO_DECL bool non_blocking_send1(socket_type s, |
254 | const void* data, size_t size, int flags, | |
255 | boost::system::error_code& ec, size_t& bytes_transferred); | |
256 | ||
7c673cae FG |
257 | #endif // defined(BOOST_ASIO_HAS_IOCP) |
258 | ||
259 | BOOST_ASIO_DECL signed_size_type sendto(socket_type s, const buf* bufs, | |
260 | size_t count, int flags, const socket_addr_type* addr, | |
261 | std::size_t addrlen, boost::system::error_code& ec); | |
262 | ||
20effc67 TL |
263 | BOOST_ASIO_DECL signed_size_type sendto1(socket_type s, const void* data, |
264 | size_t size, int flags, const socket_addr_type* addr, | |
265 | std::size_t addrlen, boost::system::error_code& ec); | |
266 | ||
7c673cae FG |
267 | BOOST_ASIO_DECL size_t sync_sendto(socket_type s, state_type state, |
268 | const buf* bufs, size_t count, int flags, const socket_addr_type* addr, | |
269 | std::size_t addrlen, boost::system::error_code& ec); | |
270 | ||
20effc67 TL |
271 | BOOST_ASIO_DECL size_t sync_sendto1(socket_type s, state_type state, |
272 | const void* data, size_t size, int flags, const socket_addr_type* addr, | |
273 | std::size_t addrlen, boost::system::error_code& ec); | |
274 | ||
7c673cae FG |
275 | #if !defined(BOOST_ASIO_HAS_IOCP) |
276 | ||
277 | BOOST_ASIO_DECL bool non_blocking_sendto(socket_type s, | |
278 | const buf* bufs, size_t count, int flags, | |
279 | const socket_addr_type* addr, std::size_t addrlen, | |
280 | boost::system::error_code& ec, size_t& bytes_transferred); | |
281 | ||
20effc67 TL |
282 | BOOST_ASIO_DECL bool non_blocking_sendto1(socket_type s, |
283 | const void* data, size_t size, int flags, | |
284 | const socket_addr_type* addr, std::size_t addrlen, | |
285 | boost::system::error_code& ec, size_t& bytes_transferred); | |
286 | ||
7c673cae FG |
287 | #endif // !defined(BOOST_ASIO_HAS_IOCP) |
288 | ||
289 | BOOST_ASIO_DECL socket_type socket(int af, int type, int protocol, | |
290 | boost::system::error_code& ec); | |
291 | ||
292 | BOOST_ASIO_DECL int setsockopt(socket_type s, state_type& state, | |
293 | int level, int optname, const void* optval, | |
294 | std::size_t optlen, boost::system::error_code& ec); | |
295 | ||
296 | BOOST_ASIO_DECL int getsockopt(socket_type s, state_type state, | |
297 | int level, int optname, void* optval, | |
298 | size_t* optlen, boost::system::error_code& ec); | |
299 | ||
300 | BOOST_ASIO_DECL int getpeername(socket_type s, socket_addr_type* addr, | |
301 | std::size_t* addrlen, bool cached, boost::system::error_code& ec); | |
302 | ||
303 | BOOST_ASIO_DECL int getsockname(socket_type s, socket_addr_type* addr, | |
304 | std::size_t* addrlen, boost::system::error_code& ec); | |
305 | ||
306 | BOOST_ASIO_DECL int ioctl(socket_type s, state_type& state, | |
307 | int cmd, ioctl_arg_type* arg, boost::system::error_code& ec); | |
308 | ||
309 | BOOST_ASIO_DECL int select(int nfds, fd_set* readfds, fd_set* writefds, | |
310 | fd_set* exceptfds, timeval* timeout, boost::system::error_code& ec); | |
311 | ||
312 | BOOST_ASIO_DECL int poll_read(socket_type s, | |
b32b8144 | 313 | state_type state, int msec, boost::system::error_code& ec); |
7c673cae FG |
314 | |
315 | BOOST_ASIO_DECL int poll_write(socket_type s, | |
b32b8144 | 316 | state_type state, int msec, boost::system::error_code& ec); |
7c673cae | 317 | |
b32b8144 FG |
318 | BOOST_ASIO_DECL int poll_error(socket_type s, |
319 | state_type state, int msec, boost::system::error_code& ec); | |
320 | ||
321 | BOOST_ASIO_DECL int poll_connect(socket_type s, | |
322 | int msec, boost::system::error_code& ec); | |
7c673cae FG |
323 | |
324 | #endif // !defined(BOOST_ASIO_WINDOWS_RUNTIME) | |
325 | ||
326 | BOOST_ASIO_DECL const char* inet_ntop(int af, const void* src, char* dest, | |
327 | size_t length, unsigned long scope_id, boost::system::error_code& ec); | |
328 | ||
329 | BOOST_ASIO_DECL int inet_pton(int af, const char* src, void* dest, | |
330 | unsigned long* scope_id, boost::system::error_code& ec); | |
331 | ||
332 | BOOST_ASIO_DECL int gethostname(char* name, | |
333 | int namelen, boost::system::error_code& ec); | |
334 | ||
335 | #if !defined(BOOST_ASIO_WINDOWS_RUNTIME) | |
336 | ||
337 | BOOST_ASIO_DECL boost::system::error_code getaddrinfo(const char* host, | |
338 | const char* service, const addrinfo_type& hints, | |
339 | addrinfo_type** result, boost::system::error_code& ec); | |
340 | ||
341 | BOOST_ASIO_DECL boost::system::error_code background_getaddrinfo( | |
342 | const weak_cancel_token_type& cancel_token, const char* host, | |
343 | const char* service, const addrinfo_type& hints, | |
344 | addrinfo_type** result, boost::system::error_code& ec); | |
345 | ||
346 | BOOST_ASIO_DECL void freeaddrinfo(addrinfo_type* ai); | |
347 | ||
348 | BOOST_ASIO_DECL boost::system::error_code getnameinfo( | |
349 | const socket_addr_type* addr, std::size_t addrlen, | |
350 | char* host, std::size_t hostlen, char* serv, | |
351 | std::size_t servlen, int flags, boost::system::error_code& ec); | |
352 | ||
353 | BOOST_ASIO_DECL boost::system::error_code sync_getnameinfo( | |
354 | const socket_addr_type* addr, std::size_t addrlen, | |
355 | char* host, std::size_t hostlen, char* serv, | |
356 | std::size_t servlen, int sock_type, boost::system::error_code& ec); | |
357 | ||
358 | BOOST_ASIO_DECL boost::system::error_code background_getnameinfo( | |
359 | const weak_cancel_token_type& cancel_token, | |
360 | const socket_addr_type* addr, std::size_t addrlen, | |
361 | char* host, std::size_t hostlen, char* serv, | |
362 | std::size_t servlen, int sock_type, boost::system::error_code& ec); | |
363 | ||
364 | #endif // !defined(BOOST_ASIO_WINDOWS_RUNTIME) | |
365 | ||
366 | BOOST_ASIO_DECL u_long_type network_to_host_long(u_long_type value); | |
367 | ||
368 | BOOST_ASIO_DECL u_long_type host_to_network_long(u_long_type value); | |
369 | ||
370 | BOOST_ASIO_DECL u_short_type network_to_host_short(u_short_type value); | |
371 | ||
372 | BOOST_ASIO_DECL u_short_type host_to_network_short(u_short_type value); | |
373 | ||
374 | } // namespace socket_ops | |
375 | } // namespace detail | |
376 | } // namespace asio | |
377 | } // namespace boost | |
378 | ||
379 | #include <boost/asio/detail/pop_options.hpp> | |
380 | ||
381 | #if defined(BOOST_ASIO_HEADER_ONLY) | |
382 | # include <boost/asio/detail/impl/socket_ops.ipp> | |
383 | #endif // defined(BOOST_ASIO_HEADER_ONLY) | |
384 | ||
385 | #endif // BOOST_ASIO_DETAIL_SOCKET_OPS_HPP |