From 4f9168c23ec008a9040b51cb1091cc873150d2ee Mon Sep 17 00:00:00 2001 From: sailfish009 Date: Fri, 20 Mar 2020 11:29:58 +0900 Subject: [PATCH] v1.14.0 --- backup/asio_ssl.cpp | 2 +- build/.gitignore | 3 +- build/_clear.sh | 2 + include/asio.hpp | 29 +- include/asio/associated_allocator.hpp | 2 +- include/asio/associated_executor.hpp | 2 +- include/asio/async_result.hpp | 265 +- include/asio/awaitable.hpp | 123 + include/asio/basic_datagram_socket.hpp | 535 ++-- include/asio/basic_deadline_timer.hpp | 258 +- include/asio/basic_io_object.hpp | 2 +- include/asio/basic_raw_socket.hpp | 537 ++-- include/asio/basic_seq_packet_socket.hpp | 360 ++- include/asio/basic_serial_port.hpp | 347 ++- include/asio/basic_signal_set.hpp | 272 +- include/asio/basic_socket.hpp | 539 ++-- include/asio/basic_socket_acceptor.hpp | 1258 ++++++--- include/asio/basic_socket_iostream.hpp | 65 +- include/asio/basic_socket_streambuf.hpp | 50 +- include/asio/basic_stream_socket.hpp | 428 +-- include/asio/basic_streambuf.hpp | 2 +- include/asio/basic_streambuf_fwd.hpp | 2 +- include/asio/basic_waitable_timer.hpp | 267 +- include/asio/bind_executor.hpp | 33 +- include/asio/buffer.hpp | 495 +++- include/asio/buffered_read_stream.hpp | 19 +- include/asio/buffered_read_stream_fwd.hpp | 2 +- include/asio/buffered_stream.hpp | 19 +- include/asio/buffered_stream_fwd.hpp | 2 +- include/asio/buffered_write_stream.hpp | 19 +- include/asio/buffered_write_stream_fwd.hpp | 2 +- include/asio/buffers_iterator.hpp | 2 +- include/asio/co_spawn.hpp | 88 + include/asio/completion_condition.hpp | 2 +- include/asio/compose.hpp | 136 + include/asio/connect.hpp | 165 +- include/asio/coroutine.hpp | 6 +- include/asio/datagram_socket_service.hpp | 466 ---- include/asio/deadline_timer.hpp | 2 +- include/asio/deadline_timer_service.hpp | 173 -- include/asio/defer.hpp | 12 +- include/asio/{experimental => }/detached.hpp | 23 +- include/asio/detail/array.hpp | 2 +- include/asio/detail/array_fwd.hpp | 2 +- include/asio/detail/assert.hpp | 2 +- include/asio/detail/atomic_count.hpp | 2 +- .../asio/detail/base_from_completion_cond.hpp | 7 +- include/asio/detail/bind_handler.hpp | 2 +- include/asio/detail/buffer_resize_guard.hpp | 2 +- .../asio/detail/buffer_sequence_adapter.hpp | 2 +- .../asio/detail/buffered_stream_storage.hpp | 2 +- include/asio/detail/call_stack.hpp | 2 +- include/asio/detail/chrono.hpp | 2 +- include/asio/detail/chrono_time_traits.hpp | 2 +- include/asio/detail/completion_handler.hpp | 2 +- include/asio/detail/concurrency_hint.hpp | 2 +- .../detail/conditionally_enabled_event.hpp | 2 +- .../detail/conditionally_enabled_mutex.hpp | 2 +- include/asio/detail/config.hpp | 78 +- include/asio/detail/consuming_buffers.hpp | 2 +- include/asio/detail/cstddef.hpp | 2 +- include/asio/detail/cstdint.hpp | 2 +- include/asio/detail/date_time_fwd.hpp | 2 +- .../asio/detail/deadline_timer_service.hpp | 22 +- include/asio/detail/dependent_type.hpp | 2 +- include/asio/detail/descriptor_ops.hpp | 2 +- include/asio/detail/descriptor_read_op.hpp | 16 +- include/asio/detail/descriptor_write_op.hpp | 16 +- include/asio/detail/dev_poll_reactor.hpp | 2 +- include/asio/detail/epoll_reactor.hpp | 2 +- include/asio/detail/event.hpp | 2 +- .../detail/eventfd_select_interrupter.hpp | 2 +- include/asio/detail/executor_function.hpp | 104 + include/asio/detail/executor_op.hpp | 2 +- include/asio/detail/fd_set_adapter.hpp | 2 +- include/asio/detail/fenced_block.hpp | 2 +- include/asio/detail/functional.hpp | 2 +- include/asio/detail/future.hpp | 2 +- include/asio/detail/gcc_arm_fenced_block.hpp | 2 +- include/asio/detail/gcc_hppa_fenced_block.hpp | 2 +- include/asio/detail/gcc_sync_fenced_block.hpp | 2 +- include/asio/detail/gcc_x86_fenced_block.hpp | 2 +- include/asio/detail/global.hpp | 2 +- include/asio/detail/handler_alloc_helpers.hpp | 19 +- include/asio/detail/handler_cont_helpers.hpp | 2 +- .../asio/detail/handler_invoke_helpers.hpp | 2 +- include/asio/detail/handler_tracking.hpp | 2 +- .../asio/detail/handler_type_requirements.hpp | 2 +- include/asio/detail/handler_work.hpp | 34 +- include/asio/detail/hash_map.hpp | 2 +- .../detail/impl/buffer_sequence_adapter.ipp | 2 +- include/asio/detail/impl/descriptor_ops.ipp | 2 +- include/asio/detail/impl/dev_poll_reactor.hpp | 2 +- include/asio/detail/impl/dev_poll_reactor.ipp | 2 +- include/asio/detail/impl/epoll_reactor.hpp | 2 +- include/asio/detail/impl/epoll_reactor.ipp | 2 +- .../impl/eventfd_select_interrupter.ipp | 2 +- include/asio/detail/impl/handler_tracking.ipp | 2 +- include/asio/detail/impl/kqueue_reactor.hpp | 2 +- include/asio/detail/impl/kqueue_reactor.ipp | 2 +- include/asio/detail/impl/null_event.ipp | 2 +- .../detail/impl/pipe_select_interrupter.ipp | 2 +- include/asio/detail/impl/posix_event.ipp | 2 +- include/asio/detail/impl/posix_mutex.ipp | 2 +- include/asio/detail/impl/posix_thread.ipp | 2 +- include/asio/detail/impl/posix_tss_ptr.ipp | 2 +- .../impl/reactive_descriptor_service.ipp | 8 +- .../impl/reactive_serial_port_service.ipp | 8 +- .../impl/reactive_socket_service_base.ipp | 7 +- .../detail/impl/resolver_service_base.ipp | 64 +- include/asio/detail/impl/scheduler.ipp | 54 +- include/asio/detail/impl/select_reactor.hpp | 2 +- include/asio/detail/impl/select_reactor.ipp | 2 +- include/asio/detail/impl/service_registry.hpp | 2 +- include/asio/detail/impl/service_registry.ipp | 2 +- .../asio/detail/impl/signal_set_service.ipp | 42 +- include/asio/detail/impl/socket_ops.ipp | 9 +- .../detail/impl/socket_select_interrupter.ipp | 2 +- .../detail/impl/strand_executor_service.hpp | 2 +- .../detail/impl/strand_executor_service.ipp | 2 +- include/asio/detail/impl/strand_service.hpp | 2 +- include/asio/detail/impl/strand_service.ipp | 2 +- include/asio/detail/impl/throw_error.ipp | 2 +- .../asio/detail/impl/timer_queue_ptime.ipp | 2 +- include/asio/detail/impl/timer_queue_set.ipp | 2 +- include/asio/detail/impl/win_event.ipp | 2 +- .../detail/impl/win_iocp_handle_service.ipp | 9 +- .../asio/detail/impl/win_iocp_io_context.hpp | 2 +- .../asio/detail/impl/win_iocp_io_context.ipp | 43 +- .../impl/win_iocp_serial_port_service.ipp | 8 +- .../impl/win_iocp_socket_service_base.ipp | 10 +- include/asio/detail/impl/win_mutex.ipp | 2 +- .../detail/impl/win_object_handle_service.ipp | 35 +- include/asio/detail/impl/win_static_mutex.ipp | 2 +- include/asio/detail/impl/win_thread.ipp | 2 +- include/asio/detail/impl/win_tss_ptr.ipp | 2 +- .../impl/winrt_ssocket_service_base.ipp | 30 +- .../detail/impl/winrt_timer_scheduler.hpp | 8 +- .../detail/impl/winrt_timer_scheduler.ipp | 15 +- include/asio/detail/impl/winsock_init.ipp | 2 +- include/asio/detail/io_control.hpp | 2 +- include/asio/detail/io_object_executor.hpp | 160 ++ include/asio/detail/io_object_impl.hpp | 193 ++ include/asio/detail/is_buffer_sequence.hpp | 51 +- include/asio/detail/is_executor.hpp | 2 +- include/asio/detail/keyword_tss_ptr.hpp | 2 +- include/asio/detail/kqueue_reactor.hpp | 2 +- .../asio/detail/local_free_on_block_exit.hpp | 2 +- include/asio/detail/macos_fenced_block.hpp | 2 +- include/asio/detail/memory.hpp | 2 +- include/asio/detail/mutex.hpp | 2 +- include/asio/detail/non_const_lvalue.hpp | 54 + include/asio/detail/noncopyable.hpp | 2 +- include/asio/detail/null_event.hpp | 2 +- include/asio/detail/null_fenced_block.hpp | 2 +- include/asio/detail/null_global.hpp | 2 +- include/asio/detail/null_mutex.hpp | 2 +- include/asio/detail/null_reactor.hpp | 2 +- include/asio/detail/null_signal_blocker.hpp | 2 +- include/asio/detail/null_socket_service.hpp | 115 +- include/asio/detail/null_static_mutex.hpp | 2 +- include/asio/detail/null_thread.hpp | 2 +- include/asio/detail/null_tss_ptr.hpp | 2 +- include/asio/detail/object_pool.hpp | 2 +- include/asio/detail/old_win_sdk_compat.hpp | 2 +- include/asio/detail/op_queue.hpp | 2 +- include/asio/detail/operation.hpp | 2 +- .../asio/detail/pipe_select_interrupter.hpp | 2 +- include/asio/detail/pop_options.hpp | 14 +- include/asio/detail/posix_event.hpp | 4 +- include/asio/detail/posix_fd_set_adapter.hpp | 2 +- include/asio/detail/posix_global.hpp | 2 +- include/asio/detail/posix_mutex.hpp | 2 +- include/asio/detail/posix_signal_blocker.hpp | 2 +- include/asio/detail/posix_static_mutex.hpp | 2 +- include/asio/detail/posix_thread.hpp | 2 +- include/asio/detail/posix_tss_ptr.hpp | 2 +- include/asio/detail/push_options.hpp | 14 +- .../detail/reactive_descriptor_service.hpp | 53 +- .../asio/detail/reactive_null_buffers_op.hpp | 14 +- .../detail/reactive_serial_port_service.hpp | 24 +- .../asio/detail/reactive_socket_accept_op.hpp | 51 +- .../detail/reactive_socket_connect_op.hpp | 15 +- .../asio/detail/reactive_socket_recv_op.hpp | 18 +- .../detail/reactive_socket_recvfrom_op.hpp | 16 +- .../detail/reactive_socket_recvmsg_op.hpp | 15 +- .../asio/detail/reactive_socket_send_op.hpp | 18 +- .../asio/detail/reactive_socket_sendto_op.hpp | 16 +- .../asio/detail/reactive_socket_service.hpp | 115 +- .../detail/reactive_socket_service_base.hpp | 83 +- include/asio/detail/reactive_wait_op.hpp | 14 +- include/asio/detail/reactor.hpp | 2 +- include/asio/detail/reactor_fwd.hpp | 2 +- include/asio/detail/reactor_op.hpp | 2 +- include/asio/detail/reactor_op_queue.hpp | 2 +- include/asio/detail/recycling_allocator.hpp | 30 +- include/asio/detail/regex_fwd.hpp | 2 +- include/asio/detail/resolve_endpoint_op.hpp | 36 +- include/asio/detail/resolve_op.hpp | 2 +- include/asio/detail/resolve_query_op.hpp | 34 +- include/asio/detail/resolver_service.hpp | 36 +- include/asio/detail/resolver_service_base.hpp | 41 +- include/asio/detail/scheduler.hpp | 15 +- include/asio/detail/scheduler_operation.hpp | 2 +- include/asio/detail/scheduler_thread_info.hpp | 2 +- include/asio/detail/scoped_lock.hpp | 2 +- include/asio/detail/scoped_ptr.hpp | 2 +- include/asio/detail/select_interrupter.hpp | 2 +- include/asio/detail/select_reactor.hpp | 2 +- include/asio/detail/service_registry.hpp | 2 +- include/asio/detail/signal_blocker.hpp | 2 +- include/asio/detail/signal_handler.hpp | 14 +- include/asio/detail/signal_init.hpp | 2 +- include/asio/detail/signal_op.hpp | 2 +- include/asio/detail/signal_set_service.hpp | 36 +- include/asio/detail/socket_holder.hpp | 2 +- include/asio/detail/socket_ops.hpp | 2 +- include/asio/detail/socket_option.hpp | 2 +- .../asio/detail/socket_select_interrupter.hpp | 2 +- include/asio/detail/socket_types.hpp | 2 +- include/asio/detail/solaris_fenced_block.hpp | 2 +- include/asio/detail/static_mutex.hpp | 2 +- include/asio/detail/std_event.hpp | 2 +- include/asio/detail/std_fenced_block.hpp | 2 +- include/asio/detail/std_global.hpp | 2 +- include/asio/detail/std_mutex.hpp | 2 +- include/asio/detail/std_static_mutex.hpp | 2 +- include/asio/detail/std_thread.hpp | 2 +- .../asio/detail/strand_executor_service.hpp | 2 +- include/asio/detail/strand_service.hpp | 2 +- include/asio/detail/string_view.hpp | 2 +- include/asio/detail/thread.hpp | 2 +- include/asio/detail/thread_context.hpp | 2 +- include/asio/detail/thread_group.hpp | 8 +- include/asio/detail/thread_info_base.hpp | 11 +- include/asio/detail/throw_error.hpp | 2 +- include/asio/detail/throw_exception.hpp | 2 +- include/asio/detail/timer_queue.hpp | 2 +- include/asio/detail/timer_queue_base.hpp | 2 +- include/asio/detail/timer_queue_ptime.hpp | 2 +- include/asio/detail/timer_queue_set.hpp | 2 +- include/asio/detail/timer_scheduler.hpp | 2 +- include/asio/detail/timer_scheduler_fwd.hpp | 2 +- include/asio/detail/tss_ptr.hpp | 2 +- include/asio/detail/type_traits.hpp | 2 +- include/asio/detail/variadic_templates.hpp | 16 +- include/asio/detail/wait_handler.hpp | 16 +- include/asio/detail/wait_op.hpp | 2 +- include/asio/detail/win_event.hpp | 2 +- include/asio/detail/win_fd_set_adapter.hpp | 2 +- include/asio/detail/win_fenced_block.hpp | 2 +- include/asio/detail/win_global.hpp | 13 +- .../asio/detail/win_iocp_handle_read_op.hpp | 16 +- .../asio/detail/win_iocp_handle_service.hpp | 72 +- .../asio/detail/win_iocp_handle_write_op.hpp | 15 +- include/asio/detail/win_iocp_io_context.hpp | 14 +- .../asio/detail/win_iocp_null_buffers_op.hpp | 14 +- include/asio/detail/win_iocp_operation.hpp | 2 +- .../asio/detail/win_iocp_overlapped_op.hpp | 14 +- .../asio/detail/win_iocp_overlapped_ptr.hpp | 42 +- .../detail/win_iocp_serial_port_service.hpp | 24 +- .../asio/detail/win_iocp_socket_accept_op.hpp | 41 +- .../detail/win_iocp_socket_connect_op.hpp | 15 +- .../asio/detail/win_iocp_socket_recv_op.hpp | 15 +- .../detail/win_iocp_socket_recvfrom_op.hpp | 16 +- .../detail/win_iocp_socket_recvmsg_op.hpp | 15 +- .../asio/detail/win_iocp_socket_send_op.hpp | 15 +- .../asio/detail/win_iocp_socket_service.hpp | 132 +- .../detail/win_iocp_socket_service_base.hpp | 101 +- include/asio/detail/win_iocp_thread_info.hpp | 2 +- include/asio/detail/win_iocp_wait_op.hpp | 14 +- include/asio/detail/win_mutex.hpp | 2 +- .../asio/detail/win_object_handle_service.hpp | 35 +- include/asio/detail/win_static_mutex.hpp | 2 +- include/asio/detail/win_thread.hpp | 2 +- include/asio/detail/win_tss_ptr.hpp | 2 +- include/asio/detail/winapp_thread.hpp | 2 +- include/asio/detail/wince_thread.hpp | 2 +- include/asio/detail/winrt_async_manager.hpp | 39 +- include/asio/detail/winrt_async_op.hpp | 2 +- include/asio/detail/winrt_resolve_op.hpp | 15 +- .../asio/detail/winrt_resolver_service.hpp | 54 +- .../asio/detail/winrt_socket_connect_op.hpp | 14 +- include/asio/detail/winrt_socket_recv_op.hpp | 15 +- include/asio/detail/winrt_socket_send_op.hpp | 15 +- include/asio/detail/winrt_ssocket_service.hpp | 23 +- .../detail/winrt_ssocket_service_base.hpp | 59 +- include/asio/detail/winrt_timer_scheduler.hpp | 26 +- include/asio/detail/winrt_utils.hpp | 2 +- include/asio/detail/winsock_init.hpp | 2 +- include/asio/detail/work_dispatcher.hpp | 7 +- include/asio/detail/wrapped_handler.hpp | 2 +- include/asio/dispatch.hpp | 10 +- include/asio/error.hpp | 2 +- include/asio/error_code.hpp | 2 +- include/asio/execution_context.hpp | 5 +- include/asio/executor.hpp | 2 +- include/asio/executor_work_guard.hpp | 4 +- include/asio/experimental.hpp | 22 - include/asio/experimental/co_spawn.hpp | 226 -- include/asio/experimental/impl/co_spawn.hpp | 876 ------ include/asio/experimental/impl/detached.hpp | 91 - include/asio/generic/basic_endpoint.hpp | 2 +- include/asio/generic/datagram_protocol.hpp | 2 +- include/asio/generic/detail/endpoint.hpp | 2 +- include/asio/generic/detail/impl/endpoint.ipp | 2 +- include/asio/generic/raw_protocol.hpp | 2 +- include/asio/generic/seq_packet_protocol.hpp | 2 +- include/asio/generic/stream_protocol.hpp | 2 +- include/asio/handler_alloc_hook.hpp | 2 +- include/asio/handler_continuation_hook.hpp | 2 +- include/asio/handler_invoke_hook.hpp | 2 +- include/asio/handler_type.hpp | 50 - include/asio/high_resolution_timer.hpp | 2 +- include/asio/impl/awaitable.hpp | 422 +++ include/asio/impl/buffered_read_stream.hpp | 107 +- include/asio/impl/buffered_write_stream.hpp | 99 +- include/asio/impl/co_spawn.hpp | 138 + include/asio/impl/compose.hpp | 419 +++ include/asio/impl/connect.hpp | 410 ++- include/asio/impl/defer.hpp | 58 +- include/asio/impl/detached.hpp | 130 + include/asio/impl/dispatch.hpp | 59 +- include/asio/impl/error.ipp | 2 +- include/asio/impl/error_code.ipp | 2 +- include/asio/impl/execution_context.hpp | 14 +- include/asio/impl/execution_context.ipp | 2 +- include/asio/impl/executor.hpp | 31 +- include/asio/impl/executor.ipp | 2 +- include/asio/impl/handler_alloc_hook.ipp | 2 +- include/asio/impl/io_context.hpp | 130 +- include/asio/impl/io_context.ipp | 7 +- include/asio/impl/post.hpp | 58 +- include/asio/impl/read.hpp | 570 +++- include/asio/impl/read_at.hpp | 147 +- include/asio/impl/read_until.hpp | 2362 ++++++++++++++--- .../impl/redirect_error.hpp | 174 +- include/asio/impl/serial_port_base.hpp | 2 +- include/asio/impl/serial_port_base.ipp | 2 +- include/asio/impl/spawn.hpp | 47 +- include/asio/impl/src.cpp | 2 +- include/asio/impl/src.hpp | 2 +- include/asio/impl/system_context.hpp | 2 +- include/asio/impl/system_context.ipp | 11 +- include/asio/impl/system_executor.hpp | 2 +- include/asio/impl/thread_pool.hpp | 2 +- include/asio/impl/thread_pool.ipp | 21 +- include/asio/impl/use_awaitable.hpp | 276 ++ include/asio/impl/use_future.hpp | 52 +- include/asio/impl/write.hpp | 520 +++- include/asio/impl/write_at.hpp | 146 +- include/asio/io_context.hpp | 16 +- include/asio/io_context_strand.hpp | 92 +- include/asio/io_service.hpp | 2 +- include/asio/io_service_strand.hpp | 2 +- include/asio/ip/address.hpp | 62 +- include/asio/ip/address_v4.hpp | 58 +- include/asio/ip/address_v4_iterator.hpp | 2 +- include/asio/ip/address_v4_range.hpp | 2 +- include/asio/ip/address_v6.hpp | 77 +- include/asio/ip/address_v6_iterator.hpp | 2 +- include/asio/ip/address_v6_range.hpp | 2 +- include/asio/ip/bad_address_cast.hpp | 2 +- include/asio/ip/basic_endpoint.hpp | 47 +- include/asio/ip/basic_resolver.hpp | 306 +-- include/asio/ip/basic_resolver_entry.hpp | 2 +- include/asio/ip/basic_resolver_iterator.hpp | 2 +- include/asio/ip/basic_resolver_query.hpp | 2 +- include/asio/ip/basic_resolver_results.hpp | 2 +- include/asio/ip/detail/endpoint.hpp | 40 +- include/asio/ip/detail/impl/endpoint.ipp | 20 +- include/asio/ip/detail/socket_option.hpp | 2 +- include/asio/ip/host_name.hpp | 2 +- include/asio/ip/icmp.hpp | 2 +- include/asio/ip/impl/address.hpp | 2 +- include/asio/ip/impl/address.ipp | 41 +- include/asio/ip/impl/address_v4.hpp | 2 +- include/asio/ip/impl/address_v4.ipp | 22 +- include/asio/ip/impl/address_v6.hpp | 2 +- include/asio/ip/impl/address_v6.ipp | 52 +- include/asio/ip/impl/basic_endpoint.hpp | 2 +- include/asio/ip/impl/host_name.ipp | 2 +- include/asio/ip/impl/network_v4.hpp | 2 +- include/asio/ip/impl/network_v4.ipp | 2 +- include/asio/ip/impl/network_v6.hpp | 2 +- include/asio/ip/impl/network_v6.ipp | 2 +- include/asio/ip/multicast.hpp | 16 +- include/asio/ip/network_v4.hpp | 2 +- include/asio/ip/network_v6.hpp | 2 +- include/asio/ip/resolver_base.hpp | 2 +- include/asio/ip/resolver_query_base.hpp | 2 +- include/asio/ip/resolver_service.hpp | 200 -- include/asio/ip/tcp.hpp | 6 +- include/asio/ip/udp.hpp | 2 +- include/asio/ip/unicast.hpp | 6 +- include/asio/ip/v6_only.hpp | 6 +- include/asio/is_executor.hpp | 2 +- include/asio/is_read_buffered.hpp | 2 +- include/asio/is_write_buffered.hpp | 2 +- include/asio/local/basic_endpoint.hpp | 10 +- include/asio/local/connect_pair.hpp | 33 +- include/asio/local/datagram_protocol.hpp | 2 +- include/asio/local/detail/endpoint.hpp | 8 +- include/asio/local/detail/impl/endpoint.ipp | 9 +- include/asio/local/stream_protocol.hpp | 2 +- include/asio/packaged_task.hpp | 2 +- include/asio/placeholders.hpp | 2 +- include/asio/posix/basic_descriptor.hpp | 228 +- .../asio/posix/basic_stream_descriptor.hpp | 192 +- include/asio/posix/descriptor.hpp | 617 +---- include/asio/posix/descriptor_base.hpp | 4 +- include/asio/posix/stream_descriptor.hpp | 329 +-- .../asio/posix/stream_descriptor_service.hpp | 279 -- include/asio/post.hpp | 8 +- include/asio/raw_socket_service.hpp | 466 ---- include/asio/read.hpp | 370 ++- include/asio/read_at.hpp | 26 +- include/asio/read_until.hpp | 1775 ++++++++++--- .../{experimental => }/redirect_error.hpp | 19 +- include/asio/seq_packet_socket_service.hpp | 416 --- include/asio/serial_port.hpp | 739 +----- include/asio/serial_port_base.hpp | 2 +- include/asio/serial_port_service.hpp | 249 -- include/asio/signal_set.hpp | 425 +-- include/asio/signal_set_service.hpp | 142 - include/asio/socket_acceptor_service.hpp | 372 --- include/asio/socket_base.hpp | 52 +- include/asio/spawn.hpp | 2 +- include/asio/ssl.hpp | 2 +- include/asio/ssl/context.hpp | 2 +- include/asio/ssl/context_base.hpp | 2 +- .../asio/ssl/detail/buffered_handshake_op.hpp | 2 +- include/asio/ssl/detail/engine.hpp | 2 +- include/asio/ssl/detail/handshake_op.hpp | 2 +- include/asio/ssl/detail/impl/engine.ipp | 28 +- include/asio/ssl/detail/impl/openssl_init.ipp | 2 +- include/asio/ssl/detail/io.hpp | 17 +- include/asio/ssl/detail/openssl_init.hpp | 2 +- include/asio/ssl/detail/openssl_types.hpp | 2 +- include/asio/ssl/detail/password_callback.hpp | 2 +- include/asio/ssl/detail/read_op.hpp | 2 +- include/asio/ssl/detail/shutdown_op.hpp | 14 +- include/asio/ssl/detail/stream_core.hpp | 9 +- include/asio/ssl/detail/verify_callback.hpp | 2 +- include/asio/ssl/detail/write_op.hpp | 2 +- include/asio/ssl/error.hpp | 26 +- include/asio/ssl/impl/context.hpp | 2 +- include/asio/ssl/impl/context.ipp | 2 +- include/asio/ssl/impl/error.ipp | 4 +- .../asio/ssl/impl/rfc2818_verification.ipp | 2 +- include/asio/ssl/impl/src.hpp | 2 +- include/asio/ssl/rfc2818_verification.hpp | 2 +- include/asio/ssl/stream.hpp | 188 +- include/asio/ssl/stream_base.hpp | 2 +- include/asio/ssl/verify_context.hpp | 2 +- include/asio/ssl/verify_mode.hpp | 2 +- include/asio/steady_timer.hpp | 2 +- include/asio/strand.hpp | 29 +- include/asio/stream_socket_service.hpp | 412 --- include/asio/streambuf.hpp | 2 +- include/asio/system_context.hpp | 5 +- include/asio/system_error.hpp | 2 +- include/asio/system_executor.hpp | 2 +- include/asio/system_timer.hpp | 2 +- include/asio/this_coro.hpp | 45 + include/asio/thread.hpp | 2 +- include/asio/thread_pool.hpp | 5 +- include/asio/time_traits.hpp | 2 +- include/asio/ts/buffer.hpp | 2 +- include/asio/ts/executor.hpp | 3 +- include/asio/ts/internet.hpp | 2 +- include/asio/ts/io_context.hpp | 2 +- include/asio/ts/net.hpp | 2 +- include/asio/ts/netfwd.hpp | 74 +- include/asio/ts/socket.hpp | 2 +- include/asio/ts/timer.hpp | 2 +- include/asio/unyield.hpp | 2 +- include/asio/use_awaitable.hpp | 71 + include/asio/use_future.hpp | 2 +- include/asio/uses_executor.hpp | 2 +- include/asio/version.hpp | 4 +- include/asio/wait_traits.hpp | 2 +- include/asio/waitable_timer_service.hpp | 210 -- include/asio/windows/basic_handle.hpp | 273 -- include/asio/windows/basic_object_handle.hpp | 292 +- .../asio/windows/basic_overlapped_handle.hpp | 353 +++ .../windows/basic_random_access_handle.hpp | 167 +- include/asio/windows/basic_stream_handle.hpp | 170 +- include/asio/windows/object_handle.hpp | 349 +-- .../asio/windows/object_handle_service.hpp | 183 -- include/asio/windows/overlapped_handle.hpp | 300 +-- include/asio/windows/overlapped_ptr.hpp | 45 +- include/asio/windows/random_access_handle.hpp | 347 +-- .../windows/random_access_handle_service.hpp | 214 -- include/asio/windows/stream_handle.hpp | 331 +-- .../asio/windows/stream_handle_service.hpp | 210 -- include/asio/write.hpp | 363 ++- include/asio/write_at.hpp | 26 +- include/asio/yield.hpp | 2 +- src/asio.cpp | 2 +- 500 files changed, 15450 insertions(+), 15282 deletions(-) create mode 100755 build/_clear.sh create mode 100644 include/asio/awaitable.hpp create mode 100644 include/asio/co_spawn.hpp create mode 100644 include/asio/compose.hpp delete mode 100644 include/asio/datagram_socket_service.hpp delete mode 100644 include/asio/deadline_timer_service.hpp rename include/asio/{experimental => }/detached.hpp (67%) create mode 100644 include/asio/detail/executor_function.hpp create mode 100644 include/asio/detail/io_object_executor.hpp create mode 100644 include/asio/detail/io_object_impl.hpp create mode 100644 include/asio/detail/non_const_lvalue.hpp delete mode 100644 include/asio/experimental.hpp delete mode 100644 include/asio/experimental/co_spawn.hpp delete mode 100644 include/asio/experimental/impl/co_spawn.hpp delete mode 100644 include/asio/experimental/impl/detached.hpp delete mode 100644 include/asio/handler_type.hpp create mode 100644 include/asio/impl/awaitable.hpp create mode 100644 include/asio/impl/co_spawn.hpp create mode 100644 include/asio/impl/compose.hpp create mode 100644 include/asio/impl/detached.hpp rename include/asio/{experimental => }/impl/redirect_error.hpp (57%) create mode 100644 include/asio/impl/use_awaitable.hpp delete mode 100644 include/asio/ip/resolver_service.hpp delete mode 100644 include/asio/posix/stream_descriptor_service.hpp delete mode 100644 include/asio/raw_socket_service.hpp rename include/asio/{experimental => }/redirect_error.hpp (76%) delete mode 100644 include/asio/seq_packet_socket_service.hpp delete mode 100644 include/asio/serial_port_service.hpp delete mode 100644 include/asio/signal_set_service.hpp delete mode 100644 include/asio/socket_acceptor_service.hpp delete mode 100644 include/asio/stream_socket_service.hpp create mode 100644 include/asio/this_coro.hpp create mode 100644 include/asio/use_awaitable.hpp delete mode 100644 include/asio/waitable_timer_service.hpp delete mode 100644 include/asio/windows/basic_handle.hpp create mode 100644 include/asio/windows/basic_overlapped_handle.hpp delete mode 100644 include/asio/windows/object_handle_service.hpp delete mode 100644 include/asio/windows/random_access_handle_service.hpp delete mode 100644 include/asio/windows/stream_handle_service.hpp diff --git a/backup/asio_ssl.cpp b/backup/asio_ssl.cpp index dd3d6d3..d232f00 100644 --- a/backup/asio_ssl.cpp +++ b/backup/asio_ssl.cpp @@ -2,7 +2,7 @@ // asio_ssl.cpp // ~~~~~~~~~~~~ // -// Copyright (c) 2003-2018 Christopher M. Kohlhoff (chris at kohlhoff dot com) +// Copyright (c) 2003-2019 Christopher M. Kohlhoff (chris at kohlhoff dot com) // // Distributed under the Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) diff --git a/build/.gitignore b/build/.gitignore index 86d0cb2..c4ea5d0 100644 --- a/build/.gitignore +++ b/build/.gitignore @@ -1,4 +1,5 @@ # Ignore everything in this directory * # Except this file -!.gitignore \ No newline at end of file +!.gitignore +!_clear.sh diff --git a/build/_clear.sh b/build/_clear.sh new file mode 100755 index 0000000..cd1b5e3 --- /dev/null +++ b/build/_clear.sh @@ -0,0 +1,2 @@ +rm -rf CMakeCache.txt CMakeFiles/ cmake_install.cmake libasio.a Makefile + diff --git a/include/asio.hpp b/include/asio.hpp index 3356df0..4b47b92 100644 --- a/include/asio.hpp +++ b/include/asio.hpp @@ -2,7 +2,7 @@ // asio.hpp // ~~~~~~~~ // -// Copyright (c) 2003-2018 Christopher M. Kohlhoff (chris at kohlhoff dot com) +// Copyright (c) 2003-2019 Christopher M. Kohlhoff (chris at kohlhoff dot com) // // Distributed under the Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) @@ -18,6 +18,7 @@ #include "asio/associated_allocator.hpp" #include "asio/associated_executor.hpp" #include "asio/async_result.hpp" +#include "asio/awaitable.hpp" #include "asio/basic_datagram_socket.hpp" #include "asio/basic_deadline_timer.hpp" #include "asio/basic_io_object.hpp" @@ -25,6 +26,7 @@ #include "asio/basic_seq_packet_socket.hpp" #include "asio/basic_serial_port.hpp" #include "asio/basic_signal_set.hpp" +#include "asio/basic_socket.hpp" #include "asio/basic_socket_acceptor.hpp" #include "asio/basic_socket_iostream.hpp" #include "asio/basic_socket_streambuf.hpp" @@ -40,13 +42,14 @@ #include "asio/buffered_write_stream_fwd.hpp" #include "asio/buffered_write_stream.hpp" #include "asio/buffers_iterator.hpp" +#include "asio/co_spawn.hpp" #include "asio/completion_condition.hpp" +#include "asio/compose.hpp" #include "asio/connect.hpp" #include "asio/coroutine.hpp" -#include "asio/datagram_socket_service.hpp" -#include "asio/deadline_timer_service.hpp" #include "asio/deadline_timer.hpp" #include "asio/defer.hpp" +#include "asio/detached.hpp" #include "asio/dispatch.hpp" #include "asio/error.hpp" #include "asio/error_code.hpp" @@ -61,7 +64,6 @@ #include "asio/handler_alloc_hook.hpp" #include "asio/handler_continuation_hook.hpp" #include "asio/handler_invoke_hook.hpp" -#include "asio/handler_type.hpp" #include "asio/high_resolution_timer.hpp" #include "asio/io_context.hpp" #include "asio/io_context_strand.hpp" @@ -74,6 +76,8 @@ #include "asio/ip/address_v6.hpp" #include "asio/ip/address_v6_iterator.hpp" #include "asio/ip/address_v6_range.hpp" +#include "asio/ip/network_v4.hpp" +#include "asio/ip/network_v6.hpp" #include "asio/ip/bad_address_cast.hpp" #include "asio/ip/basic_endpoint.hpp" #include "asio/ip/basic_resolver.hpp" @@ -85,7 +89,6 @@ #include "asio/ip/multicast.hpp" #include "asio/ip/resolver_base.hpp" #include "asio/ip/resolver_query_base.hpp" -#include "asio/ip/resolver_service.hpp" #include "asio/ip/tcp.hpp" #include "asio/ip/udp.hpp" #include "asio/ip/unicast.hpp" @@ -104,48 +107,40 @@ #include "asio/posix/descriptor.hpp" #include "asio/posix/descriptor_base.hpp" #include "asio/posix/stream_descriptor.hpp" -#include "asio/posix/stream_descriptor_service.hpp" #include "asio/post.hpp" -#include "asio/raw_socket_service.hpp" #include "asio/read.hpp" #include "asio/read_at.hpp" #include "asio/read_until.hpp" -#include "asio/seq_packet_socket_service.hpp" +#include "asio/redirect_error.hpp" #include "asio/serial_port.hpp" #include "asio/serial_port_base.hpp" -#include "asio/serial_port_service.hpp" #include "asio/signal_set.hpp" -#include "asio/signal_set_service.hpp" -#include "asio/socket_acceptor_service.hpp" #include "asio/socket_base.hpp" #include "asio/steady_timer.hpp" #include "asio/strand.hpp" -#include "asio/stream_socket_service.hpp" #include "asio/streambuf.hpp" #include "asio/system_context.hpp" #include "asio/system_error.hpp" #include "asio/system_executor.hpp" #include "asio/system_timer.hpp" +#include "asio/this_coro.hpp" #include "asio/thread.hpp" #include "asio/thread_pool.hpp" #include "asio/time_traits.hpp" +#include "asio/use_awaitable.hpp" #include "asio/use_future.hpp" #include "asio/uses_executor.hpp" #include "asio/version.hpp" #include "asio/wait_traits.hpp" -#include "asio/waitable_timer_service.hpp" -#include "asio/windows/basic_handle.hpp" #include "asio/windows/basic_object_handle.hpp" +#include "asio/windows/basic_overlapped_handle.hpp" #include "asio/windows/basic_random_access_handle.hpp" #include "asio/windows/basic_stream_handle.hpp" #include "asio/windows/object_handle.hpp" -#include "asio/windows/object_handle_service.hpp" #include "asio/windows/overlapped_handle.hpp" #include "asio/windows/overlapped_ptr.hpp" #include "asio/windows/random_access_handle.hpp" -#include "asio/windows/random_access_handle_service.hpp" #include "asio/windows/stream_handle.hpp" -#include "asio/windows/stream_handle_service.hpp" #include "asio/write.hpp" #include "asio/write_at.hpp" diff --git a/include/asio/associated_allocator.hpp b/include/asio/associated_allocator.hpp index 8b488bb..02d6538 100644 --- a/include/asio/associated_allocator.hpp +++ b/include/asio/associated_allocator.hpp @@ -2,7 +2,7 @@ // associated_allocator.hpp // ~~~~~~~~~~~~~~~~~~~~~~~~ // -// Copyright (c) 2003-2018 Christopher M. Kohlhoff (chris at kohlhoff dot com) +// Copyright (c) 2003-2019 Christopher M. Kohlhoff (chris at kohlhoff dot com) // // Distributed under the Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) diff --git a/include/asio/associated_executor.hpp b/include/asio/associated_executor.hpp index 4c5c207..7fe6af5 100644 --- a/include/asio/associated_executor.hpp +++ b/include/asio/associated_executor.hpp @@ -2,7 +2,7 @@ // associated_executor.hpp // ~~~~~~~~~~~~~~~~~~~~~~~ // -// Copyright (c) 2003-2018 Christopher M. Kohlhoff (chris at kohlhoff dot com) +// Copyright (c) 2003-2019 Christopher M. Kohlhoff (chris at kohlhoff dot com) // // Distributed under the Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) diff --git a/include/asio/async_result.hpp b/include/asio/async_result.hpp index 18acdf2..6113c59 100644 --- a/include/asio/async_result.hpp +++ b/include/asio/async_result.hpp @@ -2,7 +2,7 @@ // async_result.hpp // ~~~~~~~~~~~~~~~~ // -// Copyright (c) 2003-2018 Christopher M. Kohlhoff (chris at kohlhoff dot com) +// Copyright (c) 2003-2019 Christopher M. Kohlhoff (chris at kohlhoff dot com) // // Distributed under the Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) @@ -17,7 +17,7 @@ #include "asio/detail/config.hpp" #include "asio/detail/type_traits.hpp" -#include "asio/handler_type.hpp" +#include "asio/detail/variadic_templates.hpp" #include "asio/detail/push_options.hpp" @@ -41,30 +41,15 @@ namespace asio { * The primary template assumes that the CompletionToken is the completion * handler. */ -#if defined(ASIO_NO_DEPRECATED) || defined(GENERATING_DOCUMENTATION) template -#else // defined(ASIO_NO_DEPRECATED) || defined(GENERATING_DOCUMENTATION) -template -#endif // defined(ASIO_NO_DEPRECATED) || defined(GENERATING_DOCUMENTATION) class async_result { public: -#if defined(ASIO_NO_DEPRECATED) || defined(GENERATING_DOCUMENTATION) /// The concrete completion handler type for the specific signature. typedef CompletionToken completion_handler_type; /// The return type of the initiating function. typedef void return_type; -#else // defined(ASIO_NO_DEPRECATED) || defined(GENERATING_DOCUMENTATION) - // For backward compatibility, determine the concrete completion handler type - // by using the legacy handler_type trait. - typedef typename handler_type::type - completion_handler_type; - - // For backward compatibility, determine the initiating function return type - // using the legacy single-parameter version of async_result. - typedef typename async_result::type return_type; -#endif // defined(ASIO_NO_DEPRECATED) || defined(GENERATING_DOCUMENTATION) /// Construct an async result from a given handler. /** @@ -73,11 +58,6 @@ class async_result * then returned from the initiating function. */ explicit async_result(completion_handler_type& h) -#if defined(ASIO_NO_DEPRECATED) || defined(GENERATING_DOCUMENTATION) - // No data members to initialise. -#else // defined(ASIO_NO_DEPRECATED) || defined(GENERATING_DOCUMENTATION) - : legacy_result_(h) -#endif // defined(ASIO_NO_DEPRECATED) || defined(GENERATING_DOCUMENTATION) { (void)h; } @@ -85,55 +65,59 @@ class async_result /// Obtain the value to be returned from the initiating function. return_type get() { -#if defined(ASIO_NO_DEPRECATED) || defined(GENERATING_DOCUMENTATION) - // Nothing to do. -#else // defined(ASIO_NO_DEPRECATED) || defined(GENERATING_DOCUMENTATION) - return legacy_result_.get(); -#endif // defined(ASIO_NO_DEPRECATED) || defined(GENERATING_DOCUMENTATION) } -private: - async_result(const async_result&) ASIO_DELETED; - async_result& operator=(const async_result&) ASIO_DELETED; +#if defined(ASIO_HAS_VARIADIC_TEMPLATES) \ + || defined(GENERATING_DOCUMENTATION) -#if defined(ASIO_NO_DEPRECATED) || defined(GENERATING_DOCUMENTATION) - // No data members. -#else // defined(ASIO_NO_DEPRECATED) || defined(GENERATING_DOCUMENTATION) - async_result legacy_result_; -#endif // defined(ASIO_NO_DEPRECATED) || defined(GENERATING_DOCUMENTATION) -}; - -#if !defined(ASIO_NO_DEPRECATED) - -/// (Deprecated: Use two-parameter version of async_result.) An interface for -/// customising the behaviour of an initiating function. -/** - * This template may be specialised for user-defined handler types. - */ -template -class async_result -{ -public: - /// The return type of the initiating function. - typedef void type; - - /// Construct an async result from a given handler. - /** - * When using a specalised async_result, the constructor has an opportunity - * to initialise some state associated with the handler, which is then - * returned from the initiating function. - */ - explicit async_result(Handler&) + /// Initiate the asynchronous operation that will produce the result, and + /// obtain the value to be returned from the initiating function. + template + static return_type initiate( + ASIO_MOVE_ARG(Initiation) initiation, + ASIO_MOVE_ARG(RawCompletionToken) token, + ASIO_MOVE_ARG(Args)... args) { + ASIO_MOVE_CAST(Initiation)(initiation)( + ASIO_MOVE_CAST(RawCompletionToken)(token), + ASIO_MOVE_CAST(Args)(args)...); } - /// Obtain the value to be returned from the initiating function. - type get() +#else // defined(ASIO_HAS_VARIADIC_TEMPLATES) + // || defined(GENERATING_DOCUMENTATION) + + template + static return_type initiate( + ASIO_MOVE_ARG(Initiation) initiation, + ASIO_MOVE_ARG(RawCompletionToken) token) { + ASIO_MOVE_CAST(Initiation)(initiation)( + ASIO_MOVE_CAST(RawCompletionToken)(token)); } -}; -#endif // !defined(ASIO_NO_DEPRECATED) +#define ASIO_PRIVATE_INITIATE_DEF(n) \ + template \ + static return_type initiate( \ + ASIO_MOVE_ARG(Initiation) initiation, \ + ASIO_MOVE_ARG(RawCompletionToken) token, \ + ASIO_VARIADIC_MOVE_PARAMS(n)) \ + { \ + ASIO_MOVE_CAST(Initiation)(initiation)( \ + ASIO_MOVE_CAST(RawCompletionToken)(token), \ + ASIO_VARIADIC_MOVE_ARGS(n)); \ + } \ + /**/ + ASIO_VARIADIC_GENERATE(ASIO_PRIVATE_INITIATE_DEF) +#undef ASIO_PRIVATE_INITIATE_DEF + +#endif // defined(ASIO_HAS_VARIADIC_TEMPLATES) + // || defined(GENERATING_DOCUMENTATION) + +private: + async_result(const async_result&) ASIO_DELETED; + async_result& operator=(const async_result&) ASIO_DELETED; +}; /// Helper template to deduce the handler type from a CompletionToken, capture /// a local copy of the handler, and then create an async_result for the @@ -194,10 +178,40 @@ struct async_result_helper { }; -} // namespace detail -} // namespace asio +struct async_result_memfns_base +{ + void initiate(); +}; -#include "asio/detail/pop_options.hpp" +template +struct async_result_memfns_derived + : T, async_result_memfns_base +{ +}; + +template +struct async_result_memfns_check +{ +}; + +template +char (&async_result_initiate_memfn_helper(...))[2]; + +template +char async_result_initiate_memfn_helper( + async_result_memfns_check< + void (async_result_memfns_base::*)(), + &async_result_memfns_derived::initiate>*); + +template +struct async_result_has_initiate_memfn + : integral_constant::type, Signature> + >(0)) != 1> +{ +}; + +} // namespace detail #if defined(GENERATING_DOCUMENTATION) # define ASIO_INITFN_RESULT_TYPE(ct, sig) \ @@ -218,4 +232,125 @@ struct async_result_helper typename ::asio::decay::type, sig>::completion_handler_type #endif +#if defined(GENERATING_DOCUMENTATION) + +template +ASIO_INITFN_RESULT_TYPE(CompletionToken, Signature) +async_initiate(ASIO_MOVE_ARG(Initiation) initiation, + ASIO_NONDEDUCED_MOVE_ARG(CompletionToken), + ASIO_MOVE_ARG(Args)... args); + +#elif defined(ASIO_HAS_VARIADIC_TEMPLATES) + +template +inline typename enable_if< + detail::async_result_has_initiate_memfn::value, + ASIO_INITFN_RESULT_TYPE(CompletionToken, Signature)>::type +async_initiate(ASIO_MOVE_ARG(Initiation) initiation, + ASIO_NONDEDUCED_MOVE_ARG(CompletionToken) token, + ASIO_MOVE_ARG(Args)... args) +{ + return async_result::type, + Signature>::initiate(ASIO_MOVE_CAST(Initiation)(initiation), + ASIO_MOVE_CAST(CompletionToken)(token), + ASIO_MOVE_CAST(Args)(args)...); +} + +template +inline typename enable_if< + !detail::async_result_has_initiate_memfn::value, + ASIO_INITFN_RESULT_TYPE(CompletionToken, Signature)>::type +async_initiate(ASIO_MOVE_ARG(Initiation) initiation, + ASIO_NONDEDUCED_MOVE_ARG(CompletionToken) token, + ASIO_MOVE_ARG(Args)... args) +{ + async_completion completion(token); + + ASIO_MOVE_CAST(Initiation)(initiation)( + ASIO_MOVE_CAST(ASIO_HANDLER_TYPE(CompletionToken, + Signature))(completion.completion_handler), + ASIO_MOVE_CAST(Args)(args)...); + + return completion.result.get(); +} + +#else // defined(ASIO_HAS_VARIADIC_TEMPLATES) + +template +inline typename enable_if< + detail::async_result_has_initiate_memfn::value, + ASIO_INITFN_RESULT_TYPE(CompletionToken, Signature)>::type +async_initiate(ASIO_MOVE_ARG(Initiation) initiation, + ASIO_NONDEDUCED_MOVE_ARG(CompletionToken) token) +{ + return async_result::type, + Signature>::initiate(ASIO_MOVE_CAST(Initiation)(initiation), + ASIO_MOVE_CAST(CompletionToken)(token)); +} + +template +inline typename enable_if< + !detail::async_result_has_initiate_memfn::value, + ASIO_INITFN_RESULT_TYPE(CompletionToken, Signature)>::type +async_initiate(ASIO_MOVE_ARG(Initiation) initiation, + ASIO_NONDEDUCED_MOVE_ARG(CompletionToken) token) +{ + async_completion completion(token); + + ASIO_MOVE_CAST(Initiation)(initiation)( + ASIO_MOVE_CAST(ASIO_HANDLER_TYPE(CompletionToken, + Signature))(completion.completion_handler)); + + return completion.result.get(); +} + +#define ASIO_PRIVATE_INITIATE_DEF(n) \ + template \ + inline typename enable_if< \ + detail::async_result_has_initiate_memfn< \ + CompletionToken, Signature>::value, \ + ASIO_INITFN_RESULT_TYPE(CompletionToken, Signature)>::type \ + async_initiate(ASIO_MOVE_ARG(Initiation) initiation, \ + ASIO_NONDEDUCED_MOVE_ARG(CompletionToken) token, \ + ASIO_VARIADIC_MOVE_PARAMS(n)) \ + { \ + return async_result::type, \ + Signature>::initiate(ASIO_MOVE_CAST(Initiation)(initiation), \ + ASIO_MOVE_CAST(CompletionToken)(token), \ + ASIO_VARIADIC_MOVE_ARGS(n)); \ + } \ + \ + template \ + inline typename enable_if< \ + !detail::async_result_has_initiate_memfn< \ + CompletionToken, Signature>::value, \ + ASIO_INITFN_RESULT_TYPE(CompletionToken, Signature)>::type \ + async_initiate(ASIO_MOVE_ARG(Initiation) initiation, \ + ASIO_NONDEDUCED_MOVE_ARG(CompletionToken) token, \ + ASIO_VARIADIC_MOVE_PARAMS(n)) \ + { \ + async_completion completion(token); \ + \ + ASIO_MOVE_CAST(Initiation)(initiation)( \ + ASIO_MOVE_CAST(ASIO_HANDLER_TYPE(CompletionToken, \ + Signature))(completion.completion_handler), \ + ASIO_VARIADIC_MOVE_ARGS(n)); \ + \ + return completion.result.get(); \ + } \ + /**/ + ASIO_VARIADIC_GENERATE(ASIO_PRIVATE_INITIATE_DEF) +#undef ASIO_PRIVATE_INITIATE_DEF + +#endif // defined(ASIO_HAS_VARIADIC_TEMPLATES) + +} // namespace asio + +#include "asio/detail/pop_options.hpp" + #endif // ASIO_ASYNC_RESULT_HPP diff --git a/include/asio/awaitable.hpp b/include/asio/awaitable.hpp new file mode 100644 index 0000000..890fb67 --- /dev/null +++ b/include/asio/awaitable.hpp @@ -0,0 +1,123 @@ +// +// awaitable.hpp +// ~~~~~~~~~~~~~ +// +// Copyright (c) 2003-2019 Christopher M. Kohlhoff (chris at kohlhoff dot com) +// +// Distributed under the Boost Software License, Version 1.0. (See accompanying +// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) +// + +#ifndef ASIO_AWAITABLE_HPP +#define ASIO_AWAITABLE_HPP + +#if defined(_MSC_VER) && (_MSC_VER >= 1200) +# pragma once +#endif // defined(_MSC_VER) && (_MSC_VER >= 1200) + +#include "asio/detail/config.hpp" + +#if defined(ASIO_HAS_CO_AWAIT) || defined(GENERATING_DOCUMENTATION) + +#include +#include "asio/executor.hpp" + +#include "asio/detail/push_options.hpp" + +namespace asio { +namespace detail { + +using std::experimental::coroutine_handle; +using std::experimental::suspend_always; + +template class awaitable_thread; +template class awaitable_frame; + +} // namespace detail + +/// The return type of a coroutine or asynchronous operation. +template +class awaitable +{ +public: + /// The type of the awaited value. + typedef T value_type; + + /// The executor type that will be used for the coroutine. + typedef Executor executor_type; + + /// Default constructor. + constexpr awaitable() noexcept + : frame_(nullptr) + { + } + + /// Move constructor. + awaitable(awaitable&& other) noexcept + : frame_(std::exchange(other.frame_, nullptr)) + { + } + + /// Destructor + ~awaitable() + { + if (frame_) + frame_->destroy(); + } + + /// Checks if the awaitable refers to a future result. + bool valid() const noexcept + { + return !!frame_; + } + +#if !defined(GENERATING_DOCUMENTATION) + + // Support for co_await keyword. + bool await_ready() const noexcept + { + return false; + } + + // Support for co_await keyword. + template + void await_suspend( + detail::coroutine_handle> h) + { + frame_->push_frame(&h.promise()); + } + + // Support for co_await keyword. + T await_resume() + { + return frame_->get(); + } + +#endif // !defined(GENERATING_DOCUMENTATION) + +private: + template friend class detail::awaitable_thread; + template friend class detail::awaitable_frame; + + // Not copy constructible or copy assignable. + awaitable(const awaitable&) = delete; + awaitable& operator=(const awaitable&) = delete; + + // Construct the awaitable from a coroutine's frame object. + explicit awaitable(detail::awaitable_frame* a) + : frame_(a) + { + } + + detail::awaitable_frame* frame_; +}; + +} // namespace asio + +#include "asio/detail/pop_options.hpp" + +#include "asio/impl/awaitable.hpp" + +#endif // defined(ASIO_HAS_CO_AWAIT) || defined(GENERATING_DOCUMENTATION) + +#endif // ASIO_AWAITABLE_HPP diff --git a/include/asio/basic_datagram_socket.hpp b/include/asio/basic_datagram_socket.hpp index 346cc35..bbd4885 100644 --- a/include/asio/basic_datagram_socket.hpp +++ b/include/asio/basic_datagram_socket.hpp @@ -2,7 +2,7 @@ // basic_datagram_socket.hpp // ~~~~~~~~~~~~~~~~~~~~~~~~~ // -// Copyright (c) 2003-2018 Christopher M. Kohlhoff (chris at kohlhoff dot com) +// Copyright (c) 2003-2019 Christopher M. Kohlhoff (chris at kohlhoff dot com) // // Distributed under the Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) @@ -19,18 +19,24 @@ #include #include "asio/basic_socket.hpp" #include "asio/detail/handler_type_requirements.hpp" +#include "asio/detail/non_const_lvalue.hpp" #include "asio/detail/throw_error.hpp" #include "asio/detail/type_traits.hpp" #include "asio/error.hpp" -#if defined(ASIO_ENABLE_OLD_SERVICES) -# include "asio/datagram_socket_service.hpp" -#endif // defined(ASIO_ENABLE_OLD_SERVICES) - #include "asio/detail/push_options.hpp" namespace asio { +#if !defined(ASIO_BASIC_DATAGRAM_SOCKET_FWD_DECL) +#define ASIO_BASIC_DATAGRAM_SOCKET_FWD_DECL + +// Forward declaration with defaulted arguments. +template +class basic_datagram_socket; + +#endif // !defined(ASIO_BASIC_DATAGRAM_SOCKET_FWD_DECL) + /// Provides datagram-oriented socket functionality. /** * The basic_datagram_socket class template provides asynchronous and blocking @@ -40,18 +46,28 @@ namespace asio { * @e Distinct @e objects: Safe.@n * @e Shared @e objects: Unsafe. */ -template )> +template class basic_datagram_socket - : public basic_socket + : public basic_socket { public: + /// The type of the executor associated with the object. + typedef Executor executor_type; + + /// Rebinds the socket type to another executor. + template + struct rebind_executor + { + /// The socket type when rebound to the specified executor. + typedef basic_datagram_socket other; + }; + /// The native representation of a socket. #if defined(GENERATING_DOCUMENTATION) typedef implementation_defined native_handle_type; #else - typedef typename basic_socket< - Protocol ASIO_SVC_TARG>::native_handle_type native_handle_type; + typedef typename basic_socket::native_handle_type native_handle_type; #endif /// The protocol type. @@ -65,12 +81,29 @@ class basic_datagram_socket * This constructor creates a datagram socket without opening it. The open() * function must be called before data can be sent or received on the socket. * - * @param io_context The io_context object that the datagram socket will use - * to dispatch handlers for any asynchronous operations performed on the - * socket. + * @param ex The I/O executor that the socket will use, by default, to + * dispatch handlers for any asynchronous operations performed on the socket. + */ + explicit basic_datagram_socket(const executor_type& ex) + : basic_socket(ex) + { + } + + /// Construct a basic_datagram_socket without opening it. + /** + * This constructor creates a datagram socket without opening it. The open() + * function must be called before data can be sent or received on the socket. + * + * @param context An execution context which provides the I/O executor that + * the socket will use, by default, to dispatch handlers for any asynchronous + * operations performed on the socket. */ - explicit basic_datagram_socket(asio::io_context& io_context) - : basic_socket(io_context) + template + explicit basic_datagram_socket(ExecutionContext& context, + typename enable_if< + is_convertible::value + >::type* = 0) + : basic_socket(context) { } @@ -78,17 +111,37 @@ class basic_datagram_socket /** * This constructor creates and opens a datagram socket. * - * @param io_context The io_context object that the datagram socket will use - * to dispatch handlers for any asynchronous operations performed on the - * socket. + * @param ex The I/O executor that the socket will use, by default, to + * dispatch handlers for any asynchronous operations performed on the socket. + * + * @param protocol An object specifying protocol parameters to be used. + * + * @throws asio::system_error Thrown on failure. + */ + basic_datagram_socket(const executor_type& ex, const protocol_type& protocol) + : basic_socket(ex, protocol) + { + } + + /// Construct and open a basic_datagram_socket. + /** + * This constructor creates and opens a datagram socket. + * + * @param context An execution context which provides the I/O executor that + * the socket will use, by default, to dispatch handlers for any asynchronous + * operations performed on the socket. * * @param protocol An object specifying protocol parameters to be used. * * @throws asio::system_error Thrown on failure. */ - basic_datagram_socket(asio::io_context& io_context, - const protocol_type& protocol) - : basic_socket(io_context, protocol) + template + basic_datagram_socket(ExecutionContext& context, + const protocol_type& protocol, + typename enable_if< + is_convertible::value + >::type* = 0) + : basic_socket(context, protocol) { } @@ -99,18 +152,42 @@ class basic_datagram_socket * to the specified endpoint on the local machine. The protocol used is the * protocol associated with the given endpoint. * - * @param io_context The io_context object that the datagram socket will use - * to dispatch handlers for any asynchronous operations performed on the - * socket. + * @param ex The I/O executor that the socket will use, by default, to + * dispatch handlers for any asynchronous operations performed on the socket. + * + * @param endpoint An endpoint on the local machine to which the datagram + * socket will be bound. + * + * @throws asio::system_error Thrown on failure. + */ + basic_datagram_socket(const executor_type& ex, const endpoint_type& endpoint) + : basic_socket(ex, endpoint) + { + } + + /// Construct a basic_datagram_socket, opening it and binding it to the given + /// local endpoint. + /** + * This constructor creates a datagram socket and automatically opens it bound + * to the specified endpoint on the local machine. The protocol used is the + * protocol associated with the given endpoint. + * + * @param context An execution context which provides the I/O executor that + * the socket will use, by default, to dispatch handlers for any asynchronous + * operations performed on the socket. * * @param endpoint An endpoint on the local machine to which the datagram * socket will be bound. * * @throws asio::system_error Thrown on failure. */ - basic_datagram_socket(asio::io_context& io_context, - const endpoint_type& endpoint) - : basic_socket(io_context, endpoint) + template + basic_datagram_socket(ExecutionContext& context, + const endpoint_type& endpoint, + typename enable_if< + is_convertible::value + >::type* = 0) + : basic_socket(context, endpoint) { } @@ -119,9 +196,8 @@ class basic_datagram_socket * This constructor creates a datagram socket object to hold an existing * native socket. * - * @param io_context The io_context object that the datagram socket will use - * to dispatch handlers for any asynchronous operations performed on the - * socket. + * @param ex The I/O executor that the socket will use, by default, to + * dispatch handlers for any asynchronous operations performed on the socket. * * @param protocol An object specifying protocol parameters to be used. * @@ -129,10 +205,34 @@ class basic_datagram_socket * * @throws asio::system_error Thrown on failure. */ - basic_datagram_socket(asio::io_context& io_context, + basic_datagram_socket(const executor_type& ex, const protocol_type& protocol, const native_handle_type& native_socket) - : basic_socket( - io_context, protocol, native_socket) + : basic_socket(ex, protocol, native_socket) + { + } + + /// Construct a basic_datagram_socket on an existing native socket. + /** + * This constructor creates a datagram socket object to hold an existing + * native socket. + * + * @param context An execution context which provides the I/O executor that + * the socket will use, by default, to dispatch handlers for any asynchronous + * operations performed on the socket. + * + * @param protocol An object specifying protocol parameters to be used. + * + * @param native_socket The new underlying socket implementation. + * + * @throws asio::system_error Thrown on failure. + */ + template + basic_datagram_socket(ExecutionContext& context, + const protocol_type& protocol, const native_handle_type& native_socket, + typename enable_if< + is_convertible::value + >::type* = 0) + : basic_socket(context, protocol, native_socket) { } @@ -145,10 +245,11 @@ class basic_datagram_socket * will occur. * * @note Following the move, the moved-from object is in the same state as if - * constructed using the @c basic_datagram_socket(io_context&) constructor. + * constructed using the @c basic_datagram_socket(const executor_type&) + * constructor. */ basic_datagram_socket(basic_datagram_socket&& other) - : basic_socket(std::move(other)) + : basic_socket(std::move(other)) { } @@ -161,11 +262,12 @@ class basic_datagram_socket * will occur. * * @note Following the move, the moved-from object is in the same state as if - * constructed using the @c basic_datagram_socket(io_context&) constructor. + * constructed using the @c basic_datagram_socket(const executor_type&) + * constructor. */ basic_datagram_socket& operator=(basic_datagram_socket&& other) { - basic_socket::operator=(std::move(other)); + basic_socket::operator=(std::move(other)); return *this; } @@ -178,13 +280,16 @@ class basic_datagram_socket * will occur. * * @note Following the move, the moved-from object is in the same state as if - * constructed using the @c basic_datagram_socket(io_context&) constructor. + * constructed using the @c basic_datagram_socket(const executor_type&) + * constructor. */ - template - basic_datagram_socket( - basic_datagram_socket&& other, - typename enable_if::value>::type* = 0) - : basic_socket(std::move(other)) + template + basic_datagram_socket(basic_datagram_socket&& other, + typename enable_if< + is_convertible::value + && is_convertible::value + >::type* = 0) + : basic_socket(std::move(other)) { } @@ -198,14 +303,17 @@ class basic_datagram_socket * will occur. * * @note Following the move, the moved-from object is in the same state as if - * constructed using the @c basic_datagram_socket(io_context&) constructor. + * constructed using the @c basic_datagram_socket(const executor_type&) + * constructor. */ - template - typename enable_if::value, - basic_datagram_socket>::type& operator=( - basic_datagram_socket&& other) + template + typename enable_if< + is_convertible::value + && is_convertible::value, + basic_datagram_socket& + >::type operator=(basic_datagram_socket&& other) { - basic_socket::operator=(std::move(other)); + basic_socket::operator=(std::move(other)); return *this; } #endif // defined(ASIO_HAS_MOVE) || defined(GENERATING_DOCUMENTATION) @@ -245,8 +353,8 @@ class basic_datagram_socket std::size_t send(const ConstBufferSequence& buffers) { asio::error_code ec; - std::size_t s = this->get_service().send( - this->get_implementation(), buffers, 0, ec); + std::size_t s = this->impl_.get_service().send( + this->impl_.get_implementation(), buffers, 0, ec); asio::detail::throw_error(ec, "send"); return s; } @@ -273,8 +381,8 @@ class basic_datagram_socket socket_base::message_flags flags) { asio::error_code ec; - std::size_t s = this->get_service().send( - this->get_implementation(), buffers, flags, ec); + std::size_t s = this->impl_.get_service().send( + this->impl_.get_implementation(), buffers, flags, ec); asio::detail::throw_error(ec, "send"); return s; } @@ -300,8 +408,8 @@ class basic_datagram_socket std::size_t send(const ConstBufferSequence& buffers, socket_base::message_flags flags, asio::error_code& ec) { - return this->get_service().send( - this->get_implementation(), buffers, flags, ec); + return this->impl_.get_service().send( + this->impl_.get_implementation(), buffers, flags, ec); } /// Start an asynchronous send on a connected socket. @@ -322,9 +430,9 @@ class basic_datagram_socket * std::size_t bytes_transferred // Number of bytes sent. * ); @endcode * Regardless of whether the asynchronous operation completes immediately or - * not, the handler will not be invoked from within this function. Invocation - * of the handler will be performed in a manner equivalent to using - * asio::io_context::post(). + * not, the handler will not be invoked from within this function. On + * immediate completion, invocation of the handler will be performed in a + * manner equivalent to using asio::post(). * * @note The async_send operation can only be used with a connected socket. * Use the async_send_to function to send data on an unconnected datagram @@ -345,22 +453,10 @@ class basic_datagram_socket async_send(const ConstBufferSequence& buffers, ASIO_MOVE_ARG(WriteHandler) handler) { - // If you get an error on the following line it means that your handler does - // not meet the documented type requirements for a WriteHandler. - ASIO_WRITE_HANDLER_CHECK(WriteHandler, handler) type_check; - -#if defined(ASIO_ENABLE_OLD_SERVICES) - return this->get_service().async_send(this->get_implementation(), - buffers, 0, ASIO_MOVE_CAST(WriteHandler)(handler)); -#else // defined(ASIO_ENABLE_OLD_SERVICES) - async_completion init(handler); - - this->get_service().async_send(this->get_implementation(), - buffers, 0, init.completion_handler); - - return init.result.get(); -#endif // defined(ASIO_ENABLE_OLD_SERVICES) + return async_initiate( + initiate_async_send(), handler, this, + buffers, socket_base::message_flags(0)); } /// Start an asynchronous send on a connected socket. @@ -383,9 +479,9 @@ class basic_datagram_socket * std::size_t bytes_transferred // Number of bytes sent. * ); @endcode * Regardless of whether the asynchronous operation completes immediately or - * not, the handler will not be invoked from within this function. Invocation - * of the handler will be performed in a manner equivalent to using - * asio::io_context::post(). + * not, the handler will not be invoked from within this function. On + * immediate completion, invocation of the handler will be performed in a + * manner equivalent to using asio::post(). * * @note The async_send operation can only be used with a connected socket. * Use the async_send_to function to send data on an unconnected datagram @@ -398,22 +494,9 @@ class basic_datagram_socket socket_base::message_flags flags, ASIO_MOVE_ARG(WriteHandler) handler) { - // If you get an error on the following line it means that your handler does - // not meet the documented type requirements for a WriteHandler. - ASIO_WRITE_HANDLER_CHECK(WriteHandler, handler) type_check; - -#if defined(ASIO_ENABLE_OLD_SERVICES) - return this->get_service().async_send(this->get_implementation(), - buffers, flags, ASIO_MOVE_CAST(WriteHandler)(handler)); -#else // defined(ASIO_ENABLE_OLD_SERVICES) - async_completion init(handler); - - this->get_service().async_send(this->get_implementation(), - buffers, flags, init.completion_handler); - - return init.result.get(); -#endif // defined(ASIO_ENABLE_OLD_SERVICES) + return async_initiate( + initiate_async_send(), handler, this, buffers, flags); } /// Send a datagram to the specified endpoint. @@ -446,8 +529,8 @@ class basic_datagram_socket const endpoint_type& destination) { asio::error_code ec; - std::size_t s = this->get_service().send_to( - this->get_implementation(), buffers, destination, 0, ec); + std::size_t s = this->impl_.get_service().send_to( + this->impl_.get_implementation(), buffers, destination, 0, ec); asio::detail::throw_error(ec, "send_to"); return s; } @@ -473,8 +556,8 @@ class basic_datagram_socket const endpoint_type& destination, socket_base::message_flags flags) { asio::error_code ec; - std::size_t s = this->get_service().send_to( - this->get_implementation(), buffers, destination, flags, ec); + std::size_t s = this->impl_.get_service().send_to( + this->impl_.get_implementation(), buffers, destination, flags, ec); asio::detail::throw_error(ec, "send_to"); return s; } @@ -500,7 +583,7 @@ class basic_datagram_socket const endpoint_type& destination, socket_base::message_flags flags, asio::error_code& ec) { - return this->get_service().send_to(this->get_implementation(), + return this->impl_.get_service().send_to(this->impl_.get_implementation(), buffers, destination, flags, ec); } @@ -525,9 +608,9 @@ class basic_datagram_socket * std::size_t bytes_transferred // Number of bytes sent. * ); @endcode * Regardless of whether the asynchronous operation completes immediately or - * not, the handler will not be invoked from within this function. Invocation - * of the handler will be performed in a manner equivalent to using - * asio::io_context::post(). + * not, the handler will not be invoked from within this function. On + * immediate completion, invocation of the handler will be performed in a + * manner equivalent to using asio::post(). * * @par Example * To send a single data buffer use the @ref buffer function as follows: @@ -548,24 +631,10 @@ class basic_datagram_socket const endpoint_type& destination, ASIO_MOVE_ARG(WriteHandler) handler) { - // If you get an error on the following line it means that your handler does - // not meet the documented type requirements for a WriteHandler. - ASIO_WRITE_HANDLER_CHECK(WriteHandler, handler) type_check; - -#if defined(ASIO_ENABLE_OLD_SERVICES) - return this->get_service().async_send_to( - this->get_implementation(), buffers, destination, 0, - ASIO_MOVE_CAST(WriteHandler)(handler)); -#else // defined(ASIO_ENABLE_OLD_SERVICES) - async_completion init(handler); - - this->get_service().async_send_to( - this->get_implementation(), buffers, destination, 0, - init.completion_handler); - - return init.result.get(); -#endif // defined(ASIO_ENABLE_OLD_SERVICES) + return async_initiate( + initiate_async_send_to(), handler, this, buffers, + destination, socket_base::message_flags(0)); } /// Start an asynchronous send. @@ -591,9 +660,9 @@ class basic_datagram_socket * std::size_t bytes_transferred // Number of bytes sent. * ); @endcode * Regardless of whether the asynchronous operation completes immediately or - * not, the handler will not be invoked from within this function. Invocation - * of the handler will be performed in a manner equivalent to using - * asio::io_context::post(). + * not, the handler will not be invoked from within this function. On + * immediate completion, invocation of the handler will be performed in a + * manner equivalent to using asio::post(). */ template ASIO_INITFN_RESULT_TYPE(WriteHandler, @@ -602,24 +671,9 @@ class basic_datagram_socket const endpoint_type& destination, socket_base::message_flags flags, ASIO_MOVE_ARG(WriteHandler) handler) { - // If you get an error on the following line it means that your handler does - // not meet the documented type requirements for a WriteHandler. - ASIO_WRITE_HANDLER_CHECK(WriteHandler, handler) type_check; - -#if defined(ASIO_ENABLE_OLD_SERVICES) - return this->get_service().async_send_to( - this->get_implementation(), buffers, destination, flags, - ASIO_MOVE_CAST(WriteHandler)(handler)); -#else // defined(ASIO_ENABLE_OLD_SERVICES) - async_completion init(handler); - - this->get_service().async_send_to( - this->get_implementation(), buffers, destination, flags, - init.completion_handler); - - return init.result.get(); -#endif // defined(ASIO_ENABLE_OLD_SERVICES) + return async_initiate( + initiate_async_send_to(), handler, this, buffers, destination, flags); } /// Receive some data on a connected socket. @@ -650,8 +704,8 @@ class basic_datagram_socket std::size_t receive(const MutableBufferSequence& buffers) { asio::error_code ec; - std::size_t s = this->get_service().receive( - this->get_implementation(), buffers, 0, ec); + std::size_t s = this->impl_.get_service().receive( + this->impl_.get_implementation(), buffers, 0, ec); asio::detail::throw_error(ec, "receive"); return s; } @@ -679,8 +733,8 @@ class basic_datagram_socket socket_base::message_flags flags) { asio::error_code ec; - std::size_t s = this->get_service().receive( - this->get_implementation(), buffers, flags, ec); + std::size_t s = this->impl_.get_service().receive( + this->impl_.get_implementation(), buffers, flags, ec); asio::detail::throw_error(ec, "receive"); return s; } @@ -707,8 +761,8 @@ class basic_datagram_socket std::size_t receive(const MutableBufferSequence& buffers, socket_base::message_flags flags, asio::error_code& ec) { - return this->get_service().receive( - this->get_implementation(), buffers, flags, ec); + return this->impl_.get_service().receive( + this->impl_.get_implementation(), buffers, flags, ec); } /// Start an asynchronous receive on a connected socket. @@ -729,9 +783,9 @@ class basic_datagram_socket * std::size_t bytes_transferred // Number of bytes received. * ); @endcode * Regardless of whether the asynchronous operation completes immediately or - * not, the handler will not be invoked from within this function. Invocation - * of the handler will be performed in a manner equivalent to using - * asio::io_context::post(). + * not, the handler will not be invoked from within this function. On + * immediate completion, invocation of the handler will be performed in a + * manner equivalent to using asio::post(). * * @note The async_receive operation can only be used with a connected socket. * Use the async_receive_from function to receive data on an unconnected @@ -753,22 +807,10 @@ class basic_datagram_socket async_receive(const MutableBufferSequence& buffers, ASIO_MOVE_ARG(ReadHandler) handler) { - // If you get an error on the following line it means that your handler does - // not meet the documented type requirements for a ReadHandler. - ASIO_READ_HANDLER_CHECK(ReadHandler, handler) type_check; - -#if defined(ASIO_ENABLE_OLD_SERVICES) - return this->get_service().async_receive(this->get_implementation(), - buffers, 0, ASIO_MOVE_CAST(ReadHandler)(handler)); -#else // defined(ASIO_ENABLE_OLD_SERVICES) - async_completion init(handler); - - this->get_service().async_receive(this->get_implementation(), - buffers, 0, init.completion_handler); - - return init.result.get(); -#endif // defined(ASIO_ENABLE_OLD_SERVICES) + return async_initiate( + initiate_async_receive(), handler, this, + buffers, socket_base::message_flags(0)); } /// Start an asynchronous receive on a connected socket. @@ -791,9 +833,9 @@ class basic_datagram_socket * std::size_t bytes_transferred // Number of bytes received. * ); @endcode * Regardless of whether the asynchronous operation completes immediately or - * not, the handler will not be invoked from within this function. Invocation - * of the handler will be performed in a manner equivalent to using - * asio::io_context::post(). + * not, the handler will not be invoked from within this function. On + * immediate completion, invocation of the handler will be performed in a + * manner equivalent to using asio::post(). * * @note The async_receive operation can only be used with a connected socket. * Use the async_receive_from function to receive data on an unconnected @@ -806,22 +848,9 @@ class basic_datagram_socket socket_base::message_flags flags, ASIO_MOVE_ARG(ReadHandler) handler) { - // If you get an error on the following line it means that your handler does - // not meet the documented type requirements for a ReadHandler. - ASIO_READ_HANDLER_CHECK(ReadHandler, handler) type_check; - -#if defined(ASIO_ENABLE_OLD_SERVICES) - return this->get_service().async_receive(this->get_implementation(), - buffers, flags, ASIO_MOVE_CAST(ReadHandler)(handler)); -#else // defined(ASIO_ENABLE_OLD_SERVICES) - async_completion init(handler); - - this->get_service().async_receive(this->get_implementation(), - buffers, flags, init.completion_handler); - - return init.result.get(); -#endif // defined(ASIO_ENABLE_OLD_SERVICES) + return async_initiate( + initiate_async_receive(), handler, this, buffers, flags); } /// Receive a datagram with the endpoint of the sender. @@ -855,8 +884,8 @@ class basic_datagram_socket endpoint_type& sender_endpoint) { asio::error_code ec; - std::size_t s = this->get_service().receive_from( - this->get_implementation(), buffers, sender_endpoint, 0, ec); + std::size_t s = this->impl_.get_service().receive_from( + this->impl_.get_implementation(), buffers, sender_endpoint, 0, ec); asio::detail::throw_error(ec, "receive_from"); return s; } @@ -882,8 +911,8 @@ class basic_datagram_socket endpoint_type& sender_endpoint, socket_base::message_flags flags) { asio::error_code ec; - std::size_t s = this->get_service().receive_from( - this->get_implementation(), buffers, sender_endpoint, flags, ec); + std::size_t s = this->impl_.get_service().receive_from( + this->impl_.get_implementation(), buffers, sender_endpoint, flags, ec); asio::detail::throw_error(ec, "receive_from"); return s; } @@ -909,8 +938,8 @@ class basic_datagram_socket endpoint_type& sender_endpoint, socket_base::message_flags flags, asio::error_code& ec) { - return this->get_service().receive_from(this->get_implementation(), - buffers, sender_endpoint, flags, ec); + return this->impl_.get_service().receive_from( + this->impl_.get_implementation(), buffers, sender_endpoint, flags, ec); } /// Start an asynchronous receive. @@ -936,9 +965,9 @@ class basic_datagram_socket * std::size_t bytes_transferred // Number of bytes received. * ); @endcode * Regardless of whether the asynchronous operation completes immediately or - * not, the handler will not be invoked from within this function. Invocation - * of the handler will be performed in a manner equivalent to using - * asio::io_context::post(). + * not, the handler will not be invoked from within this function. On + * immediate completion, invocation of the handler will be performed in a + * manner equivalent to using asio::post(). * * @par Example * To receive into a single data buffer use the @ref buffer function as @@ -956,24 +985,10 @@ class basic_datagram_socket endpoint_type& sender_endpoint, ASIO_MOVE_ARG(ReadHandler) handler) { - // If you get an error on the following line it means that your handler does - // not meet the documented type requirements for a ReadHandler. - ASIO_READ_HANDLER_CHECK(ReadHandler, handler) type_check; - -#if defined(ASIO_ENABLE_OLD_SERVICES) - return this->get_service().async_receive_from( - this->get_implementation(), buffers, sender_endpoint, 0, - ASIO_MOVE_CAST(ReadHandler)(handler)); -#else // defined(ASIO_ENABLE_OLD_SERVICES) - async_completion init(handler); - - this->get_service().async_receive_from( - this->get_implementation(), buffers, sender_endpoint, 0, - init.completion_handler); - - return init.result.get(); -#endif // defined(ASIO_ENABLE_OLD_SERVICES) + return async_initiate( + initiate_async_receive_from(), handler, this, buffers, + &sender_endpoint, socket_base::message_flags(0)); } /// Start an asynchronous receive. @@ -1001,9 +1016,9 @@ class basic_datagram_socket * std::size_t bytes_transferred // Number of bytes received. * ); @endcode * Regardless of whether the asynchronous operation completes immediately or - * not, the handler will not be invoked from within this function. Invocation - * of the handler will be performed in a manner equivalent to using - * asio::io_context::post(). + * not, the handler will not be invoked from within this function. On + * immediate completion, invocation of the handler will be performed in a + * manner equivalent to using asio::post(). */ template ASIO_INITFN_RESULT_TYPE(ReadHandler, @@ -1012,25 +1027,85 @@ class basic_datagram_socket endpoint_type& sender_endpoint, socket_base::message_flags flags, ASIO_MOVE_ARG(ReadHandler) handler) { - // If you get an error on the following line it means that your handler does - // not meet the documented type requirements for a ReadHandler. - ASIO_READ_HANDLER_CHECK(ReadHandler, handler) type_check; + return async_initiate( + initiate_async_receive_from(), handler, + this, buffers, &sender_endpoint, flags); + } -#if defined(ASIO_ENABLE_OLD_SERVICES) - return this->get_service().async_receive_from( - this->get_implementation(), buffers, sender_endpoint, flags, - ASIO_MOVE_CAST(ReadHandler)(handler)); -#else // defined(ASIO_ENABLE_OLD_SERVICES) - async_completion init(handler); +private: + struct initiate_async_send + { + template + void operator()(ASIO_MOVE_ARG(WriteHandler) handler, + basic_datagram_socket* self, const ConstBufferSequence& buffers, + socket_base::message_flags flags) const + { + // If you get an error on the following line it means that your handler + // does not meet the documented type requirements for a WriteHandler. + ASIO_WRITE_HANDLER_CHECK(WriteHandler, handler) type_check; - this->get_service().async_receive_from( - this->get_implementation(), buffers, sender_endpoint, flags, - init.completion_handler); + detail::non_const_lvalue handler2(handler); + self->impl_.get_service().async_send( + self->impl_.get_implementation(), buffers, flags, + handler2.value, self->impl_.get_implementation_executor()); + } + }; - return init.result.get(); -#endif // defined(ASIO_ENABLE_OLD_SERVICES) - } + struct initiate_async_send_to + { + template + void operator()(ASIO_MOVE_ARG(WriteHandler) handler, + basic_datagram_socket* self, const ConstBufferSequence& buffers, + const endpoint_type& destination, + socket_base::message_flags flags) const + { + // If you get an error on the following line it means that your handler + // does not meet the documented type requirements for a WriteHandler. + ASIO_WRITE_HANDLER_CHECK(WriteHandler, handler) type_check; + + detail::non_const_lvalue handler2(handler); + self->impl_.get_service().async_send_to( + self->impl_.get_implementation(), buffers, destination, flags, + handler2.value, self->impl_.get_implementation_executor()); + } + }; + + struct initiate_async_receive + { + template + void operator()(ASIO_MOVE_ARG(ReadHandler) handler, + basic_datagram_socket* self, const MutableBufferSequence& buffers, + socket_base::message_flags flags) const + { + // If you get an error on the following line it means that your handler + // does not meet the documented type requirements for a ReadHandler. + ASIO_READ_HANDLER_CHECK(ReadHandler, handler) type_check; + + detail::non_const_lvalue handler2(handler); + self->impl_.get_service().async_receive( + self->impl_.get_implementation(), buffers, flags, + handler2.value, self->impl_.get_implementation_executor()); + } + }; + + struct initiate_async_receive_from + { + template + void operator()(ASIO_MOVE_ARG(ReadHandler) handler, + basic_datagram_socket* self, const MutableBufferSequence& buffers, + endpoint_type* sender_endpoint, socket_base::message_flags flags) const + { + // If you get an error on the following line it means that your handler + // does not meet the documented type requirements for a ReadHandler. + ASIO_READ_HANDLER_CHECK(ReadHandler, handler) type_check; + + detail::non_const_lvalue handler2(handler); + self->impl_.get_service().async_receive_from( + self->impl_.get_implementation(), buffers, *sender_endpoint, flags, + handler2.value, self->impl_.get_implementation_executor()); + } + }; }; } // namespace asio diff --git a/include/asio/basic_deadline_timer.hpp b/include/asio/basic_deadline_timer.hpp index 5b20066..d8100a7 100644 --- a/include/asio/basic_deadline_timer.hpp +++ b/include/asio/basic_deadline_timer.hpp @@ -2,7 +2,7 @@ // basic_deadline_timer.hpp // ~~~~~~~~~~~~~~~~~~~~~~~~ // -// Copyright (c) 2003-2018 Christopher M. Kohlhoff (chris at kohlhoff dot com) +// Copyright (c) 2003-2019 Christopher M. Kohlhoff (chris at kohlhoff dot com) // // Distributed under the Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) @@ -21,19 +21,16 @@ || defined(GENERATING_DOCUMENTATION) #include -#include "asio/basic_io_object.hpp" +#include "asio/detail/deadline_timer_service.hpp" #include "asio/detail/handler_type_requirements.hpp" +#include "asio/detail/io_object_impl.hpp" +#include "asio/detail/non_const_lvalue.hpp" #include "asio/detail/throw_error.hpp" #include "asio/error.hpp" +#include "asio/execution_context.hpp" +#include "asio/executor.hpp" #include "asio/time_traits.hpp" -#if defined(ASIO_ENABLE_OLD_SERVICES) -# include "asio/deadline_timer_service.hpp" -#else // defined(ASIO_ENABLE_OLD_SERVICES) -# include "asio/detail/deadline_timer_service.hpp" -# define ASIO_SVC_T detail::deadline_timer_service -#endif // defined(ASIO_ENABLE_OLD_SERVICES) - #include "asio/detail/push_options.hpp" namespace asio { @@ -57,7 +54,7 @@ namespace asio { * Performing a blocking wait: * @code * // Construct a timer without setting an expiry time. - * asio::deadline_timer timer(io_context); + * asio::deadline_timer timer(my_context); * * // Set an expiry time relative to now. * timer.expires_from_now(boost::posix_time::seconds(5)); @@ -80,7 +77,7 @@ namespace asio { * ... * * // Construct a timer with an absolute expiry time. - * asio::deadline_timer timer(io_context, + * asio::deadline_timer timer(my_context, * boost::posix_time::time_from_string("2005-12-07 23:59:59.000")); * * // Start an asynchronous wait. @@ -127,14 +124,13 @@ namespace asio { * it contains the value asio::error::operation_aborted. */ template - ASIO_SVC_TPARAM_DEF2(= deadline_timer_service)> + typename TimeTraits = asio::time_traits