2 // detail/null_socket_service.hpp
3 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
5 // Copyright (c) 2003-2020 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/execution_context.hpp>
25 #include <boost/asio/post.hpp>
26 #include <boost/asio/socket_base.hpp>
27 #include <boost/asio/detail/bind_handler.hpp>
29 #include <boost/asio/detail/push_options.hpp>
35 template <typename Protocol>
36 class null_socket_service :
37 public execution_context_service_base<null_socket_service<Protocol> >
41 typedef Protocol protocol_type;
44 typedef typename Protocol::endpoint endpoint_type;
46 // The native type of a socket.
47 typedef int native_handle_type;
49 // The implementation type of the socket.
50 struct implementation_type
55 null_socket_service(execution_context& context)
56 : execution_context_service_base<null_socket_service<Protocol> >(context)
60 // Destroy all user-defined handler objects owned by the service.
65 // Construct a new socket implementation.
66 void construct(implementation_type&)
70 // Move-construct a new socket implementation.
71 void move_construct(implementation_type&, implementation_type&)
75 // Move-assign from another socket implementation.
76 void move_assign(implementation_type&,
77 null_socket_service&, implementation_type&)
81 // Move-construct a new socket implementation from another protocol type.
82 template <typename Protocol1>
83 void converting_move_construct(implementation_type&,
84 null_socket_service<Protocol1>&,
85 typename null_socket_service<Protocol1>::implementation_type&)
89 // Destroy a socket implementation.
90 void destroy(implementation_type&)
94 // Open a new socket implementation.
95 boost::system::error_code open(implementation_type&,
96 const protocol_type&, boost::system::error_code& ec)
98 ec = boost::asio::error::operation_not_supported;
102 // Assign a native socket to a socket implementation.
103 boost::system::error_code assign(implementation_type&, const protocol_type&,
104 const native_handle_type&, boost::system::error_code& ec)
106 ec = boost::asio::error::operation_not_supported;
110 // Determine whether the socket is open.
111 bool is_open(const implementation_type&) const
116 // Destroy a socket implementation.
117 boost::system::error_code close(implementation_type&,
118 boost::system::error_code& ec)
120 ec = boost::asio::error::operation_not_supported;
124 // Release ownership of the socket.
125 native_handle_type release(implementation_type&,
126 boost::system::error_code& ec)
128 ec = boost::asio::error::operation_not_supported;
132 // Get the native socket representation.
133 native_handle_type native_handle(implementation_type&)
138 // Cancel all operations associated with the socket.
139 boost::system::error_code cancel(implementation_type&,
140 boost::system::error_code& ec)
142 ec = boost::asio::error::operation_not_supported;
146 // Determine whether the socket is at the out-of-band data mark.
147 bool at_mark(const implementation_type&,
148 boost::system::error_code& ec) const
150 ec = boost::asio::error::operation_not_supported;
154 // Determine the number of bytes available for reading.
155 std::size_t available(const implementation_type&,
156 boost::system::error_code& ec) const
158 ec = boost::asio::error::operation_not_supported;
162 // Place the socket into the state where it will listen for new connections.
163 boost::system::error_code listen(implementation_type&,
164 int, boost::system::error_code& ec)
166 ec = boost::asio::error::operation_not_supported;
170 // Perform an IO control command on the socket.
171 template <typename IO_Control_Command>
172 boost::system::error_code io_control(implementation_type&,
173 IO_Control_Command&, boost::system::error_code& ec)
175 ec = boost::asio::error::operation_not_supported;
179 // Gets the non-blocking mode of the socket.
180 bool non_blocking(const implementation_type&) const
185 // Sets the non-blocking mode of the socket.
186 boost::system::error_code non_blocking(implementation_type&,
187 bool, boost::system::error_code& ec)
189 ec = boost::asio::error::operation_not_supported;
193 // Gets the non-blocking mode of the native socket implementation.
194 bool native_non_blocking(const implementation_type&) const
199 // Sets the non-blocking mode of the native socket implementation.
200 boost::system::error_code native_non_blocking(implementation_type&,
201 bool, boost::system::error_code& ec)
203 ec = boost::asio::error::operation_not_supported;
207 // Disable sends or receives on the socket.
208 boost::system::error_code shutdown(implementation_type&,
209 socket_base::shutdown_type, boost::system::error_code& ec)
211 ec = boost::asio::error::operation_not_supported;
215 // Bind the socket to the specified local endpoint.
216 boost::system::error_code bind(implementation_type&,
217 const endpoint_type&, boost::system::error_code& ec)
219 ec = boost::asio::error::operation_not_supported;
223 // Set a socket option.
224 template <typename Option>
225 boost::system::error_code set_option(implementation_type&,
226 const Option&, boost::system::error_code& ec)
228 ec = boost::asio::error::operation_not_supported;
232 // Set a socket option.
233 template <typename Option>
234 boost::system::error_code get_option(const implementation_type&,
235 Option&, boost::system::error_code& ec) const
237 ec = boost::asio::error::operation_not_supported;
241 // Get the local endpoint.
242 endpoint_type local_endpoint(const implementation_type&,
243 boost::system::error_code& ec) const
245 ec = boost::asio::error::operation_not_supported;
246 return endpoint_type();
249 // Get the remote endpoint.
250 endpoint_type remote_endpoint(const implementation_type&,
251 boost::system::error_code& ec) const
253 ec = boost::asio::error::operation_not_supported;
254 return endpoint_type();
257 // Send the given data to the peer.
258 template <typename ConstBufferSequence>
259 std::size_t send(implementation_type&, const ConstBufferSequence&,
260 socket_base::message_flags, boost::system::error_code& ec)
262 ec = boost::asio::error::operation_not_supported;
266 // Wait until data can be sent without blocking.
267 std::size_t send(implementation_type&, const null_buffers&,
268 socket_base::message_flags, boost::system::error_code& ec)
270 ec = boost::asio::error::operation_not_supported;
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>
277 void async_send(implementation_type&, const ConstBufferSequence&,
278 socket_base::message_flags, Handler& handler, const IoExecutor& io_ex)
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));
286 // Start an asynchronous wait until data can be sent without blocking.
287 template <typename Handler, typename IoExecutor>
288 void async_send(implementation_type&, const null_buffers&,
289 socket_base::message_flags, Handler& handler, const IoExecutor& io_ex)
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));
297 // Receive some data from the peer. Returns the number of bytes received.
298 template <typename MutableBufferSequence>
299 std::size_t receive(implementation_type&, const MutableBufferSequence&,
300 socket_base::message_flags, boost::system::error_code& ec)
302 ec = boost::asio::error::operation_not_supported;
306 // Wait until data can be received without blocking.
307 std::size_t receive(implementation_type&, const null_buffers&,
308 socket_base::message_flags, boost::system::error_code& ec)
310 ec = boost::asio::error::operation_not_supported;
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>
318 void async_receive(implementation_type&, const MutableBufferSequence&,
319 socket_base::message_flags, Handler& handler, const IoExecutor& io_ex)
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));
327 // Wait until data can be received without blocking.
328 template <typename Handler, typename IoExecutor>
329 void async_receive(implementation_type&, const null_buffers&,
330 socket_base::message_flags, Handler& handler, const IoExecutor& io_ex)
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));
338 // Receive some data with associated flags. Returns the number of bytes
340 template <typename MutableBufferSequence>
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)
345 ec = boost::asio::error::operation_not_supported;
349 // Wait until data can be received without blocking.
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)
354 ec = boost::asio::error::operation_not_supported;
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>
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)
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));
372 // Wait until data can be received without blocking.
373 template <typename Handler, typename IoExecutor>
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)
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));
384 // Send a datagram to the specified endpoint. Returns the number of bytes
386 template <typename ConstBufferSequence>
387 std::size_t send_to(implementation_type&, const ConstBufferSequence&,
388 const endpoint_type&, socket_base::message_flags,
389 boost::system::error_code& ec)
391 ec = boost::asio::error::operation_not_supported;
395 // Wait until data can be sent without blocking.
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)
400 ec = boost::asio::error::operation_not_supported;
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>
407 void async_send_to(implementation_type&, const ConstBufferSequence&,
408 const endpoint_type&, socket_base::message_flags,
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));
417 // Start an asynchronous wait until data can be sent without blocking.
418 template <typename Handler, typename IoExecutor>
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)
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));
429 // Receive a datagram with the endpoint of the sender. Returns the number of
431 template <typename MutableBufferSequence>
432 std::size_t receive_from(implementation_type&, const MutableBufferSequence&,
433 endpoint_type&, socket_base::message_flags,
434 boost::system::error_code& ec)
436 ec = boost::asio::error::operation_not_supported;
440 // Wait until data can be received without blocking.
441 std::size_t receive_from(implementation_type&, const null_buffers&,
442 endpoint_type&, socket_base::message_flags,
443 boost::system::error_code& ec)
445 ec = boost::asio::error::operation_not_supported;
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>
454 void async_receive_from(implementation_type&, const MutableBufferSequence&,
455 endpoint_type&, socket_base::message_flags, Handler& handler,
456 const IoExecutor& io_ex)
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));
464 // Wait until data can be received without blocking.
465 template <typename Handler, typename IoExecutor>
466 void async_receive_from(implementation_type&, const null_buffers&,
467 endpoint_type&, socket_base::message_flags, Handler& handler,
468 const IoExecutor& io_ex)
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));
476 // Accept a new connection.
477 template <typename Socket>
478 boost::system::error_code accept(implementation_type&,
479 Socket&, endpoint_type*, boost::system::error_code& ec)
481 ec = boost::asio::error::operation_not_supported;
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>
488 void async_accept(implementation_type&, Socket&, endpoint_type*,
489 Handler& handler, const IoExecutor& io_ex)
491 boost::system::error_code ec = boost::asio::error::operation_not_supported;
492 boost::asio::post(io_ex, detail::bind_handler(handler, ec));
495 // Connect the socket to the specified endpoint.
496 boost::system::error_code connect(implementation_type&,
497 const endpoint_type&, boost::system::error_code& ec)
499 ec = boost::asio::error::operation_not_supported;
503 // Start an asynchronous connect.
504 template <typename Handler, typename IoExecutor>
505 void async_connect(implementation_type&, const endpoint_type&,
506 Handler& handler, const IoExecutor& io_ex)
508 boost::system::error_code ec = boost::asio::error::operation_not_supported;
509 boost::asio::post(io_ex, detail::bind_handler(handler, ec));
513 } // namespace detail
517 #include <boost/asio/detail/pop_options.hpp>
519 #endif // defined(BOOST_ASIO_WINDOWS_RUNTIME)
521 #endif // BOOST_ASIO_DETAIL_NULL_SOCKET_SERVICE_HPP