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