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