]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | // |
2 | // detail/null_socket_service.hpp | |
3 | // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | |
4 | // | |
5 | // Copyright (c) 2003-2016 Christopher M. Kohlhoff (chris at kohlhoff dot com) | |
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_NULL_SOCKET_SERVICE_HPP | |
12 | #define BOOST_ASIO_DETAIL_NULL_SOCKET_SERVICE_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 | #if defined(BOOST_ASIO_WINDOWS_RUNTIME) | |
21 | ||
22 | #include <boost/asio/buffer.hpp> | |
23 | #include <boost/asio/error.hpp> | |
24 | #include <boost/asio/io_service.hpp> | |
25 | #include <boost/asio/socket_base.hpp> | |
26 | #include <boost/asio/detail/bind_handler.hpp> | |
27 | ||
28 | #include <boost/asio/detail/push_options.hpp> | |
29 | ||
30 | namespace boost { | |
31 | namespace asio { | |
32 | namespace detail { | |
33 | ||
34 | template <typename Protocol> | |
35 | class null_socket_service | |
36 | { | |
37 | public: | |
38 | // The protocol type. | |
39 | typedef Protocol protocol_type; | |
40 | ||
41 | // The endpoint type. | |
42 | typedef typename Protocol::endpoint endpoint_type; | |
43 | ||
44 | // The native type of a socket. | |
45 | typedef int native_handle_type; | |
46 | ||
47 | // The implementation type of the socket. | |
48 | struct implementation_type | |
49 | { | |
50 | }; | |
51 | ||
52 | // Constructor. | |
53 | null_socket_service(boost::asio::io_service& io_service) | |
54 | : io_service_(io_service) | |
55 | { | |
56 | } | |
57 | ||
58 | // Destroy all user-defined handler objects owned by the service. | |
59 | void shutdown_service() | |
60 | { | |
61 | } | |
62 | ||
63 | // Construct a new socket implementation. | |
64 | void construct(implementation_type&) | |
65 | { | |
66 | } | |
67 | ||
68 | // Move-construct a new socket implementation. | |
69 | void move_construct(implementation_type&, implementation_type&) | |
70 | { | |
71 | } | |
72 | ||
73 | // Move-assign from another socket implementation. | |
74 | void move_assign(implementation_type&, | |
75 | null_socket_service&, implementation_type&) | |
76 | { | |
77 | } | |
78 | ||
79 | // Move-construct a new socket implementation from another protocol type. | |
80 | template <typename Protocol1> | |
81 | void converting_move_construct(implementation_type&, | |
82 | typename null_socket_service<Protocol1>::implementation_type&) | |
83 | { | |
84 | } | |
85 | ||
86 | // Destroy a socket implementation. | |
87 | void destroy(implementation_type&) | |
88 | { | |
89 | } | |
90 | ||
91 | // Open a new socket implementation. | |
92 | boost::system::error_code open(implementation_type&, | |
93 | const protocol_type&, boost::system::error_code& ec) | |
94 | { | |
95 | ec = boost::asio::error::operation_not_supported; | |
96 | return ec; | |
97 | } | |
98 | ||
99 | // Assign a native socket to a socket implementation. | |
100 | boost::system::error_code assign(implementation_type&, const protocol_type&, | |
101 | const native_handle_type&, boost::system::error_code& ec) | |
102 | { | |
103 | ec = boost::asio::error::operation_not_supported; | |
104 | return ec; | |
105 | } | |
106 | ||
107 | // Determine whether the socket is open. | |
108 | bool is_open(const implementation_type&) const | |
109 | { | |
110 | return false; | |
111 | } | |
112 | ||
113 | // Destroy a socket implementation. | |
114 | boost::system::error_code close(implementation_type&, | |
115 | boost::system::error_code& ec) | |
116 | { | |
117 | ec = boost::asio::error::operation_not_supported; | |
118 | return ec; | |
119 | } | |
120 | ||
121 | // Get the native socket representation. | |
122 | native_handle_type native_handle(implementation_type&) | |
123 | { | |
124 | return 0; | |
125 | } | |
126 | ||
127 | // Cancel all operations associated with the socket. | |
128 | boost::system::error_code cancel(implementation_type&, | |
129 | boost::system::error_code& ec) | |
130 | { | |
131 | ec = boost::asio::error::operation_not_supported; | |
132 | return ec; | |
133 | } | |
134 | ||
135 | // Determine whether the socket is at the out-of-band data mark. | |
136 | bool at_mark(const implementation_type&, | |
137 | boost::system::error_code& ec) const | |
138 | { | |
139 | ec = boost::asio::error::operation_not_supported; | |
140 | return false; | |
141 | } | |
142 | ||
143 | // Determine the number of bytes available for reading. | |
144 | std::size_t available(const implementation_type&, | |
145 | boost::system::error_code& ec) const | |
146 | { | |
147 | ec = boost::asio::error::operation_not_supported; | |
148 | return 0; | |
149 | } | |
150 | ||
151 | // Place the socket into the state where it will listen for new connections. | |
152 | boost::system::error_code listen(implementation_type&, | |
153 | int, boost::system::error_code& ec) | |
154 | { | |
155 | ec = boost::asio::error::operation_not_supported; | |
156 | return ec; | |
157 | } | |
158 | ||
159 | // Perform an IO control command on the socket. | |
160 | template <typename IO_Control_Command> | |
161 | boost::system::error_code io_control(implementation_type&, | |
162 | IO_Control_Command&, boost::system::error_code& ec) | |
163 | { | |
164 | ec = boost::asio::error::operation_not_supported; | |
165 | return ec; | |
166 | } | |
167 | ||
168 | // Gets the non-blocking mode of the socket. | |
169 | bool non_blocking(const implementation_type&) const | |
170 | { | |
171 | return false; | |
172 | } | |
173 | ||
174 | // Sets the non-blocking mode of the socket. | |
175 | boost::system::error_code non_blocking(implementation_type&, | |
176 | bool, boost::system::error_code& ec) | |
177 | { | |
178 | ec = boost::asio::error::operation_not_supported; | |
179 | return ec; | |
180 | } | |
181 | ||
182 | // Gets the non-blocking mode of the native socket implementation. | |
183 | bool native_non_blocking(const implementation_type&) const | |
184 | { | |
185 | return false; | |
186 | } | |
187 | ||
188 | // Sets the non-blocking mode of the native socket implementation. | |
189 | boost::system::error_code native_non_blocking(implementation_type&, | |
190 | bool, boost::system::error_code& ec) | |
191 | { | |
192 | ec = boost::asio::error::operation_not_supported; | |
193 | return ec; | |
194 | } | |
195 | ||
196 | // Disable sends or receives on the socket. | |
197 | boost::system::error_code shutdown(implementation_type&, | |
198 | socket_base::shutdown_type, boost::system::error_code& ec) | |
199 | { | |
200 | ec = boost::asio::error::operation_not_supported; | |
201 | return ec; | |
202 | } | |
203 | ||
204 | // Bind the socket to the specified local endpoint. | |
205 | boost::system::error_code bind(implementation_type&, | |
206 | const endpoint_type&, boost::system::error_code& ec) | |
207 | { | |
208 | ec = boost::asio::error::operation_not_supported; | |
209 | return ec; | |
210 | } | |
211 | ||
212 | // Set a socket option. | |
213 | template <typename Option> | |
214 | boost::system::error_code set_option(implementation_type&, | |
215 | const Option&, boost::system::error_code& ec) | |
216 | { | |
217 | ec = boost::asio::error::operation_not_supported; | |
218 | return ec; | |
219 | } | |
220 | ||
221 | // Set a socket option. | |
222 | template <typename Option> | |
223 | boost::system::error_code get_option(const implementation_type&, | |
224 | Option&, boost::system::error_code& ec) const | |
225 | { | |
226 | ec = boost::asio::error::operation_not_supported; | |
227 | return ec; | |
228 | } | |
229 | ||
230 | // Get the local endpoint. | |
231 | endpoint_type local_endpoint(const implementation_type&, | |
232 | boost::system::error_code& ec) const | |
233 | { | |
234 | ec = boost::asio::error::operation_not_supported; | |
235 | return endpoint_type(); | |
236 | } | |
237 | ||
238 | // Get the remote endpoint. | |
239 | endpoint_type remote_endpoint(const implementation_type&, | |
240 | boost::system::error_code& ec) const | |
241 | { | |
242 | ec = boost::asio::error::operation_not_supported; | |
243 | return endpoint_type(); | |
244 | } | |
245 | ||
246 | // Send the given data to the peer. | |
247 | template <typename ConstBufferSequence> | |
248 | std::size_t send(implementation_type&, const ConstBufferSequence&, | |
249 | socket_base::message_flags, boost::system::error_code& ec) | |
250 | { | |
251 | ec = boost::asio::error::operation_not_supported; | |
252 | return 0; | |
253 | } | |
254 | ||
255 | // Wait until data can be sent without blocking. | |
256 | std::size_t send(implementation_type&, const null_buffers&, | |
257 | socket_base::message_flags, boost::system::error_code& ec) | |
258 | { | |
259 | ec = boost::asio::error::operation_not_supported; | |
260 | return 0; | |
261 | } | |
262 | ||
263 | // Start an asynchronous send. The data being sent must be valid for the | |
264 | // lifetime of the asynchronous operation. | |
265 | template <typename ConstBufferSequence, typename Handler> | |
266 | void async_send(implementation_type&, const ConstBufferSequence&, | |
267 | socket_base::message_flags, Handler& handler) | |
268 | { | |
269 | boost::system::error_code ec = boost::asio::error::operation_not_supported; | |
270 | const std::size_t bytes_transferred = 0; | |
271 | io_service_.post(detail::bind_handler(handler, ec, bytes_transferred)); | |
272 | } | |
273 | ||
274 | // Start an asynchronous wait until data can be sent without blocking. | |
275 | template <typename Handler> | |
276 | void async_send(implementation_type&, const null_buffers&, | |
277 | socket_base::message_flags, Handler& handler) | |
278 | { | |
279 | boost::system::error_code ec = boost::asio::error::operation_not_supported; | |
280 | const std::size_t bytes_transferred = 0; | |
281 | io_service_.post(detail::bind_handler(handler, ec, bytes_transferred)); | |
282 | } | |
283 | ||
284 | // Receive some data from the peer. Returns the number of bytes received. | |
285 | template <typename MutableBufferSequence> | |
286 | std::size_t receive(implementation_type&, const MutableBufferSequence&, | |
287 | socket_base::message_flags, boost::system::error_code& ec) | |
288 | { | |
289 | ec = boost::asio::error::operation_not_supported; | |
290 | return 0; | |
291 | } | |
292 | ||
293 | // Wait until data can be received without blocking. | |
294 | std::size_t receive(implementation_type&, const null_buffers&, | |
295 | socket_base::message_flags, boost::system::error_code& ec) | |
296 | { | |
297 | ec = boost::asio::error::operation_not_supported; | |
298 | return 0; | |
299 | } | |
300 | ||
301 | // Start an asynchronous receive. The buffer for the data being received | |
302 | // must be valid for the lifetime of the asynchronous operation. | |
303 | template <typename MutableBufferSequence, typename Handler> | |
304 | void async_receive(implementation_type&, const MutableBufferSequence&, | |
305 | socket_base::message_flags, Handler& handler) | |
306 | { | |
307 | boost::system::error_code ec = boost::asio::error::operation_not_supported; | |
308 | const std::size_t bytes_transferred = 0; | |
309 | io_service_.post(detail::bind_handler(handler, ec, bytes_transferred)); | |
310 | } | |
311 | ||
312 | // Wait until data can be received without blocking. | |
313 | template <typename Handler> | |
314 | void async_receive(implementation_type&, const null_buffers&, | |
315 | socket_base::message_flags, Handler& handler) | |
316 | { | |
317 | boost::system::error_code ec = boost::asio::error::operation_not_supported; | |
318 | const std::size_t bytes_transferred = 0; | |
319 | io_service_.post(detail::bind_handler(handler, ec, bytes_transferred)); | |
320 | } | |
321 | ||
322 | // Receive some data with associated flags. Returns the number of bytes | |
323 | // received. | |
324 | template <typename MutableBufferSequence> | |
325 | std::size_t receive_with_flags(implementation_type&, | |
326 | const MutableBufferSequence&, socket_base::message_flags, | |
327 | socket_base::message_flags&, boost::system::error_code& ec) | |
328 | { | |
329 | ec = boost::asio::error::operation_not_supported; | |
330 | return 0; | |
331 | } | |
332 | ||
333 | // Wait until data can be received without blocking. | |
334 | std::size_t receive_with_flags(implementation_type&, | |
335 | const null_buffers&, socket_base::message_flags, | |
336 | socket_base::message_flags&, boost::system::error_code& ec) | |
337 | { | |
338 | ec = boost::asio::error::operation_not_supported; | |
339 | return 0; | |
340 | } | |
341 | ||
342 | // Start an asynchronous receive. The buffer for the data being received | |
343 | // must be valid for the lifetime of the asynchronous operation. | |
344 | template <typename MutableBufferSequence, typename Handler> | |
345 | void async_receive_with_flags(implementation_type&, | |
346 | const MutableBufferSequence&, socket_base::message_flags, | |
347 | socket_base::message_flags&, Handler& handler) | |
348 | { | |
349 | boost::system::error_code ec = boost::asio::error::operation_not_supported; | |
350 | const std::size_t bytes_transferred = 0; | |
351 | io_service_.post(detail::bind_handler(handler, ec, bytes_transferred)); | |
352 | } | |
353 | ||
354 | // Wait until data can be received without blocking. | |
355 | template <typename Handler> | |
356 | void async_receive_with_flags(implementation_type&, | |
357 | const null_buffers&, socket_base::message_flags, | |
358 | socket_base::message_flags&, Handler& handler) | |
359 | { | |
360 | boost::system::error_code ec = boost::asio::error::operation_not_supported; | |
361 | const std::size_t bytes_transferred = 0; | |
362 | io_service_.post(detail::bind_handler(handler, ec, bytes_transferred)); | |
363 | } | |
364 | ||
365 | // Send a datagram to the specified endpoint. Returns the number of bytes | |
366 | // sent. | |
367 | template <typename ConstBufferSequence> | |
368 | std::size_t send_to(implementation_type&, const ConstBufferSequence&, | |
369 | const endpoint_type&, socket_base::message_flags, | |
370 | boost::system::error_code& ec) | |
371 | { | |
372 | ec = boost::asio::error::operation_not_supported; | |
373 | return 0; | |
374 | } | |
375 | ||
376 | // Wait until data can be sent without blocking. | |
377 | std::size_t send_to(implementation_type&, const null_buffers&, | |
378 | const endpoint_type&, socket_base::message_flags, | |
379 | boost::system::error_code& ec) | |
380 | { | |
381 | ec = boost::asio::error::operation_not_supported; | |
382 | return 0; | |
383 | } | |
384 | ||
385 | // Start an asynchronous send. The data being sent must be valid for the | |
386 | // lifetime of the asynchronous operation. | |
387 | template <typename ConstBufferSequence, typename Handler> | |
388 | void async_send_to(implementation_type&, const ConstBufferSequence&, | |
389 | const endpoint_type&, socket_base::message_flags, | |
390 | Handler& handler) | |
391 | { | |
392 | boost::system::error_code ec = boost::asio::error::operation_not_supported; | |
393 | const std::size_t bytes_transferred = 0; | |
394 | io_service_.post(detail::bind_handler(handler, ec, bytes_transferred)); | |
395 | } | |
396 | ||
397 | // Start an asynchronous wait until data can be sent without blocking. | |
398 | template <typename Handler> | |
399 | void async_send_to(implementation_type&, const null_buffers&, | |
400 | const endpoint_type&, socket_base::message_flags, Handler& handler) | |
401 | { | |
402 | boost::system::error_code ec = boost::asio::error::operation_not_supported; | |
403 | const std::size_t bytes_transferred = 0; | |
404 | io_service_.post(detail::bind_handler(handler, ec, bytes_transferred)); | |
405 | } | |
406 | ||
407 | // Receive a datagram with the endpoint of the sender. Returns the number of | |
408 | // bytes received. | |
409 | template <typename MutableBufferSequence> | |
410 | std::size_t receive_from(implementation_type&, const MutableBufferSequence&, | |
411 | endpoint_type&, socket_base::message_flags, | |
412 | boost::system::error_code& ec) | |
413 | { | |
414 | ec = boost::asio::error::operation_not_supported; | |
415 | return 0; | |
416 | } | |
417 | ||
418 | // Wait until data can be received without blocking. | |
419 | std::size_t receive_from(implementation_type&, const null_buffers&, | |
420 | endpoint_type&, socket_base::message_flags, | |
421 | boost::system::error_code& ec) | |
422 | { | |
423 | ec = boost::asio::error::operation_not_supported; | |
424 | return 0; | |
425 | } | |
426 | ||
427 | // Start an asynchronous receive. The buffer for the data being received and | |
428 | // the sender_endpoint object must both be valid for the lifetime of the | |
429 | // asynchronous operation. | |
430 | template <typename MutableBufferSequence, typename Handler> | |
431 | void async_receive_from(implementation_type&, | |
432 | const MutableBufferSequence&, endpoint_type&, | |
433 | socket_base::message_flags, Handler& handler) | |
434 | { | |
435 | boost::system::error_code ec = boost::asio::error::operation_not_supported; | |
436 | const std::size_t bytes_transferred = 0; | |
437 | io_service_.post(detail::bind_handler(handler, ec, bytes_transferred)); | |
438 | } | |
439 | ||
440 | // Wait until data can be received without blocking. | |
441 | template <typename Handler> | |
442 | void async_receive_from(implementation_type&, | |
443 | const null_buffers&, endpoint_type&, | |
444 | socket_base::message_flags, Handler& handler) | |
445 | { | |
446 | boost::system::error_code ec = boost::asio::error::operation_not_supported; | |
447 | const std::size_t bytes_transferred = 0; | |
448 | io_service_.post(detail::bind_handler(handler, ec, bytes_transferred)); | |
449 | } | |
450 | ||
451 | // Accept a new connection. | |
452 | template <typename Socket> | |
453 | boost::system::error_code accept(implementation_type&, | |
454 | Socket&, endpoint_type*, boost::system::error_code& ec) | |
455 | { | |
456 | ec = boost::asio::error::operation_not_supported; | |
457 | return ec; | |
458 | } | |
459 | ||
460 | // Start an asynchronous accept. The peer and peer_endpoint objects | |
461 | // must be valid until the accept's handler is invoked. | |
462 | template <typename Socket, typename Handler> | |
463 | void async_accept(implementation_type&, Socket&, | |
464 | endpoint_type*, Handler& handler) | |
465 | { | |
466 | boost::system::error_code ec = boost::asio::error::operation_not_supported; | |
467 | io_service_.post(detail::bind_handler(handler, ec)); | |
468 | } | |
469 | ||
470 | // Connect the socket to the specified endpoint. | |
471 | boost::system::error_code connect(implementation_type&, | |
472 | const endpoint_type&, boost::system::error_code& ec) | |
473 | { | |
474 | ec = boost::asio::error::operation_not_supported; | |
475 | return ec; | |
476 | } | |
477 | ||
478 | // Start an asynchronous connect. | |
479 | template <typename Handler> | |
480 | void async_connect(implementation_type&, | |
481 | const endpoint_type&, Handler& handler) | |
482 | { | |
483 | boost::system::error_code ec = boost::asio::error::operation_not_supported; | |
484 | io_service_.post(detail::bind_handler(handler, ec)); | |
485 | } | |
486 | ||
487 | private: | |
488 | boost::asio::io_service& io_service_; | |
489 | }; | |
490 | ||
491 | } // namespace detail | |
492 | } // namespace asio | |
493 | } // namespace boost | |
494 | ||
495 | #include <boost/asio/detail/pop_options.hpp> | |
496 | ||
497 | #endif // defined(BOOST_ASIO_WINDOWS_RUNTIME) | |
498 | ||
499 | #endif // BOOST_ASIO_DETAIL_NULL_SOCKET_SERVICE_HPP |