2 // detail/null_socket_service.hpp
3 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
5 // Copyright (c) 2003-2014 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 typename null_socket_service<Protocol1>::implementation_type&)
86 // Destroy a socket implementation.
87 void destroy(implementation_type&)
91 // Open a new socket implementation.
92 boost::system::error_code open(implementation_type&,
93 const protocol_type&, boost::system::error_code& ec)
95 ec = boost::asio::error::operation_not_supported;
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)
103 ec = boost::asio::error::operation_not_supported;
107 // Determine whether the socket is open.
108 bool is_open(const implementation_type&) const
113 // Destroy a socket implementation.
114 boost::system::error_code close(implementation_type&,
115 boost::system::error_code& ec)
117 ec = boost::asio::error::operation_not_supported;
121 // Get the native socket representation.
122 native_handle_type native_handle(implementation_type&)
127 // Cancel all operations associated with the socket.
128 boost::system::error_code cancel(implementation_type&,
129 boost::system::error_code& ec)
131 ec = boost::asio::error::operation_not_supported;
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
139 ec = boost::asio::error::operation_not_supported;
143 // Determine the number of bytes available for reading.
144 std::size_t available(const implementation_type&,
145 boost::system::error_code& ec) const
147 ec = boost::asio::error::operation_not_supported;
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)
155 ec = boost::asio::error::operation_not_supported;
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)
164 ec = boost::asio::error::operation_not_supported;
168 // Gets the non-blocking mode of the socket.
169 bool non_blocking(const implementation_type&) const
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)
178 ec = boost::asio::error::operation_not_supported;
182 // Gets the non-blocking mode of the native socket implementation.
183 bool native_non_blocking(const implementation_type&) const
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)
192 ec = boost::asio::error::operation_not_supported;
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)
200 ec = boost::asio::error::operation_not_supported;
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)
208 ec = boost::asio::error::operation_not_supported;
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)
217 ec = boost::asio::error::operation_not_supported;
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
226 ec = boost::asio::error::operation_not_supported;
230 // Get the local endpoint.
231 endpoint_type local_endpoint(const implementation_type&,
232 boost::system::error_code& ec) const
234 ec = boost::asio::error::operation_not_supported;
235 return endpoint_type();
238 // Get the remote endpoint.
239 endpoint_type remote_endpoint(const implementation_type&,
240 boost::system::error_code& ec) const
242 ec = boost::asio::error::operation_not_supported;
243 return endpoint_type();
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)
251 ec = boost::asio::error::operation_not_supported;
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)
259 ec = boost::asio::error::operation_not_supported;
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)
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));
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)
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));
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)
289 ec = boost::asio::error::operation_not_supported;
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)
297 ec = boost::asio::error::operation_not_supported;
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)
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));
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)
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));
322 // Receive some data with associated flags. Returns the number of bytes
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)
329 ec = boost::asio::error::operation_not_supported;
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)
338 ec = boost::asio::error::operation_not_supported;
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)
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));
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)
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));
365 // Send a datagram to the specified endpoint. Returns the number of bytes
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)
372 ec = boost::asio::error::operation_not_supported;
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)
381 ec = boost::asio::error::operation_not_supported;
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,
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));
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)
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));
407 // Receive a datagram with the endpoint of the sender. Returns the number of
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)
414 ec = boost::asio::error::operation_not_supported;
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)
423 ec = boost::asio::error::operation_not_supported;
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)
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));
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)
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));
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)
456 ec = boost::asio::error::operation_not_supported;
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)
466 boost::system::error_code ec = boost::asio::error::operation_not_supported;
467 io_service_.post(detail::bind_handler(handler, ec));
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)
474 ec = boost::asio::error::operation_not_supported;
478 // Start an asynchronous connect.
479 template <typename Handler>
480 void async_connect(implementation_type&,
481 const endpoint_type&, Handler& handler)
483 boost::system::error_code ec = boost::asio::error::operation_not_supported;
484 io_service_.post(detail::bind_handler(handler, ec));
488 boost::asio::io_service& io_service_;
491 } // namespace detail
495 #include <boost/asio/detail/pop_options.hpp>
497 #endif // defined(BOOST_ASIO_WINDOWS_RUNTIME)
499 #endif // BOOST_ASIO_DETAIL_NULL_SOCKET_SERVICE_HPP