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