2 // detail/null_socket_service.hpp
3 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
5 // Copyright (c) 2003-2017 Christopher M. Kohlhoff (chris at kohlhoff dot com)
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)
11 #ifndef BOOST_ASIO_DETAIL_NULL_SOCKET_SERVICE_HPP
12 #define BOOST_ASIO_DETAIL_NULL_SOCKET_SERVICE_HPP
14 #if defined(_MSC_VER) && (_MSC_VER >= 1200)
16 #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
18 #include <boost/asio/detail/config.hpp>
20 #if defined(BOOST_ASIO_WINDOWS_RUNTIME)
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>
28 #include <boost/asio/detail/push_options.hpp>
34 template <typename Protocol>
35 class null_socket_service
39 typedef Protocol protocol_type;
42 typedef typename Protocol::endpoint endpoint_type;
44 // The native type of a socket.
45 typedef int native_handle_type;
47 // The implementation type of the socket.
48 struct implementation_type
53 null_socket_service(boost::asio::io_service& io_service)
54 : io_service_(io_service)
58 // Destroy all user-defined handler objects owned by the service.
59 void shutdown_service()
63 // Construct a new socket implementation.
64 void construct(implementation_type&)
68 // Move-construct a new socket implementation.
69 void move_construct(implementation_type&, implementation_type&)
73 // Move-assign from another socket implementation.
74 void move_assign(implementation_type&,
75 null_socket_service&, implementation_type&)
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&)
87 // Destroy a socket implementation.
88 void destroy(implementation_type&)
92 // Open a new socket implementation.
93 boost::system::error_code open(implementation_type&,
94 const protocol_type&, boost::system::error_code& ec)
96 ec = boost::asio::error::operation_not_supported;
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)
104 ec = boost::asio::error::operation_not_supported;
108 // Determine whether the socket is open.
109 bool is_open(const implementation_type&) const
114 // Destroy a socket implementation.
115 boost::system::error_code close(implementation_type&,
116 boost::system::error_code& ec)
118 ec = boost::asio::error::operation_not_supported;
122 // Get the native socket representation.
123 native_handle_type native_handle(implementation_type&)
128 // Cancel all operations associated with the socket.
129 boost::system::error_code cancel(implementation_type&,
130 boost::system::error_code& ec)
132 ec = boost::asio::error::operation_not_supported;
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
140 ec = boost::asio::error::operation_not_supported;
144 // Determine the number of bytes available for reading.
145 std::size_t available(const implementation_type&,
146 boost::system::error_code& ec) const
148 ec = boost::asio::error::operation_not_supported;
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)
156 ec = boost::asio::error::operation_not_supported;
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)
165 ec = boost::asio::error::operation_not_supported;
169 // Gets the non-blocking mode of the socket.
170 bool non_blocking(const implementation_type&) const
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)
179 ec = boost::asio::error::operation_not_supported;
183 // Gets the non-blocking mode of the native socket implementation.
184 bool native_non_blocking(const implementation_type&) const
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)
193 ec = boost::asio::error::operation_not_supported;
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)
201 ec = boost::asio::error::operation_not_supported;
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)
209 ec = boost::asio::error::operation_not_supported;
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)
218 ec = boost::asio::error::operation_not_supported;
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
227 ec = boost::asio::error::operation_not_supported;
231 // Get the local endpoint.
232 endpoint_type local_endpoint(const implementation_type&,
233 boost::system::error_code& ec) const
235 ec = boost::asio::error::operation_not_supported;
236 return endpoint_type();
239 // Get the remote endpoint.
240 endpoint_type remote_endpoint(const implementation_type&,
241 boost::system::error_code& ec) const
243 ec = boost::asio::error::operation_not_supported;
244 return endpoint_type();
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)
252 ec = boost::asio::error::operation_not_supported;
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)
260 ec = boost::asio::error::operation_not_supported;
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)
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));
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)
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));
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)
290 ec = boost::asio::error::operation_not_supported;
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)
298 ec = boost::asio::error::operation_not_supported;
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)
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));
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)
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));
323 // Receive some data with associated flags. Returns the number of bytes
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)
330 ec = boost::asio::error::operation_not_supported;
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)
339 ec = boost::asio::error::operation_not_supported;
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)
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));
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)
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));
366 // Send a datagram to the specified endpoint. Returns the number of bytes
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)
373 ec = boost::asio::error::operation_not_supported;
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)
382 ec = boost::asio::error::operation_not_supported;
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,
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));
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)
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));
408 // Receive a datagram with the endpoint of the sender. Returns the number of
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)
415 ec = boost::asio::error::operation_not_supported;
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)
424 ec = boost::asio::error::operation_not_supported;
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)
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));
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)
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));
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)
457 ec = boost::asio::error::operation_not_supported;
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)
467 boost::system::error_code ec = boost::asio::error::operation_not_supported;
468 io_service_.post(detail::bind_handler(handler, ec));
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)
475 ec = boost::asio::error::operation_not_supported;
479 // Start an asynchronous connect.
480 template <typename Handler>
481 void async_connect(implementation_type&,
482 const endpoint_type&, Handler& handler)
484 boost::system::error_code ec = boost::asio::error::operation_not_supported;
485 io_service_.post(detail::bind_handler(handler, ec));
489 boost::asio::io_service& io_service_;
492 } // namespace detail
496 #include <boost/asio/detail/pop_options.hpp>
498 #endif // defined(BOOST_ASIO_WINDOWS_RUNTIME)
500 #endif // BOOST_ASIO_DETAIL_NULL_SOCKET_SERVICE_HPP