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