mirror of
https://github.com/deneraraujo/OpenVPNAdapter.git
synced 2026-04-24 00:00:05 +08:00
Merge commit '1dd2f4645226bd269f2407d5ed431acc3f66e7a6' as 'Sources/ASIO'
This commit is contained in:
@@ -0,0 +1,11 @@
|
||||
.deps
|
||||
.dirstamp
|
||||
*.o
|
||||
*.obj
|
||||
*.exe
|
||||
*_test
|
||||
*.ilk
|
||||
*.manifest
|
||||
*.pdb
|
||||
*.tds
|
||||
*.winmd
|
||||
@@ -0,0 +1,429 @@
|
||||
AUTOMAKE_OPTIONS = subdir-objects
|
||||
|
||||
if SEPARATE_COMPILATION
|
||||
noinst_LIBRARIES = libasio.a
|
||||
libasio_a_SOURCES = ../asio.cpp
|
||||
if HAVE_OPENSSL
|
||||
libasio_a_SOURCES += ../asio_ssl.cpp
|
||||
endif
|
||||
LDADD = libasio.a
|
||||
endif
|
||||
|
||||
check_PROGRAMS = \
|
||||
unit/associated_allocator \
|
||||
unit/associated_executor \
|
||||
unit/async_result \
|
||||
unit/awaitable \
|
||||
unit/basic_datagram_socket \
|
||||
unit/basic_deadline_timer \
|
||||
unit/basic_raw_socket \
|
||||
unit/basic_seq_packet_socket \
|
||||
unit/basic_serial_port \
|
||||
unit/basic_signal_set \
|
||||
unit/basic_socket \
|
||||
unit/basic_socket_acceptor \
|
||||
unit/basic_stream_socket \
|
||||
unit/basic_streambuf \
|
||||
unit/basic_waitable_timer \
|
||||
unit/bind_executor \
|
||||
unit/buffered_read_stream \
|
||||
unit/buffered_stream \
|
||||
unit/buffered_write_stream \
|
||||
unit/buffer \
|
||||
unit/buffers_iterator \
|
||||
unit/co_spawn \
|
||||
unit/completion_condition \
|
||||
unit/compose \
|
||||
unit/connect \
|
||||
unit/coroutine \
|
||||
unit/deadline_timer \
|
||||
unit/defer \
|
||||
unit/detached \
|
||||
unit/dispatch \
|
||||
unit/error \
|
||||
unit/execution_context \
|
||||
unit/executor \
|
||||
unit/executor_work_guard \
|
||||
unit/generic/basic_endpoint \
|
||||
unit/generic/datagram_protocol \
|
||||
unit/generic/raw_protocol \
|
||||
unit/generic/seq_packet_protocol \
|
||||
unit/generic/stream_protocol \
|
||||
unit/high_resolution_timer \
|
||||
unit/io_context \
|
||||
unit/io_context_strand \
|
||||
unit/ip/address \
|
||||
unit/ip/address_v4 \
|
||||
unit/ip/address_v4_iterator \
|
||||
unit/ip/address_v4_range \
|
||||
unit/ip/address_v6 \
|
||||
unit/ip/address_v6_iterator \
|
||||
unit/ip/address_v6_range \
|
||||
unit/ip/basic_endpoint \
|
||||
unit/ip/basic_resolver \
|
||||
unit/ip/basic_resolver_entry \
|
||||
unit/ip/basic_resolver_iterator \
|
||||
unit/ip/basic_resolver_query \
|
||||
unit/ip/host_name \
|
||||
unit/ip/icmp \
|
||||
unit/ip/multicast \
|
||||
unit/ip/network_v4 \
|
||||
unit/ip/network_v6 \
|
||||
unit/ip/resolver_query_base \
|
||||
unit/ip/tcp \
|
||||
unit/ip/udp \
|
||||
unit/ip/unicast \
|
||||
unit/ip/v6_only \
|
||||
unit/is_read_buffered \
|
||||
unit/is_write_buffered \
|
||||
unit/local/basic_endpoint \
|
||||
unit/local/connect_pair \
|
||||
unit/local/datagram_protocol \
|
||||
unit/local/stream_protocol \
|
||||
unit/packaged_task \
|
||||
unit/placeholders \
|
||||
unit/posix/basic_descriptor \
|
||||
unit/posix/basic_stream_descriptor \
|
||||
unit/posix/descriptor \
|
||||
unit/posix/descriptor_base \
|
||||
unit/posix/stream_descriptor \
|
||||
unit/post \
|
||||
unit/read \
|
||||
unit/read_at \
|
||||
unit/read_until \
|
||||
unit/redirect_error \
|
||||
unit/serial_port \
|
||||
unit/serial_port_base \
|
||||
unit/signal_set \
|
||||
unit/socket_base \
|
||||
unit/steady_timer \
|
||||
unit/strand \
|
||||
unit/streambuf \
|
||||
unit/system_context \
|
||||
unit/system_executor \
|
||||
unit/system_timer \
|
||||
unit/this_coro \
|
||||
unit/thread \
|
||||
unit/time_traits \
|
||||
unit/ts/buffer \
|
||||
unit/ts/executor \
|
||||
unit/ts/internet \
|
||||
unit/ts/io_context \
|
||||
unit/ts/net \
|
||||
unit/ts/netfwd \
|
||||
unit/ts/socket \
|
||||
unit/ts/timer \
|
||||
unit/use_awaitable \
|
||||
unit/use_future \
|
||||
unit/uses_executor \
|
||||
unit/wait_traits \
|
||||
unit/windows/basic_object_handle \
|
||||
unit/windows/basic_overlapped_handle \
|
||||
unit/windows/basic_random_access_handle \
|
||||
unit/windows/basic_stream_handle \
|
||||
unit/windows/object_handle \
|
||||
unit/windows/overlapped_handle \
|
||||
unit/windows/overlapped_ptr \
|
||||
unit/windows/random_access_handle \
|
||||
unit/windows/stream_handle \
|
||||
unit/write \
|
||||
unit/write_at
|
||||
|
||||
if !STANDALONE
|
||||
noinst_PROGRAMS = \
|
||||
latency/tcp_client \
|
||||
latency/tcp_server \
|
||||
latency/udp_client \
|
||||
latency/udp_server \
|
||||
performance/client \
|
||||
performance/server
|
||||
endif
|
||||
|
||||
if HAVE_OPENSSL
|
||||
check_PROGRAMS += \
|
||||
unit/ssl/context_base \
|
||||
unit/ssl/context \
|
||||
unit/ssl/error \
|
||||
unit/ssl/rfc2818_verification \
|
||||
unit/ssl/stream_base \
|
||||
unit/ssl/stream
|
||||
endif
|
||||
|
||||
TESTS = \
|
||||
unit/associated_allocator \
|
||||
unit/associated_executor \
|
||||
unit/async_result \
|
||||
unit/awaitable \
|
||||
unit/basic_datagram_socket \
|
||||
unit/basic_deadline_timer \
|
||||
unit/basic_raw_socket \
|
||||
unit/basic_seq_packet_socket \
|
||||
unit/basic_serial_port \
|
||||
unit/basic_signal_set \
|
||||
unit/basic_socket \
|
||||
unit/basic_socket_acceptor \
|
||||
unit/basic_stream_socket \
|
||||
unit/basic_streambuf \
|
||||
unit/basic_waitable_timer \
|
||||
unit/bind_executor \
|
||||
unit/buffered_read_stream \
|
||||
unit/buffered_stream \
|
||||
unit/buffered_write_stream \
|
||||
unit/buffer \
|
||||
unit/buffers_iterator \
|
||||
unit/co_spawn \
|
||||
unit/completion_condition \
|
||||
unit/compose \
|
||||
unit/connect \
|
||||
unit/deadline_timer \
|
||||
unit/defer \
|
||||
unit/detached \
|
||||
unit/dispatch \
|
||||
unit/error \
|
||||
unit/execution_context \
|
||||
unit/executor \
|
||||
unit/executor_work_guard \
|
||||
unit/high_resolution_timer \
|
||||
unit/io_context \
|
||||
unit/io_context_strand \
|
||||
unit/ip/address \
|
||||
unit/ip/address_v4 \
|
||||
unit/ip/address_v4_iterator \
|
||||
unit/ip/address_v4_range \
|
||||
unit/ip/address_v6 \
|
||||
unit/ip/address_v6_iterator \
|
||||
unit/ip/address_v6_range \
|
||||
unit/ip/basic_endpoint \
|
||||
unit/ip/basic_resolver \
|
||||
unit/ip/basic_resolver_entry \
|
||||
unit/ip/basic_resolver_iterator \
|
||||
unit/ip/basic_resolver_query \
|
||||
unit/ip/host_name \
|
||||
unit/ip/icmp \
|
||||
unit/ip/multicast \
|
||||
unit/ip/network_v4 \
|
||||
unit/ip/network_v6 \
|
||||
unit/ip/resolver_query_base \
|
||||
unit/ip/tcp \
|
||||
unit/ip/udp \
|
||||
unit/ip/unicast \
|
||||
unit/ip/v6_only \
|
||||
unit/is_read_buffered \
|
||||
unit/is_write_buffered \
|
||||
unit/local/basic_endpoint \
|
||||
unit/local/connect_pair \
|
||||
unit/local/datagram_protocol \
|
||||
unit/local/stream_protocol \
|
||||
unit/packaged_task \
|
||||
unit/placeholders \
|
||||
unit/posix/basic_descriptor\
|
||||
unit/posix/basic_stream_descriptor\
|
||||
unit/posix/descriptor\
|
||||
unit/posix/descriptor_base \
|
||||
unit/posix/stream_descriptor \
|
||||
unit/post \
|
||||
unit/read \
|
||||
unit/read_at \
|
||||
unit/read_until \
|
||||
unit/redirect_error \
|
||||
unit/serial_port \
|
||||
unit/serial_port_base \
|
||||
unit/signal_set \
|
||||
unit/socket_base \
|
||||
unit/steady_timer \
|
||||
unit/strand \
|
||||
unit/streambuf \
|
||||
unit/system_context \
|
||||
unit/system_executor \
|
||||
unit/system_timer \
|
||||
unit/this_coro \
|
||||
unit/thread \
|
||||
unit/time_traits \
|
||||
unit/ts/buffer \
|
||||
unit/ts/executor \
|
||||
unit/ts/internet \
|
||||
unit/ts/io_context \
|
||||
unit/ts/net \
|
||||
unit/ts/netfwd \
|
||||
unit/ts/socket \
|
||||
unit/ts/timer \
|
||||
unit/use_awaitable \
|
||||
unit/use_future \
|
||||
unit/uses_executor \
|
||||
unit/wait_traits \
|
||||
unit/windows/basic_object_handle \
|
||||
unit/windows/basic_overlapped_handle \
|
||||
unit/windows/basic_random_access_handle \
|
||||
unit/windows/basic_stream_handle \
|
||||
unit/windows/object_handle \
|
||||
unit/windows/overlapped_handle \
|
||||
unit/windows/overlapped_ptr \
|
||||
unit/windows/random_access_handle \
|
||||
unit/windows/stream_handle \
|
||||
unit/write \
|
||||
unit/write_at
|
||||
|
||||
if HAVE_OPENSSL
|
||||
TESTS += \
|
||||
unit/ssl/context_base \
|
||||
unit/ssl/context \
|
||||
unit/ssl/error \
|
||||
unit/ssl/rfc2818_verification \
|
||||
unit/ssl/stream_base \
|
||||
unit/ssl/stream
|
||||
endif
|
||||
|
||||
noinst_HEADERS = \
|
||||
latency/high_res_clock.hpp \
|
||||
unit/unit_test.hpp
|
||||
|
||||
AM_CXXFLAGS = -I$(srcdir)/../../include
|
||||
|
||||
if !STANDALONE
|
||||
latency_tcp_client_SOURCES = latency/tcp_client.cpp
|
||||
latency_tcp_server_SOURCES = latency/tcp_server.cpp
|
||||
latency_udp_client_SOURCES = latency/udp_client.cpp
|
||||
latency_udp_server_SOURCES = latency/udp_server.cpp
|
||||
performance_client_SOURCES = performance/client.cpp
|
||||
performance_server_SOURCES = performance/server.cpp
|
||||
endif
|
||||
|
||||
unit_associated_allocator_SOURCES = unit/associated_allocator.cpp
|
||||
unit_associated_executor_SOURCES = unit/associated_executor.cpp
|
||||
unit_async_result_SOURCES = unit/async_result.cpp
|
||||
unit_awaitable_SOURCES = unit/awaitable.cpp
|
||||
unit_basic_datagram_socket_SOURCES = unit/basic_datagram_socket.cpp
|
||||
unit_basic_deadline_timer_SOURCES = unit/basic_deadline_timer.cpp
|
||||
unit_basic_raw_socket_SOURCES = unit/basic_raw_socket.cpp
|
||||
unit_basic_seq_packet_socket_SOURCES = unit/basic_seq_packet_socket.cpp
|
||||
unit_basic_serial_port_SOURCES = unit/basic_serial_port.cpp
|
||||
unit_basic_signal_set_SOURCES = unit/basic_signal_set.cpp
|
||||
unit_basic_socket_SOURCES = unit/basic_socket.cpp
|
||||
unit_basic_socket_acceptor_SOURCES = unit/basic_socket_acceptor.cpp
|
||||
unit_basic_stream_socket_SOURCES = unit/basic_stream_socket.cpp
|
||||
unit_basic_streambuf_SOURCES = unit/basic_streambuf.cpp
|
||||
unit_basic_waitable_timer_SOURCES = unit/basic_waitable_timer.cpp
|
||||
unit_bind_executor_SOURCES = unit/bind_executor.cpp
|
||||
unit_buffer_SOURCES = unit/buffer.cpp
|
||||
unit_buffers_iterator_SOURCES = unit/buffers_iterator.cpp
|
||||
unit_buffered_read_stream_SOURCES = unit/buffered_read_stream.cpp
|
||||
unit_buffered_stream_SOURCES = unit/buffered_stream.cpp
|
||||
unit_buffered_write_stream_SOURCES = unit/buffered_write_stream.cpp
|
||||
unit_co_spawn_SOURCES = unit/co_spawn.cpp
|
||||
unit_completion_condition_SOURCES = unit/completion_condition.cpp
|
||||
unit_compose_SOURCES = unit/compose.cpp
|
||||
unit_connect_SOURCES = unit/connect.cpp
|
||||
unit_coroutine_SOURCES = unit/coroutine.cpp
|
||||
unit_deadline_timer_SOURCES = unit/deadline_timer.cpp
|
||||
unit_defer_SOURCES = unit/defer.cpp
|
||||
unit_detached_SOURCES = unit/detached.cpp
|
||||
unit_dispatch_SOURCES = unit/dispatch.cpp
|
||||
unit_error_SOURCES = unit/error.cpp
|
||||
unit_execution_context_SOURCES = unit/execution_context.cpp
|
||||
unit_executor_SOURCES = unit/executor.cpp
|
||||
unit_executor_work_guard_SOURCES = unit/executor_work_guard.cpp
|
||||
unit_generic_basic_endpoint_SOURCES = unit/generic/basic_endpoint.cpp
|
||||
unit_generic_datagram_protocol_SOURCES = unit/generic/datagram_protocol.cpp
|
||||
unit_generic_raw_protocol_SOURCES = unit/generic/raw_protocol.cpp
|
||||
unit_generic_seq_packet_protocol_SOURCES = unit/generic/seq_packet_protocol.cpp
|
||||
unit_generic_stream_protocol_SOURCES = unit/generic/stream_protocol.cpp
|
||||
unit_high_resolution_timer_SOURCES = unit/high_resolution_timer.cpp
|
||||
unit_io_context_SOURCES = unit/io_context.cpp
|
||||
unit_io_context_strand_SOURCES = unit/io_context_strand.cpp
|
||||
unit_ip_address_SOURCES = unit/ip/address.cpp
|
||||
unit_ip_address_v4_SOURCES = unit/ip/address_v4.cpp
|
||||
unit_ip_address_v4_iterator_SOURCES = unit/ip/address_v4_iterator.cpp
|
||||
unit_ip_address_v4_range_SOURCES = unit/ip/address_v4_range.cpp
|
||||
unit_ip_address_v6_SOURCES = unit/ip/address_v6.cpp
|
||||
unit_ip_address_v6_iterator_SOURCES = unit/ip/address_v6_iterator.cpp
|
||||
unit_ip_address_v6_range_SOURCES = unit/ip/address_v6_range.cpp
|
||||
unit_ip_basic_endpoint_SOURCES = unit/ip/basic_endpoint.cpp
|
||||
unit_ip_basic_resolver_SOURCES = unit/ip/basic_resolver.cpp
|
||||
unit_ip_basic_resolver_entry_SOURCES = unit/ip/basic_resolver_entry.cpp
|
||||
unit_ip_basic_resolver_iterator_SOURCES = unit/ip/basic_resolver_iterator.cpp
|
||||
unit_ip_basic_resolver_query_SOURCES = unit/ip/basic_resolver_query.cpp
|
||||
unit_ip_host_name_SOURCES = unit/ip/host_name.cpp
|
||||
unit_ip_icmp_SOURCES = unit/ip/icmp.cpp
|
||||
unit_ip_multicast_SOURCES = unit/ip/multicast.cpp
|
||||
unit_ip_network_v4_SOURCES = unit/ip/network_v4.cpp
|
||||
unit_ip_network_v6_SOURCES = unit/ip/network_v6.cpp
|
||||
unit_ip_resolver_query_base_SOURCES = unit/ip/resolver_query_base.cpp
|
||||
unit_ip_tcp_SOURCES = unit/ip/tcp.cpp
|
||||
unit_ip_udp_SOURCES = unit/ip/udp.cpp
|
||||
unit_ip_unicast_SOURCES = unit/ip/unicast.cpp
|
||||
unit_ip_v6_only_SOURCES = unit/ip/v6_only.cpp
|
||||
unit_is_read_buffered_SOURCES = unit/is_read_buffered.cpp
|
||||
unit_is_write_buffered_SOURCES = unit/is_write_buffered.cpp
|
||||
unit_local_basic_endpoint_SOURCES = unit/local/basic_endpoint.cpp
|
||||
unit_local_connect_pair_SOURCES = unit/local/connect_pair.cpp
|
||||
unit_local_datagram_protocol_SOURCES = unit/local/datagram_protocol.cpp
|
||||
unit_local_stream_protocol_SOURCES = unit/local/stream_protocol.cpp
|
||||
unit_packaged_task_SOURCES = unit/packaged_task.cpp
|
||||
unit_placeholders_SOURCES = unit/placeholders.cpp
|
||||
unit_posix_basic_descriptor_SOURCES = unit/posix/basic_descriptor.cpp
|
||||
unit_posix_basic_stream_descriptor_SOURCES = unit/posix/basic_stream_descriptor.cpp
|
||||
unit_posix_descriptor_SOURCES = unit/posix/descriptor.cpp
|
||||
unit_posix_descriptor_base_SOURCES = unit/posix/descriptor_base.cpp
|
||||
unit_posix_stream_descriptor_SOURCES = unit/posix/stream_descriptor.cpp
|
||||
unit_post_SOURCES = unit/post.cpp
|
||||
unit_read_SOURCES = unit/read.cpp
|
||||
unit_read_at_SOURCES = unit/read_at.cpp
|
||||
unit_read_until_SOURCES = unit/read_until.cpp
|
||||
unit_redirect_error_SOURCES = unit/redirect_error.cpp
|
||||
unit_serial_port_SOURCES = unit/serial_port.cpp
|
||||
unit_serial_port_base_SOURCES = unit/serial_port_base.cpp
|
||||
unit_signal_set_SOURCES = unit/signal_set.cpp
|
||||
unit_socket_base_SOURCES = unit/socket_base.cpp
|
||||
unit_steady_timer_SOURCES = unit/steady_timer.cpp
|
||||
unit_strand_SOURCES = unit/strand.cpp
|
||||
unit_streambuf_SOURCES = unit/streambuf.cpp
|
||||
unit_system_context_SOURCES = unit/system_context.cpp
|
||||
unit_system_executor_SOURCES = unit/system_executor.cpp
|
||||
unit_system_timer_SOURCES = unit/system_timer.cpp
|
||||
unit_this_coro_SOURCES = unit/this_coro.cpp
|
||||
unit_thread_SOURCES = unit/thread.cpp
|
||||
unit_time_traits_SOURCES = unit/time_traits.cpp
|
||||
unit_ts_buffer_SOURCES = unit/ts/buffer.cpp
|
||||
unit_ts_executor_SOURCES = unit/ts/executor.cpp
|
||||
unit_ts_internet_SOURCES = unit/ts/internet.cpp
|
||||
unit_ts_io_context_SOURCES = unit/ts/io_context.cpp
|
||||
unit_ts_net_SOURCES = unit/ts/net.cpp
|
||||
unit_ts_netfwd_SOURCES = unit/ts/netfwd.cpp
|
||||
unit_ts_socket_SOURCES = unit/ts/socket.cpp
|
||||
unit_ts_timer_SOURCES = unit/ts/timer.cpp
|
||||
unit_use_awaitable_SOURCES = unit/use_awaitable.cpp
|
||||
unit_use_future_SOURCES = unit/use_future.cpp
|
||||
unit_uses_executor_SOURCES = unit/uses_executor.cpp
|
||||
unit_wait_traits_SOURCES = unit/wait_traits.cpp
|
||||
unit_windows_basic_object_handle_SOURCES = unit/windows/basic_object_handle.cpp
|
||||
unit_windows_basic_overlapped_handle_SOURCES = unit/windows/basic_overlapped_handle.cpp
|
||||
unit_windows_basic_random_access_handle_SOURCES = unit/windows/basic_random_access_handle.cpp
|
||||
unit_windows_basic_stream_handle_SOURCES = unit/windows/basic_stream_handle.cpp
|
||||
unit_windows_object_handle_SOURCES = unit/windows/object_handle.cpp
|
||||
unit_windows_overlapped_handle_SOURCES = unit/windows/overlapped_handle.cpp
|
||||
unit_windows_overlapped_ptr_SOURCES = unit/windows/overlapped_ptr.cpp
|
||||
unit_windows_random_access_handle_SOURCES = unit/windows/random_access_handle.cpp
|
||||
unit_windows_stream_handle_SOURCES = unit/windows/stream_handle.cpp
|
||||
unit_write_SOURCES = unit/write.cpp
|
||||
unit_write_at_SOURCES = unit/write_at.cpp
|
||||
|
||||
if HAVE_OPENSSL
|
||||
unit_ssl_context_base_SOURCES = unit/ssl/context_base.cpp
|
||||
unit_ssl_context_SOURCES = unit/ssl/context.cpp
|
||||
unit_ssl_error_SOURCES = unit/ssl/error.cpp
|
||||
unit_ssl_stream_base_SOURCES = unit/ssl/stream_base.cpp
|
||||
unit_ssl_rfc2818_verification_SOURCES = unit/ssl/rfc2818_verification.cpp
|
||||
unit_ssl_stream_SOURCES = unit/ssl/stream.cpp
|
||||
endif
|
||||
|
||||
EXTRA_DIST = \
|
||||
latency/allocator.hpp \
|
||||
performance/handler_allocator.hpp \
|
||||
unit/archetypes/async_ops.hpp \
|
||||
unit/archetypes/async_result.hpp \
|
||||
unit/archetypes/gettable_socket_option.hpp \
|
||||
unit/archetypes/io_control_command.hpp \
|
||||
unit/archetypes/settable_socket_option.hpp
|
||||
|
||||
MAINTAINERCLEANFILES = \
|
||||
$(srcdir)/Makefile.in
|
||||
@@ -0,0 +1,11 @@
|
||||
.deps
|
||||
.dirstamp
|
||||
*.o
|
||||
*.obj
|
||||
*.exe
|
||||
*client
|
||||
*server
|
||||
*.ilk
|
||||
*.manifest
|
||||
*.pdb
|
||||
*.tds
|
||||
@@ -0,0 +1,52 @@
|
||||
//
|
||||
// allocator.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 ALLOCATOR_HPP
|
||||
#define ALLOCATOR_HPP
|
||||
|
||||
#include <boost/aligned_storage.hpp>
|
||||
|
||||
// Represents a single connection from a client.
|
||||
class allocator
|
||||
{
|
||||
public:
|
||||
allocator()
|
||||
: in_use_(false)
|
||||
{
|
||||
}
|
||||
|
||||
void* allocate(std::size_t n)
|
||||
{
|
||||
if (in_use_ || n >= 1024)
|
||||
return ::operator new(n);
|
||||
in_use_ = true;
|
||||
return static_cast<void*>(&space_);
|
||||
}
|
||||
|
||||
void deallocate(void* p)
|
||||
{
|
||||
if (p != static_cast<void*>(&space_))
|
||||
::operator delete(p);
|
||||
else
|
||||
in_use_ = false;
|
||||
}
|
||||
|
||||
private:
|
||||
allocator(const allocator&);
|
||||
allocator& operator=(const allocator&);
|
||||
|
||||
// Whether the reusable memory space is currently in use.
|
||||
bool in_use_;
|
||||
|
||||
// The reusable memory space made available by the allocator.
|
||||
boost::aligned_storage<1024>::type space_;
|
||||
};
|
||||
|
||||
#endif // ALLOCATOR_HPP
|
||||
@@ -0,0 +1,53 @@
|
||||
//
|
||||
// high_res_clock.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 HIGH_RES_CLOCK_HPP
|
||||
#define HIGH_RES_CLOCK_HPP
|
||||
|
||||
#include <boost/config.hpp>
|
||||
#include <boost/cstdint.hpp>
|
||||
|
||||
#if defined(ASIO_WINDOWS)
|
||||
|
||||
inline boost::uint64_t high_res_clock()
|
||||
{
|
||||
LARGE_INTEGER i;
|
||||
QueryPerformanceCounter(&i);
|
||||
return i.QuadPart;
|
||||
}
|
||||
|
||||
#elif defined(__GNUC__) && defined(__x86_64__)
|
||||
|
||||
inline boost::uint64_t high_res_clock()
|
||||
{
|
||||
unsigned long low, high;
|
||||
__asm__ __volatile__("rdtsc" : "=a" (low), "=d" (high));
|
||||
return (((boost::uint64_t)high) << 32) | low;
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
#include <boost/date_time/posix_time/posix_time_types.hpp>
|
||||
|
||||
inline boost::uint64_t high_res_clock()
|
||||
{
|
||||
boost::posix_time::ptime now =
|
||||
boost::posix_time::microsec_clock::universal_time();
|
||||
|
||||
boost::posix_time::ptime epoch(
|
||||
boost::gregorian::date(1970, 1, 1),
|
||||
boost::posix_time::seconds(0));
|
||||
|
||||
return (now - epoch).total_microseconds();
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#endif // HIGH_RES_CLOCK_HPP
|
||||
@@ -0,0 +1,124 @@
|
||||
//
|
||||
// tcp_client.cpp
|
||||
// ~~~~~~~~~~~~~~
|
||||
//
|
||||
// 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)
|
||||
//
|
||||
|
||||
#include <asio/ip/tcp.hpp>
|
||||
#include <asio/read.hpp>
|
||||
#include <asio/write.hpp>
|
||||
#include <boost/date_time/posix_time/posix_time_types.hpp>
|
||||
#include <boost/shared_ptr.hpp>
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
#include <vector>
|
||||
#include "high_res_clock.hpp"
|
||||
|
||||
using asio::ip::tcp;
|
||||
using boost::posix_time::ptime;
|
||||
using boost::posix_time::microsec_clock;
|
||||
|
||||
const int num_samples = 100000;
|
||||
|
||||
struct transfer_all
|
||||
{
|
||||
typedef std::size_t result_type;
|
||||
std::size_t operator()(const asio::error_code& ec, std::size_t)
|
||||
{
|
||||
return (ec && ec != asio::error::would_block) ? 0 : ~0;
|
||||
}
|
||||
};
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
if (argc != 6)
|
||||
{
|
||||
std::fprintf(stderr,
|
||||
"Usage: tcp_client <ip> <port> "
|
||||
"<nconns> <bufsize> {spin|block}\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
const char* ip = argv[1];
|
||||
unsigned short port = static_cast<unsigned short>(std::atoi(argv[2]));
|
||||
int num_connections = std::atoi(argv[3]);
|
||||
std::size_t buf_size = static_cast<std::size_t>(std::atoi(argv[4]));
|
||||
bool spin = (std::strcmp(argv[5], "spin") == 0);
|
||||
|
||||
asio::io_context io_context;
|
||||
std::vector<boost::shared_ptr<tcp::socket> > sockets;
|
||||
|
||||
for (int i = 0; i < num_connections; ++i)
|
||||
{
|
||||
boost::shared_ptr<tcp::socket> s(new tcp::socket(io_context));
|
||||
|
||||
tcp::endpoint target(asio::ip::make_address(ip), port);
|
||||
s->connect(target);
|
||||
|
||||
s->set_option(tcp::no_delay(true));
|
||||
|
||||
if (spin)
|
||||
{
|
||||
s->non_blocking(true);
|
||||
}
|
||||
|
||||
sockets.push_back(s);
|
||||
}
|
||||
|
||||
std::vector<unsigned char> write_buf(buf_size);
|
||||
std::vector<unsigned char> read_buf(buf_size);
|
||||
|
||||
ptime start = microsec_clock::universal_time();
|
||||
boost::uint64_t start_hr = high_res_clock();
|
||||
|
||||
boost::uint64_t samples[num_samples];
|
||||
for (int i = 0; i < num_samples; ++i)
|
||||
{
|
||||
tcp::socket& socket = *sockets[i % num_connections];
|
||||
|
||||
boost::uint64_t t = high_res_clock();
|
||||
|
||||
asio::error_code ec;
|
||||
asio::write(socket,
|
||||
asio::buffer(write_buf),
|
||||
transfer_all(), ec);
|
||||
|
||||
asio::read(socket,
|
||||
asio::buffer(read_buf),
|
||||
transfer_all(), ec);
|
||||
|
||||
samples[i] = high_res_clock() - t;
|
||||
}
|
||||
|
||||
ptime stop = microsec_clock::universal_time();
|
||||
boost::uint64_t stop_hr = high_res_clock();
|
||||
boost::uint64_t elapsed_usec = (stop - start).total_microseconds();
|
||||
boost::uint64_t elapsed_hr = stop_hr - start_hr;
|
||||
double scale = 1.0 * elapsed_usec / elapsed_hr;
|
||||
|
||||
std::sort(samples, samples + num_samples);
|
||||
std::printf(" 0.0%%\t%f\n", samples[0] * scale);
|
||||
std::printf(" 0.1%%\t%f\n", samples[num_samples / 1000 - 1] * scale);
|
||||
std::printf(" 1.0%%\t%f\n", samples[num_samples / 100 - 1] * scale);
|
||||
std::printf(" 10.0%%\t%f\n", samples[num_samples / 10 - 1] * scale);
|
||||
std::printf(" 20.0%%\t%f\n", samples[num_samples * 2 / 10 - 1] * scale);
|
||||
std::printf(" 30.0%%\t%f\n", samples[num_samples * 3 / 10 - 1] * scale);
|
||||
std::printf(" 40.0%%\t%f\n", samples[num_samples * 4 / 10 - 1] * scale);
|
||||
std::printf(" 50.0%%\t%f\n", samples[num_samples * 5 / 10 - 1] * scale);
|
||||
std::printf(" 60.0%%\t%f\n", samples[num_samples * 6 / 10 - 1] * scale);
|
||||
std::printf(" 70.0%%\t%f\n", samples[num_samples * 7 / 10 - 1] * scale);
|
||||
std::printf(" 80.0%%\t%f\n", samples[num_samples * 8 / 10 - 1] * scale);
|
||||
std::printf(" 90.0%%\t%f\n", samples[num_samples * 9 / 10 - 1] * scale);
|
||||
std::printf(" 99.0%%\t%f\n", samples[num_samples * 99 / 100 - 1] * scale);
|
||||
std::printf(" 99.9%%\t%f\n", samples[num_samples * 999 / 1000 - 1] * scale);
|
||||
std::printf("100.0%%\t%f\n", samples[num_samples - 1] * scale);
|
||||
|
||||
double total = 0.0;
|
||||
for (int i = 0; i < num_samples; ++i) total += samples[i] * scale;
|
||||
std::printf(" mean\t%f\n", total / num_samples);
|
||||
}
|
||||
@@ -0,0 +1,114 @@
|
||||
//
|
||||
// tcp_server.cpp
|
||||
// ~~~~~~~~~~~~~~
|
||||
//
|
||||
// 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)
|
||||
//
|
||||
|
||||
#include <asio/io_context.hpp>
|
||||
#include <asio/ip/tcp.hpp>
|
||||
#include <asio/read.hpp>
|
||||
#include <asio/write.hpp>
|
||||
#include <boost/shared_ptr.hpp>
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
#include <vector>
|
||||
|
||||
using asio::ip::tcp;
|
||||
|
||||
#include <asio/yield.hpp>
|
||||
|
||||
class tcp_server : asio::coroutine
|
||||
{
|
||||
public:
|
||||
tcp_server(tcp::acceptor& acceptor, std::size_t buf_size) :
|
||||
acceptor_(acceptor),
|
||||
socket_(acceptor_.get_executor()),
|
||||
buffer_(buf_size)
|
||||
{
|
||||
}
|
||||
|
||||
void operator()(asio::error_code ec, std::size_t n = 0)
|
||||
{
|
||||
reenter (this) for (;;)
|
||||
{
|
||||
yield acceptor_.async_accept(socket_, ref(this));
|
||||
|
||||
while (!ec)
|
||||
{
|
||||
yield asio::async_read(socket_,
|
||||
asio::buffer(buffer_), ref(this));
|
||||
|
||||
if (!ec)
|
||||
{
|
||||
for (std::size_t i = 0; i < n; ++i) buffer_[i] = ~buffer_[i];
|
||||
|
||||
yield asio::async_write(socket_,
|
||||
asio::buffer(buffer_), ref(this));
|
||||
}
|
||||
}
|
||||
|
||||
socket_.close();
|
||||
}
|
||||
}
|
||||
|
||||
struct ref
|
||||
{
|
||||
explicit ref(tcp_server* p)
|
||||
: p_(p)
|
||||
{
|
||||
}
|
||||
|
||||
void operator()(asio::error_code ec, std::size_t n = 0)
|
||||
{
|
||||
(*p_)(ec, n);
|
||||
}
|
||||
|
||||
private:
|
||||
tcp_server* p_;
|
||||
};
|
||||
|
||||
private:
|
||||
tcp::acceptor& acceptor_;
|
||||
tcp::socket socket_;
|
||||
std::vector<unsigned char> buffer_;
|
||||
tcp::endpoint sender_;
|
||||
};
|
||||
|
||||
#include <asio/unyield.hpp>
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
if (argc != 5)
|
||||
{
|
||||
std::fprintf(stderr,
|
||||
"Usage: tcp_server <port> <nconns> "
|
||||
"<bufsize> {spin|block}\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
unsigned short port = static_cast<unsigned short>(std::atoi(argv[1]));
|
||||
int max_connections = std::atoi(argv[2]);
|
||||
std::size_t buf_size = std::atoi(argv[3]);
|
||||
bool spin = (std::strcmp(argv[4], "spin") == 0);
|
||||
|
||||
asio::io_context io_context(1);
|
||||
tcp::acceptor acceptor(io_context, tcp::endpoint(tcp::v4(), port));
|
||||
std::vector<boost::shared_ptr<tcp_server> > servers;
|
||||
|
||||
for (int i = 0; i < max_connections; ++i)
|
||||
{
|
||||
boost::shared_ptr<tcp_server> s(new tcp_server(acceptor, buf_size));
|
||||
servers.push_back(s);
|
||||
(*s)(asio::error_code());
|
||||
}
|
||||
|
||||
if (spin)
|
||||
for (;;) io_context.poll();
|
||||
else
|
||||
io_context.run();
|
||||
}
|
||||
@@ -0,0 +1,104 @@
|
||||
//
|
||||
// udp_client.cpp
|
||||
// ~~~~~~~~~~~~~~
|
||||
//
|
||||
// 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)
|
||||
//
|
||||
|
||||
#include <asio/ip/udp.hpp>
|
||||
#include <boost/date_time/posix_time/posix_time_types.hpp>
|
||||
#include <algorithm>
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
#include <vector>
|
||||
#include "high_res_clock.hpp"
|
||||
|
||||
using asio::ip::udp;
|
||||
using boost::posix_time::ptime;
|
||||
using boost::posix_time::microsec_clock;
|
||||
|
||||
const int num_samples = 100000;
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
if (argc != 6)
|
||||
{
|
||||
std::fprintf(stderr,
|
||||
"Usage: udp_client <ip> <port1> "
|
||||
"<nports> <bufsize> {spin|block}\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
const char* ip = argv[1];
|
||||
unsigned short first_port = static_cast<unsigned short>(std::atoi(argv[2]));
|
||||
unsigned short num_ports = static_cast<unsigned short>(std::atoi(argv[3]));
|
||||
std::size_t buf_size = static_cast<std::size_t>(std::atoi(argv[4]));
|
||||
bool spin = (std::strcmp(argv[5], "spin") == 0);
|
||||
|
||||
asio::io_context io_context;
|
||||
|
||||
udp::socket socket(io_context, udp::endpoint(udp::v4(), 0));
|
||||
|
||||
if (spin)
|
||||
{
|
||||
socket.non_blocking(true);
|
||||
}
|
||||
|
||||
udp::endpoint target(asio::ip::make_address(ip), first_port);
|
||||
unsigned short last_port = first_port + num_ports - 1;
|
||||
std::vector<unsigned char> write_buf(buf_size);
|
||||
std::vector<unsigned char> read_buf(buf_size);
|
||||
|
||||
ptime start = microsec_clock::universal_time();
|
||||
boost::uint64_t start_hr = high_res_clock();
|
||||
|
||||
boost::uint64_t samples[num_samples];
|
||||
for (int i = 0; i < num_samples; ++i)
|
||||
{
|
||||
boost::uint64_t t = high_res_clock();
|
||||
|
||||
asio::error_code ec;
|
||||
socket.send_to(asio::buffer(write_buf), target, 0, ec);
|
||||
|
||||
do socket.receive(asio::buffer(read_buf), 0, ec);
|
||||
while (ec == asio::error::would_block);
|
||||
|
||||
samples[i] = high_res_clock() - t;
|
||||
|
||||
if (target.port() == last_port)
|
||||
target.port(first_port);
|
||||
else
|
||||
target.port(target.port() + 1);
|
||||
}
|
||||
|
||||
ptime stop = microsec_clock::universal_time();
|
||||
boost::uint64_t stop_hr = high_res_clock();
|
||||
boost::uint64_t elapsed_usec = (stop - start).total_microseconds();
|
||||
boost::uint64_t elapsed_hr = stop_hr - start_hr;
|
||||
double scale = 1.0 * elapsed_usec / elapsed_hr;
|
||||
|
||||
std::sort(samples, samples + num_samples);
|
||||
std::printf(" 0.0%%\t%f\n", samples[0] * scale);
|
||||
std::printf(" 0.1%%\t%f\n", samples[num_samples / 1000 - 1] * scale);
|
||||
std::printf(" 1.0%%\t%f\n", samples[num_samples / 100 - 1] * scale);
|
||||
std::printf(" 10.0%%\t%f\n", samples[num_samples / 10 - 1] * scale);
|
||||
std::printf(" 20.0%%\t%f\n", samples[num_samples * 2 / 10 - 1] * scale);
|
||||
std::printf(" 30.0%%\t%f\n", samples[num_samples * 3 / 10 - 1] * scale);
|
||||
std::printf(" 40.0%%\t%f\n", samples[num_samples * 4 / 10 - 1] * scale);
|
||||
std::printf(" 50.0%%\t%f\n", samples[num_samples * 5 / 10 - 1] * scale);
|
||||
std::printf(" 60.0%%\t%f\n", samples[num_samples * 6 / 10 - 1] * scale);
|
||||
std::printf(" 70.0%%\t%f\n", samples[num_samples * 7 / 10 - 1] * scale);
|
||||
std::printf(" 80.0%%\t%f\n", samples[num_samples * 8 / 10 - 1] * scale);
|
||||
std::printf(" 90.0%%\t%f\n", samples[num_samples * 9 / 10 - 1] * scale);
|
||||
std::printf(" 99.0%%\t%f\n", samples[num_samples * 99 / 100 - 1] * scale);
|
||||
std::printf(" 99.9%%\t%f\n", samples[num_samples * 999 / 1000 - 1] * scale);
|
||||
std::printf("100.0%%\t%f\n", samples[num_samples - 1] * scale);
|
||||
|
||||
double total = 0.0;
|
||||
for (int i = 0; i < num_samples; ++i) total += samples[i] * scale;
|
||||
std::printf(" mean\t%f\n", total / num_samples);
|
||||
}
|
||||
@@ -0,0 +1,125 @@
|
||||
//
|
||||
// udp_server.cpp
|
||||
// ~~~~~~~~~~~~~~
|
||||
//
|
||||
// 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)
|
||||
//
|
||||
|
||||
#include <asio/io_context.hpp>
|
||||
#include <asio/ip/udp.hpp>
|
||||
#include <boost/shared_ptr.hpp>
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
#include <vector>
|
||||
#include "allocator.hpp"
|
||||
|
||||
using asio::ip::udp;
|
||||
|
||||
#include <asio/yield.hpp>
|
||||
|
||||
class udp_server : asio::coroutine
|
||||
{
|
||||
public:
|
||||
udp_server(asio::io_context& io_context,
|
||||
unsigned short port, std::size_t buf_size) :
|
||||
socket_(io_context, udp::endpoint(udp::v4(), port)),
|
||||
buffer_(buf_size)
|
||||
{
|
||||
}
|
||||
|
||||
void operator()(asio::error_code ec, std::size_t n = 0)
|
||||
{
|
||||
reenter (this) for (;;)
|
||||
{
|
||||
yield socket_.async_receive_from(
|
||||
asio::buffer(buffer_),
|
||||
sender_, ref(this));
|
||||
|
||||
if (!ec)
|
||||
{
|
||||
for (std::size_t i = 0; i < n; ++i) buffer_[i] = ~buffer_[i];
|
||||
socket_.send_to(asio::buffer(buffer_, n), sender_, 0, ec);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
friend void* asio_handler_allocate(std::size_t n, udp_server* s)
|
||||
{
|
||||
return s->allocator_.allocate(n);
|
||||
}
|
||||
|
||||
friend void asio_handler_deallocate(void* p, std::size_t, udp_server* s)
|
||||
{
|
||||
s->allocator_.deallocate(p);
|
||||
}
|
||||
|
||||
struct ref
|
||||
{
|
||||
explicit ref(udp_server* p)
|
||||
: p_(p)
|
||||
{
|
||||
}
|
||||
|
||||
void operator()(asio::error_code ec, std::size_t n = 0)
|
||||
{
|
||||
(*p_)(ec, n);
|
||||
}
|
||||
|
||||
private:
|
||||
udp_server* p_;
|
||||
|
||||
friend void* asio_handler_allocate(std::size_t n, ref* r)
|
||||
{
|
||||
return asio_handler_allocate(n, r->p_);
|
||||
}
|
||||
|
||||
friend void asio_handler_deallocate(void* p, std::size_t n, ref* r)
|
||||
{
|
||||
asio_handler_deallocate(p, n, r->p_);
|
||||
}
|
||||
};
|
||||
|
||||
private:
|
||||
udp::socket socket_;
|
||||
std::vector<unsigned char> buffer_;
|
||||
udp::endpoint sender_;
|
||||
allocator allocator_;
|
||||
};
|
||||
|
||||
#include <asio/unyield.hpp>
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
if (argc != 5)
|
||||
{
|
||||
std::fprintf(stderr,
|
||||
"Usage: udp_server <port1> <nports> "
|
||||
"<bufsize> {spin|block}\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
unsigned short first_port = static_cast<unsigned short>(std::atoi(argv[1]));
|
||||
unsigned short num_ports = static_cast<unsigned short>(std::atoi(argv[2]));
|
||||
std::size_t buf_size = std::atoi(argv[3]);
|
||||
bool spin = (std::strcmp(argv[4], "spin") == 0);
|
||||
|
||||
asio::io_context io_context(1);
|
||||
std::vector<boost::shared_ptr<udp_server> > servers;
|
||||
|
||||
for (unsigned short i = 0; i < num_ports; ++i)
|
||||
{
|
||||
unsigned short port = first_port + i;
|
||||
boost::shared_ptr<udp_server> s(new udp_server(io_context, port, buf_size));
|
||||
servers.push_back(s);
|
||||
(*s)(asio::error_code());
|
||||
}
|
||||
|
||||
if (spin)
|
||||
for (;;) io_context.poll();
|
||||
else
|
||||
io_context.run();
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
.deps
|
||||
.dirstamp
|
||||
*.o
|
||||
*.obj
|
||||
*.exe
|
||||
client
|
||||
server
|
||||
*.ilk
|
||||
*.manifest
|
||||
*.pdb
|
||||
*.tds
|
||||
@@ -0,0 +1,286 @@
|
||||
//
|
||||
// client.cpp
|
||||
// ~~~~~~~~~~
|
||||
//
|
||||
// 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)
|
||||
//
|
||||
|
||||
#include "asio.hpp"
|
||||
#include <algorithm>
|
||||
#include <boost/bind.hpp>
|
||||
#include <boost/mem_fn.hpp>
|
||||
#include <iostream>
|
||||
#include <list>
|
||||
#include <string>
|
||||
#include "handler_allocator.hpp"
|
||||
|
||||
class stats
|
||||
{
|
||||
public:
|
||||
stats()
|
||||
: mutex_(),
|
||||
total_bytes_written_(0),
|
||||
total_bytes_read_(0)
|
||||
{
|
||||
}
|
||||
|
||||
void add(size_t bytes_written, size_t bytes_read)
|
||||
{
|
||||
asio::detail::mutex::scoped_lock lock(mutex_);
|
||||
total_bytes_written_ += bytes_written;
|
||||
total_bytes_read_ += bytes_read;
|
||||
}
|
||||
|
||||
void print()
|
||||
{
|
||||
asio::detail::mutex::scoped_lock lock(mutex_);
|
||||
std::cout << total_bytes_written_ << " total bytes written\n";
|
||||
std::cout << total_bytes_read_ << " total bytes read\n";
|
||||
}
|
||||
|
||||
private:
|
||||
asio::detail::mutex mutex_;
|
||||
size_t total_bytes_written_;
|
||||
size_t total_bytes_read_;
|
||||
};
|
||||
|
||||
class session
|
||||
{
|
||||
public:
|
||||
session(asio::io_context& ioc, size_t block_size, stats& s)
|
||||
: strand_(ioc),
|
||||
socket_(ioc),
|
||||
block_size_(block_size),
|
||||
read_data_(new char[block_size]),
|
||||
read_data_length_(0),
|
||||
write_data_(new char[block_size]),
|
||||
unwritten_count_(0),
|
||||
bytes_written_(0),
|
||||
bytes_read_(0),
|
||||
stats_(s)
|
||||
{
|
||||
for (size_t i = 0; i < block_size_; ++i)
|
||||
write_data_[i] = static_cast<char>(i % 128);
|
||||
}
|
||||
|
||||
~session()
|
||||
{
|
||||
stats_.add(bytes_written_, bytes_read_);
|
||||
|
||||
delete[] read_data_;
|
||||
delete[] write_data_;
|
||||
}
|
||||
|
||||
void start(asio::ip::tcp::resolver::results_type endpoints)
|
||||
{
|
||||
asio::async_connect(socket_, endpoints,
|
||||
asio::bind_executor(strand_,
|
||||
boost::bind(&session::handle_connect, this,
|
||||
asio::placeholders::error)));
|
||||
}
|
||||
|
||||
void stop()
|
||||
{
|
||||
asio::post(strand_, boost::bind(&session::close_socket, this));
|
||||
}
|
||||
|
||||
private:
|
||||
void handle_connect(const asio::error_code& err)
|
||||
{
|
||||
if (!err)
|
||||
{
|
||||
asio::error_code set_option_err;
|
||||
asio::ip::tcp::no_delay no_delay(true);
|
||||
socket_.set_option(no_delay, set_option_err);
|
||||
if (!set_option_err)
|
||||
{
|
||||
++unwritten_count_;
|
||||
async_write(socket_, asio::buffer(write_data_, block_size_),
|
||||
asio::bind_executor(strand_,
|
||||
make_custom_alloc_handler(write_allocator_,
|
||||
boost::bind(&session::handle_write, this,
|
||||
asio::placeholders::error,
|
||||
asio::placeholders::bytes_transferred))));
|
||||
socket_.async_read_some(asio::buffer(read_data_, block_size_),
|
||||
asio::bind_executor(strand_,
|
||||
make_custom_alloc_handler(read_allocator_,
|
||||
boost::bind(&session::handle_read, this,
|
||||
asio::placeholders::error,
|
||||
asio::placeholders::bytes_transferred))));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void handle_read(const asio::error_code& err, size_t length)
|
||||
{
|
||||
if (!err)
|
||||
{
|
||||
bytes_read_ += length;
|
||||
|
||||
read_data_length_ = length;
|
||||
++unwritten_count_;
|
||||
if (unwritten_count_ == 1)
|
||||
{
|
||||
std::swap(read_data_, write_data_);
|
||||
async_write(socket_, asio::buffer(write_data_, read_data_length_),
|
||||
asio::bind_executor(strand_,
|
||||
make_custom_alloc_handler(write_allocator_,
|
||||
boost::bind(&session::handle_write, this,
|
||||
asio::placeholders::error,
|
||||
asio::placeholders::bytes_transferred))));
|
||||
socket_.async_read_some(asio::buffer(read_data_, block_size_),
|
||||
asio::bind_executor(strand_,
|
||||
make_custom_alloc_handler(read_allocator_,
|
||||
boost::bind(&session::handle_read, this,
|
||||
asio::placeholders::error,
|
||||
asio::placeholders::bytes_transferred))));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void handle_write(const asio::error_code& err, size_t length)
|
||||
{
|
||||
if (!err && length > 0)
|
||||
{
|
||||
bytes_written_ += length;
|
||||
|
||||
--unwritten_count_;
|
||||
if (unwritten_count_ == 1)
|
||||
{
|
||||
std::swap(read_data_, write_data_);
|
||||
async_write(socket_, asio::buffer(write_data_, read_data_length_),
|
||||
asio::bind_executor(strand_,
|
||||
make_custom_alloc_handler(write_allocator_,
|
||||
boost::bind(&session::handle_write, this,
|
||||
asio::placeholders::error,
|
||||
asio::placeholders::bytes_transferred))));
|
||||
socket_.async_read_some(asio::buffer(read_data_, block_size_),
|
||||
asio::bind_executor(strand_,
|
||||
make_custom_alloc_handler(read_allocator_,
|
||||
boost::bind(&session::handle_read, this,
|
||||
asio::placeholders::error,
|
||||
asio::placeholders::bytes_transferred))));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void close_socket()
|
||||
{
|
||||
socket_.close();
|
||||
}
|
||||
|
||||
private:
|
||||
asio::io_context::strand strand_;
|
||||
asio::ip::tcp::socket socket_;
|
||||
size_t block_size_;
|
||||
char* read_data_;
|
||||
size_t read_data_length_;
|
||||
char* write_data_;
|
||||
int unwritten_count_;
|
||||
size_t bytes_written_;
|
||||
size_t bytes_read_;
|
||||
stats& stats_;
|
||||
handler_allocator read_allocator_;
|
||||
handler_allocator write_allocator_;
|
||||
};
|
||||
|
||||
class client
|
||||
{
|
||||
public:
|
||||
client(asio::io_context& ioc,
|
||||
const asio::ip::tcp::resolver::results_type endpoints,
|
||||
size_t block_size, size_t session_count, int timeout)
|
||||
: io_context_(ioc),
|
||||
stop_timer_(ioc),
|
||||
sessions_(),
|
||||
stats_()
|
||||
{
|
||||
stop_timer_.expires_after(asio::chrono::seconds(timeout));
|
||||
stop_timer_.async_wait(boost::bind(&client::handle_timeout, this));
|
||||
|
||||
for (size_t i = 0; i < session_count; ++i)
|
||||
{
|
||||
session* new_session = new session(io_context_, block_size, stats_);
|
||||
new_session->start(endpoints);
|
||||
sessions_.push_back(new_session);
|
||||
}
|
||||
}
|
||||
|
||||
~client()
|
||||
{
|
||||
while (!sessions_.empty())
|
||||
{
|
||||
delete sessions_.front();
|
||||
sessions_.pop_front();
|
||||
}
|
||||
|
||||
stats_.print();
|
||||
}
|
||||
|
||||
void handle_timeout()
|
||||
{
|
||||
std::for_each(sessions_.begin(), sessions_.end(),
|
||||
boost::mem_fn(&session::stop));
|
||||
}
|
||||
|
||||
private:
|
||||
asio::io_context& io_context_;
|
||||
asio::steady_timer stop_timer_;
|
||||
std::list<session*> sessions_;
|
||||
stats stats_;
|
||||
};
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
try
|
||||
{
|
||||
if (argc != 7)
|
||||
{
|
||||
std::cerr << "Usage: client <host> <port> <threads> <blocksize> ";
|
||||
std::cerr << "<sessions> <time>\n";
|
||||
return 1;
|
||||
}
|
||||
|
||||
using namespace std; // For atoi.
|
||||
const char* host = argv[1];
|
||||
const char* port = argv[2];
|
||||
int thread_count = atoi(argv[3]);
|
||||
size_t block_size = atoi(argv[4]);
|
||||
size_t session_count = atoi(argv[5]);
|
||||
int timeout = atoi(argv[6]);
|
||||
|
||||
asio::io_context ioc;
|
||||
|
||||
asio::ip::tcp::resolver r(ioc);
|
||||
asio::ip::tcp::resolver::results_type endpoints =
|
||||
r.resolve(host, port);
|
||||
|
||||
client c(ioc, endpoints, block_size, session_count, timeout);
|
||||
|
||||
std::list<asio::thread*> threads;
|
||||
while (--thread_count > 0)
|
||||
{
|
||||
asio::thread* new_thread = new asio::thread(
|
||||
boost::bind(&asio::io_context::run, &ioc));
|
||||
threads.push_back(new_thread);
|
||||
}
|
||||
|
||||
ioc.run();
|
||||
|
||||
while (!threads.empty())
|
||||
{
|
||||
threads.front()->join();
|
||||
delete threads.front();
|
||||
threads.pop_front();
|
||||
}
|
||||
}
|
||||
catch (std::exception& e)
|
||||
{
|
||||
std::cerr << "Exception: " << e.what() << "\n";
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,112 @@
|
||||
//
|
||||
// handler_allocator.cpp
|
||||
// ~~~~~~~~~~~~~~~~~~~~~
|
||||
//
|
||||
// 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 HANDLER_ALLOCATOR_HPP
|
||||
#define HANDLER_ALLOCATOR_HPP
|
||||
|
||||
#include "asio.hpp"
|
||||
#include <boost/aligned_storage.hpp>
|
||||
#include <boost/noncopyable.hpp>
|
||||
|
||||
// Class to manage the memory to be used for handler-based custom allocation.
|
||||
// It contains a single block of memory which may be returned for allocation
|
||||
// requests. If the memory is in use when an allocation request is made, the
|
||||
// allocator delegates allocation to the global heap.
|
||||
class handler_allocator
|
||||
: private boost::noncopyable
|
||||
{
|
||||
public:
|
||||
handler_allocator()
|
||||
: in_use_(false)
|
||||
{
|
||||
}
|
||||
|
||||
void* allocate(std::size_t size)
|
||||
{
|
||||
if (!in_use_ && size < storage_.size)
|
||||
{
|
||||
in_use_ = true;
|
||||
return storage_.address();
|
||||
}
|
||||
|
||||
return ::operator new(size);
|
||||
}
|
||||
|
||||
void deallocate(void* pointer)
|
||||
{
|
||||
if (pointer == storage_.address())
|
||||
{
|
||||
in_use_ = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
::operator delete(pointer);
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
// Storage space used for handler-based custom memory allocation.
|
||||
boost::aligned_storage<1024> storage_;
|
||||
|
||||
// Whether the handler-based custom allocation storage has been used.
|
||||
bool in_use_;
|
||||
};
|
||||
|
||||
// Wrapper class template for handler objects to allow handler memory
|
||||
// allocation to be customised. Calls to operator() are forwarded to the
|
||||
// encapsulated handler.
|
||||
template <typename Handler>
|
||||
class custom_alloc_handler
|
||||
{
|
||||
public:
|
||||
custom_alloc_handler(handler_allocator& a, Handler h)
|
||||
: allocator_(a),
|
||||
handler_(h)
|
||||
{
|
||||
}
|
||||
|
||||
template <typename Arg1>
|
||||
void operator()(Arg1 arg1)
|
||||
{
|
||||
handler_(arg1);
|
||||
}
|
||||
|
||||
template <typename Arg1, typename Arg2>
|
||||
void operator()(Arg1 arg1, Arg2 arg2)
|
||||
{
|
||||
handler_(arg1, arg2);
|
||||
}
|
||||
|
||||
friend void* asio_handler_allocate(std::size_t size,
|
||||
custom_alloc_handler<Handler>* this_handler)
|
||||
{
|
||||
return this_handler->allocator_.allocate(size);
|
||||
}
|
||||
|
||||
friend void asio_handler_deallocate(void* pointer, std::size_t /*size*/,
|
||||
custom_alloc_handler<Handler>* this_handler)
|
||||
{
|
||||
this_handler->allocator_.deallocate(pointer);
|
||||
}
|
||||
|
||||
private:
|
||||
handler_allocator& allocator_;
|
||||
Handler handler_;
|
||||
};
|
||||
|
||||
// Helper function to wrap a handler object to add custom allocation.
|
||||
template <typename Handler>
|
||||
inline custom_alloc_handler<Handler> make_custom_alloc_handler(
|
||||
handler_allocator& a, Handler h)
|
||||
{
|
||||
return custom_alloc_handler<Handler>(a, h);
|
||||
}
|
||||
|
||||
#endif // HANDLER_ALLOCATOR_HPP
|
||||
@@ -0,0 +1,233 @@
|
||||
//
|
||||
// server.cpp
|
||||
// ~~~~~~~~~~
|
||||
//
|
||||
// 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)
|
||||
//
|
||||
|
||||
#include "asio.hpp"
|
||||
#include <algorithm>
|
||||
#include <boost/bind.hpp>
|
||||
#include <iostream>
|
||||
#include <list>
|
||||
#include "handler_allocator.hpp"
|
||||
|
||||
class session
|
||||
{
|
||||
public:
|
||||
session(asio::io_context& ioc, size_t block_size)
|
||||
: io_context_(ioc),
|
||||
strand_(ioc),
|
||||
socket_(ioc),
|
||||
block_size_(block_size),
|
||||
read_data_(new char[block_size]),
|
||||
read_data_length_(0),
|
||||
write_data_(new char[block_size]),
|
||||
unsent_count_(0),
|
||||
op_count_(0)
|
||||
{
|
||||
}
|
||||
|
||||
~session()
|
||||
{
|
||||
delete[] read_data_;
|
||||
delete[] write_data_;
|
||||
}
|
||||
|
||||
asio::ip::tcp::socket& socket()
|
||||
{
|
||||
return socket_;
|
||||
}
|
||||
|
||||
void start()
|
||||
{
|
||||
asio::error_code set_option_err;
|
||||
asio::ip::tcp::no_delay no_delay(true);
|
||||
socket_.set_option(no_delay, set_option_err);
|
||||
if (!set_option_err)
|
||||
{
|
||||
++op_count_;
|
||||
socket_.async_read_some(asio::buffer(read_data_, block_size_),
|
||||
asio::bind_executor(strand_,
|
||||
make_custom_alloc_handler(read_allocator_,
|
||||
boost::bind(&session::handle_read, this,
|
||||
asio::placeholders::error,
|
||||
asio::placeholders::bytes_transferred))));
|
||||
}
|
||||
else
|
||||
{
|
||||
asio::post(io_context_, boost::bind(&session::destroy, this));
|
||||
}
|
||||
}
|
||||
|
||||
void handle_read(const asio::error_code& err, size_t length)
|
||||
{
|
||||
--op_count_;
|
||||
|
||||
if (!err)
|
||||
{
|
||||
read_data_length_ = length;
|
||||
++unsent_count_;
|
||||
if (unsent_count_ == 1)
|
||||
{
|
||||
op_count_ += 2;
|
||||
std::swap(read_data_, write_data_);
|
||||
async_write(socket_, asio::buffer(write_data_, read_data_length_),
|
||||
asio::bind_executor(strand_,
|
||||
make_custom_alloc_handler(write_allocator_,
|
||||
boost::bind(&session::handle_write, this,
|
||||
asio::placeholders::error))));
|
||||
socket_.async_read_some(asio::buffer(read_data_, block_size_),
|
||||
asio::bind_executor(strand_,
|
||||
make_custom_alloc_handler(read_allocator_,
|
||||
boost::bind(&session::handle_read, this,
|
||||
asio::placeholders::error,
|
||||
asio::placeholders::bytes_transferred))));
|
||||
}
|
||||
}
|
||||
|
||||
if (op_count_ == 0)
|
||||
asio::post(io_context_, boost::bind(&session::destroy, this));
|
||||
}
|
||||
|
||||
void handle_write(const asio::error_code& err)
|
||||
{
|
||||
--op_count_;
|
||||
|
||||
if (!err)
|
||||
{
|
||||
--unsent_count_;
|
||||
if (unsent_count_ == 1)
|
||||
{
|
||||
op_count_ += 2;
|
||||
std::swap(read_data_, write_data_);
|
||||
async_write(socket_, asio::buffer(write_data_, read_data_length_),
|
||||
asio::bind_executor(strand_,
|
||||
make_custom_alloc_handler(write_allocator_,
|
||||
boost::bind(&session::handle_write, this,
|
||||
asio::placeholders::error))));
|
||||
socket_.async_read_some(asio::buffer(read_data_, block_size_),
|
||||
asio::bind_executor(strand_,
|
||||
make_custom_alloc_handler(read_allocator_,
|
||||
boost::bind(&session::handle_read, this,
|
||||
asio::placeholders::error,
|
||||
asio::placeholders::bytes_transferred))));
|
||||
}
|
||||
}
|
||||
|
||||
if (op_count_ == 0)
|
||||
asio::post(io_context_, boost::bind(&session::destroy, this));
|
||||
}
|
||||
|
||||
static void destroy(session* s)
|
||||
{
|
||||
delete s;
|
||||
}
|
||||
|
||||
private:
|
||||
asio::io_context& io_context_;
|
||||
asio::io_context::strand strand_;
|
||||
asio::ip::tcp::socket socket_;
|
||||
size_t block_size_;
|
||||
char* read_data_;
|
||||
size_t read_data_length_;
|
||||
char* write_data_;
|
||||
int unsent_count_;
|
||||
int op_count_;
|
||||
handler_allocator read_allocator_;
|
||||
handler_allocator write_allocator_;
|
||||
};
|
||||
|
||||
class server
|
||||
{
|
||||
public:
|
||||
server(asio::io_context& ioc, const asio::ip::tcp::endpoint& endpoint,
|
||||
size_t block_size)
|
||||
: io_context_(ioc),
|
||||
acceptor_(ioc),
|
||||
block_size_(block_size)
|
||||
{
|
||||
acceptor_.open(endpoint.protocol());
|
||||
acceptor_.set_option(asio::ip::tcp::acceptor::reuse_address(1));
|
||||
acceptor_.bind(endpoint);
|
||||
acceptor_.listen();
|
||||
|
||||
start_accept();
|
||||
}
|
||||
|
||||
void start_accept()
|
||||
{
|
||||
session* new_session = new session(io_context_, block_size_);
|
||||
acceptor_.async_accept(new_session->socket(),
|
||||
boost::bind(&server::handle_accept, this, new_session,
|
||||
asio::placeholders::error));
|
||||
}
|
||||
|
||||
void handle_accept(session* new_session, const asio::error_code& err)
|
||||
{
|
||||
if (!err)
|
||||
{
|
||||
new_session->start();
|
||||
}
|
||||
else
|
||||
{
|
||||
delete new_session;
|
||||
}
|
||||
|
||||
start_accept();
|
||||
}
|
||||
|
||||
private:
|
||||
asio::io_context& io_context_;
|
||||
asio::ip::tcp::acceptor acceptor_;
|
||||
size_t block_size_;
|
||||
};
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
try
|
||||
{
|
||||
if (argc != 5)
|
||||
{
|
||||
std::cerr << "Usage: server <address> <port> <threads> <blocksize>\n";
|
||||
return 1;
|
||||
}
|
||||
|
||||
using namespace std; // For atoi.
|
||||
asio::ip::address address = asio::ip::make_address(argv[1]);
|
||||
short port = atoi(argv[2]);
|
||||
int thread_count = atoi(argv[3]);
|
||||
size_t block_size = atoi(argv[4]);
|
||||
|
||||
asio::io_context ioc;
|
||||
|
||||
server s(ioc, asio::ip::tcp::endpoint(address, port), block_size);
|
||||
|
||||
// Threads not currently supported in this test.
|
||||
std::list<asio::thread*> threads;
|
||||
while (--thread_count > 0)
|
||||
{
|
||||
asio::thread* new_thread = new asio::thread(
|
||||
boost::bind(&asio::io_context::run, &ioc));
|
||||
threads.push_back(new_thread);
|
||||
}
|
||||
|
||||
ioc.run();
|
||||
|
||||
while (!threads.empty())
|
||||
{
|
||||
threads.front()->join();
|
||||
delete threads.front();
|
||||
threads.pop_front();
|
||||
}
|
||||
}
|
||||
catch (std::exception& e)
|
||||
{
|
||||
std::cerr << "Exception: " << e.what() << "\n";
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
.deps
|
||||
.dirstamp
|
||||
*.o
|
||||
*.obj
|
||||
*.exe
|
||||
*.ilk
|
||||
*.manifest
|
||||
*.pdb
|
||||
*.tds
|
||||
associated_allocator
|
||||
associated_executor
|
||||
async_result
|
||||
awaitable
|
||||
basic_datagram_socket
|
||||
basic_deadline_timer
|
||||
basic_raw_socket
|
||||
basic_seq_packet_socket
|
||||
basic_serial_port
|
||||
basic_signal_set
|
||||
basic_socket
|
||||
basic_socket_acceptor
|
||||
basic_stream_socket
|
||||
basic_streambuf
|
||||
basic_waitable_timer
|
||||
bind_executor
|
||||
buffer
|
||||
buffered_read_stream
|
||||
buffered_stream
|
||||
buffered_write_stream
|
||||
buffers_iterator
|
||||
co_spawn
|
||||
completion_condition
|
||||
compose
|
||||
connect
|
||||
coroutine
|
||||
deadline_timer
|
||||
defer
|
||||
detached
|
||||
dispatch
|
||||
error
|
||||
error_handler
|
||||
execution_context
|
||||
executor
|
||||
executor_work_guard
|
||||
high_resolution_timer
|
||||
io_context
|
||||
io_service
|
||||
is_read_buffered
|
||||
is_write_buffered
|
||||
packaged_task
|
||||
placeholders
|
||||
post
|
||||
read
|
||||
read_at
|
||||
read_until
|
||||
redirect_error
|
||||
serial_port
|
||||
serial_port_base
|
||||
signal_set
|
||||
socket_base
|
||||
steady_timer
|
||||
strand
|
||||
streambuf
|
||||
system_context
|
||||
system_executor
|
||||
system_timer
|
||||
this_coro
|
||||
thread
|
||||
time_traits
|
||||
use_awaitable
|
||||
use_future
|
||||
uses_executor
|
||||
wait_traits
|
||||
write
|
||||
write_at
|
||||
@@ -0,0 +1,415 @@
|
||||
//
|
||||
// async_ops.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 ARCHETYPES_ASYNC_OPS_HPP
|
||||
#define ARCHETYPES_ASYNC_OPS_HPP
|
||||
|
||||
#include <asio/associated_allocator.hpp>
|
||||
#include <asio/associated_executor.hpp>
|
||||
#include <asio/async_result.hpp>
|
||||
#include <asio/error.hpp>
|
||||
|
||||
#if defined(ASIO_HAS_BOOST_BIND)
|
||||
# include <boost/bind.hpp>
|
||||
#else // defined(ASIO_HAS_BOOST_BIND)
|
||||
# include <functional>
|
||||
#endif // defined(ASIO_HAS_BOOST_BIND)
|
||||
|
||||
namespace archetypes {
|
||||
|
||||
#if defined(ASIO_HAS_BOOST_BIND)
|
||||
namespace bindns = boost;
|
||||
#else // defined(ASIO_HAS_BOOST_BIND)
|
||||
namespace bindns = std;
|
||||
#endif // defined(ASIO_HAS_BOOST_BIND)
|
||||
|
||||
template <typename CompletionToken>
|
||||
ASIO_INITFN_RESULT_TYPE(CompletionToken, void())
|
||||
async_op_0(ASIO_MOVE_ARG(CompletionToken) token)
|
||||
{
|
||||
typedef typename asio::async_completion<CompletionToken,
|
||||
void()>::completion_handler_type handler_type;
|
||||
|
||||
asio::async_completion<CompletionToken,
|
||||
void()> completion(token);
|
||||
|
||||
typename asio::associated_allocator<handler_type>::type a
|
||||
= asio::get_associated_allocator(completion.completion_handler);
|
||||
|
||||
typename asio::associated_executor<handler_type>::type ex
|
||||
= asio::get_associated_executor(completion.completion_handler);
|
||||
|
||||
ex.post(ASIO_MOVE_CAST(handler_type)(completion.completion_handler), a);
|
||||
|
||||
return completion.result.get();
|
||||
}
|
||||
|
||||
template <typename CompletionToken>
|
||||
ASIO_INITFN_RESULT_TYPE(CompletionToken, void(asio::error_code))
|
||||
async_op_ec_0(bool ok, ASIO_MOVE_ARG(CompletionToken) token)
|
||||
{
|
||||
typedef typename asio::async_completion<CompletionToken,
|
||||
void(asio::error_code)>::completion_handler_type handler_type;
|
||||
|
||||
asio::async_completion<CompletionToken,
|
||||
void(asio::error_code)> completion(token);
|
||||
|
||||
typename asio::associated_allocator<handler_type>::type a
|
||||
= asio::get_associated_allocator(completion.completion_handler);
|
||||
|
||||
typename asio::associated_executor<handler_type>::type ex
|
||||
= asio::get_associated_executor(completion.completion_handler);
|
||||
|
||||
if (ok)
|
||||
{
|
||||
ex.post(
|
||||
bindns::bind(
|
||||
ASIO_MOVE_CAST(handler_type)(completion.completion_handler),
|
||||
asio::error_code()), a);
|
||||
}
|
||||
else
|
||||
{
|
||||
ex.post(
|
||||
bindns::bind(
|
||||
ASIO_MOVE_CAST(handler_type)(completion.completion_handler),
|
||||
asio::error_code(asio::error::operation_aborted)), a);
|
||||
}
|
||||
|
||||
return completion.result.get();
|
||||
}
|
||||
|
||||
template <typename CompletionToken>
|
||||
ASIO_INITFN_RESULT_TYPE(CompletionToken, void(std::exception_ptr))
|
||||
async_op_ex_0(bool ok, ASIO_MOVE_ARG(CompletionToken) token)
|
||||
{
|
||||
typedef typename asio::async_completion<CompletionToken,
|
||||
void(std::exception_ptr)>::completion_handler_type handler_type;
|
||||
|
||||
asio::async_completion<CompletionToken,
|
||||
void(std::exception_ptr)> completion(token);
|
||||
|
||||
typename asio::associated_allocator<handler_type>::type a
|
||||
= asio::get_associated_allocator(completion.completion_handler);
|
||||
|
||||
typename asio::associated_executor<handler_type>::type ex
|
||||
= asio::get_associated_executor(completion.completion_handler);
|
||||
|
||||
if (ok)
|
||||
{
|
||||
ex.post(
|
||||
bindns::bind(
|
||||
ASIO_MOVE_CAST(handler_type)(completion.completion_handler),
|
||||
std::exception_ptr()), a);
|
||||
}
|
||||
else
|
||||
{
|
||||
ex.post(
|
||||
bindns::bind(
|
||||
ASIO_MOVE_CAST(handler_type)(completion.completion_handler),
|
||||
std::make_exception_ptr(std::runtime_error("blah"))), a);
|
||||
}
|
||||
|
||||
return completion.result.get();
|
||||
}
|
||||
|
||||
template <typename CompletionToken>
|
||||
ASIO_INITFN_RESULT_TYPE(CompletionToken, void(int))
|
||||
async_op_1(ASIO_MOVE_ARG(CompletionToken) token)
|
||||
{
|
||||
typedef typename asio::async_completion<CompletionToken,
|
||||
void(int)>::completion_handler_type handler_type;
|
||||
|
||||
asio::async_completion<CompletionToken,
|
||||
void(int)> completion(token);
|
||||
|
||||
typename asio::associated_allocator<handler_type>::type a
|
||||
= asio::get_associated_allocator(completion.completion_handler);
|
||||
|
||||
typename asio::associated_executor<handler_type>::type ex
|
||||
= asio::get_associated_executor(completion.completion_handler);
|
||||
|
||||
ex.post(
|
||||
bindns::bind(
|
||||
ASIO_MOVE_CAST(handler_type)(completion.completion_handler),
|
||||
42), a);
|
||||
|
||||
return completion.result.get();
|
||||
}
|
||||
|
||||
template <typename CompletionToken>
|
||||
ASIO_INITFN_RESULT_TYPE(CompletionToken,
|
||||
void(asio::error_code, int))
|
||||
async_op_ec_1(bool ok, ASIO_MOVE_ARG(CompletionToken) token)
|
||||
{
|
||||
typedef typename asio::async_completion<CompletionToken,
|
||||
void(asio::error_code, int)>::completion_handler_type
|
||||
handler_type;
|
||||
|
||||
asio::async_completion<CompletionToken,
|
||||
void(asio::error_code, int)> completion(token);
|
||||
|
||||
typename asio::associated_allocator<handler_type>::type a
|
||||
= asio::get_associated_allocator(completion.completion_handler);
|
||||
|
||||
typename asio::associated_executor<handler_type>::type ex
|
||||
= asio::get_associated_executor(completion.completion_handler);
|
||||
|
||||
if (ok)
|
||||
{
|
||||
ex.post(
|
||||
bindns::bind(
|
||||
ASIO_MOVE_CAST(handler_type)(completion.completion_handler),
|
||||
asio::error_code(), 42), a);
|
||||
}
|
||||
else
|
||||
{
|
||||
ex.post(
|
||||
bindns::bind(
|
||||
ASIO_MOVE_CAST(handler_type)(completion.completion_handler),
|
||||
asio::error_code(asio::error::operation_aborted),
|
||||
0), a);
|
||||
}
|
||||
|
||||
return completion.result.get();
|
||||
}
|
||||
|
||||
template <typename CompletionToken>
|
||||
ASIO_INITFN_RESULT_TYPE(CompletionToken, void(std::exception_ptr, int))
|
||||
async_op_ex_1(bool ok, ASIO_MOVE_ARG(CompletionToken) token)
|
||||
{
|
||||
typedef typename asio::async_completion<CompletionToken,
|
||||
void(std::exception_ptr, int)>::completion_handler_type
|
||||
handler_type;
|
||||
|
||||
asio::async_completion<CompletionToken,
|
||||
void(std::exception_ptr, int)> completion(token);
|
||||
|
||||
typename asio::associated_allocator<handler_type>::type a
|
||||
= asio::get_associated_allocator(completion.completion_handler);
|
||||
|
||||
typename asio::associated_executor<handler_type>::type ex
|
||||
= asio::get_associated_executor(completion.completion_handler);
|
||||
|
||||
if (ok)
|
||||
{
|
||||
ex.post(
|
||||
bindns::bind(
|
||||
ASIO_MOVE_CAST(handler_type)(completion.completion_handler),
|
||||
std::exception_ptr(), 42), a);
|
||||
}
|
||||
else
|
||||
{
|
||||
ex.post(
|
||||
bindns::bind(
|
||||
ASIO_MOVE_CAST(handler_type)(completion.completion_handler),
|
||||
std::make_exception_ptr(std::runtime_error("blah")), 0), a);
|
||||
}
|
||||
|
||||
return completion.result.get();
|
||||
}
|
||||
|
||||
template <typename CompletionToken>
|
||||
ASIO_INITFN_RESULT_TYPE(CompletionToken, void(int, double))
|
||||
async_op_2(ASIO_MOVE_ARG(CompletionToken) token)
|
||||
{
|
||||
typedef typename asio::async_completion<CompletionToken,
|
||||
void(int, double)>::completion_handler_type handler_type;
|
||||
|
||||
asio::async_completion<CompletionToken,
|
||||
void(int, double)> completion(token);
|
||||
|
||||
typename asio::associated_allocator<handler_type>::type a
|
||||
= asio::get_associated_allocator(completion.completion_handler);
|
||||
|
||||
typename asio::associated_executor<handler_type>::type ex
|
||||
= asio::get_associated_executor(completion.completion_handler);
|
||||
|
||||
ex.post(
|
||||
bindns::bind(
|
||||
ASIO_MOVE_CAST(handler_type)(completion.completion_handler),
|
||||
42, 2.0), a);
|
||||
|
||||
return completion.result.get();
|
||||
}
|
||||
|
||||
template <typename CompletionToken>
|
||||
ASIO_INITFN_RESULT_TYPE(CompletionToken,
|
||||
void(asio::error_code, int, double))
|
||||
async_op_ec_2(bool ok, ASIO_MOVE_ARG(CompletionToken) token)
|
||||
{
|
||||
typedef typename asio::async_completion<CompletionToken,
|
||||
void(asio::error_code, int, double)>::completion_handler_type
|
||||
handler_type;
|
||||
|
||||
asio::async_completion<CompletionToken,
|
||||
void(asio::error_code, int, double)> completion(token);
|
||||
|
||||
typename asio::associated_allocator<handler_type>::type a
|
||||
= asio::get_associated_allocator(completion.completion_handler);
|
||||
|
||||
typename asio::associated_executor<handler_type>::type ex
|
||||
= asio::get_associated_executor(completion.completion_handler);
|
||||
|
||||
if (ok)
|
||||
{
|
||||
ex.post(
|
||||
bindns::bind(
|
||||
ASIO_MOVE_CAST(handler_type)(completion.completion_handler),
|
||||
asio::error_code(), 42, 2.0), a);
|
||||
}
|
||||
else
|
||||
{
|
||||
ex.post(
|
||||
bindns::bind(
|
||||
ASIO_MOVE_CAST(handler_type)(completion.completion_handler),
|
||||
asio::error_code(asio::error::operation_aborted),
|
||||
0, 0.0), a);
|
||||
}
|
||||
|
||||
return completion.result.get();
|
||||
}
|
||||
|
||||
template <typename CompletionToken>
|
||||
ASIO_INITFN_RESULT_TYPE(CompletionToken,
|
||||
void(std::exception_ptr, int, double))
|
||||
async_op_ex_2(bool ok, ASIO_MOVE_ARG(CompletionToken) token)
|
||||
{
|
||||
typedef typename asio::async_completion<CompletionToken,
|
||||
void(std::exception_ptr, int, double)>::completion_handler_type
|
||||
handler_type;
|
||||
|
||||
asio::async_completion<CompletionToken,
|
||||
void(std::exception_ptr, int, double)> completion(token);
|
||||
|
||||
typename asio::associated_allocator<handler_type>::type a
|
||||
= asio::get_associated_allocator(completion.completion_handler);
|
||||
|
||||
typename asio::associated_executor<handler_type>::type ex
|
||||
= asio::get_associated_executor(completion.completion_handler);
|
||||
|
||||
if (ok)
|
||||
{
|
||||
ex.post(
|
||||
bindns::bind(
|
||||
ASIO_MOVE_CAST(handler_type)(completion.completion_handler),
|
||||
std::exception_ptr(), 42, 2.0), a);
|
||||
}
|
||||
else
|
||||
{
|
||||
ex.post(
|
||||
bindns::bind(
|
||||
ASIO_MOVE_CAST(handler_type)(completion.completion_handler),
|
||||
std::make_exception_ptr(std::runtime_error("blah")), 0, 0.0), a);
|
||||
}
|
||||
|
||||
return completion.result.get();
|
||||
}
|
||||
|
||||
template <typename CompletionToken>
|
||||
ASIO_INITFN_RESULT_TYPE(CompletionToken, void(int, double, char))
|
||||
async_op_3(ASIO_MOVE_ARG(CompletionToken) token)
|
||||
{
|
||||
typedef typename asio::async_completion<CompletionToken,
|
||||
void(int, double, char)>::completion_handler_type handler_type;
|
||||
|
||||
asio::async_completion<CompletionToken,
|
||||
void(int, double, char)> completion(token);
|
||||
|
||||
typename asio::associated_allocator<handler_type>::type a
|
||||
= asio::get_associated_allocator(completion.completion_handler);
|
||||
|
||||
typename asio::associated_executor<handler_type>::type ex
|
||||
= asio::get_associated_executor(completion.completion_handler);
|
||||
|
||||
ex.post(
|
||||
bindns::bind(
|
||||
ASIO_MOVE_CAST(handler_type)(completion.completion_handler),
|
||||
42, 2.0, 'a'), a);
|
||||
|
||||
return completion.result.get();
|
||||
}
|
||||
|
||||
template <typename CompletionToken>
|
||||
ASIO_INITFN_RESULT_TYPE(CompletionToken,
|
||||
void(asio::error_code, int, double, char))
|
||||
async_op_ec_3(bool ok, ASIO_MOVE_ARG(CompletionToken) token)
|
||||
{
|
||||
typedef typename asio::async_completion<CompletionToken,
|
||||
void(asio::error_code, int, double, char)>::completion_handler_type
|
||||
handler_type;
|
||||
|
||||
asio::async_completion<CompletionToken,
|
||||
void(asio::error_code, int, double, char)> completion(token);
|
||||
|
||||
typename asio::associated_allocator<handler_type>::type a
|
||||
= asio::get_associated_allocator(completion.completion_handler);
|
||||
|
||||
typename asio::associated_executor<handler_type>::type ex
|
||||
= asio::get_associated_executor(completion.completion_handler);
|
||||
|
||||
if (ok)
|
||||
{
|
||||
ex.post(
|
||||
bindns::bind(
|
||||
ASIO_MOVE_CAST(handler_type)(completion.completion_handler),
|
||||
asio::error_code(), 42, 2.0, 'a'), a);
|
||||
}
|
||||
else
|
||||
{
|
||||
ex.post(
|
||||
bindns::bind(
|
||||
ASIO_MOVE_CAST(handler_type)(completion.completion_handler),
|
||||
asio::error_code(asio::error::operation_aborted),
|
||||
0, 0.0, 'z'), a);
|
||||
}
|
||||
|
||||
return completion.result.get();
|
||||
}
|
||||
|
||||
template <typename CompletionToken>
|
||||
ASIO_INITFN_RESULT_TYPE(CompletionToken,
|
||||
void(std::exception_ptr, int, double, char))
|
||||
async_op_ex_3(bool ok, ASIO_MOVE_ARG(CompletionToken) token)
|
||||
{
|
||||
typedef typename asio::async_completion<CompletionToken,
|
||||
void(std::exception_ptr, int, double, char)>::completion_handler_type
|
||||
handler_type;
|
||||
|
||||
asio::async_completion<CompletionToken,
|
||||
void(std::exception_ptr, int, double, char)> completion(token);
|
||||
|
||||
typename asio::associated_allocator<handler_type>::type a
|
||||
= asio::get_associated_allocator(completion.completion_handler);
|
||||
|
||||
typename asio::associated_executor<handler_type>::type ex
|
||||
= asio::get_associated_executor(completion.completion_handler);
|
||||
|
||||
if (ok)
|
||||
{
|
||||
ex.post(
|
||||
bindns::bind(
|
||||
ASIO_MOVE_CAST(handler_type)(completion.completion_handler),
|
||||
std::exception_ptr(), 42, 2.0, 'a'), a);
|
||||
}
|
||||
else
|
||||
{
|
||||
ex.post(
|
||||
bindns::bind(
|
||||
ASIO_MOVE_CAST(handler_type)(completion.completion_handler),
|
||||
std::make_exception_ptr(std::runtime_error("blah")),
|
||||
0, 0.0, 'z'), a);
|
||||
}
|
||||
|
||||
return completion.result.get();
|
||||
}
|
||||
|
||||
} // namespace archetypes
|
||||
|
||||
#endif // ARCHETYPES_ASYNC_OPS_HPP
|
||||
@@ -0,0 +1,94 @@
|
||||
//
|
||||
// async_result.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 ARCHETYPES_ASYNC_RESULT_HPP
|
||||
#define ARCHETYPES_ASYNC_RESULT_HPP
|
||||
|
||||
#include <asio/async_result.hpp>
|
||||
|
||||
namespace archetypes {
|
||||
|
||||
struct lazy_handler
|
||||
{
|
||||
};
|
||||
|
||||
template <typename Signature>
|
||||
struct concrete_handler;
|
||||
|
||||
template <typename R, typename Arg1>
|
||||
struct concrete_handler<R(Arg1)>
|
||||
{
|
||||
concrete_handler(lazy_handler)
|
||||
{
|
||||
}
|
||||
|
||||
void operator()(typename asio::decay<Arg1>::type)
|
||||
{
|
||||
}
|
||||
|
||||
#if defined(ASIO_HAS_MOVE)
|
||||
concrete_handler(concrete_handler&&) {}
|
||||
private:
|
||||
concrete_handler(const concrete_handler&);
|
||||
#endif // defined(ASIO_HAS_MOVE)
|
||||
};
|
||||
|
||||
template <typename R, typename Arg1, typename Arg2>
|
||||
struct concrete_handler<R(Arg1, Arg2)>
|
||||
{
|
||||
concrete_handler(lazy_handler)
|
||||
{
|
||||
}
|
||||
|
||||
void operator()(typename asio::decay<Arg1>::type, typename asio::decay<Arg2>::type)
|
||||
{
|
||||
}
|
||||
|
||||
#if defined(ASIO_HAS_MOVE)
|
||||
concrete_handler(concrete_handler&&) {}
|
||||
private:
|
||||
concrete_handler(const concrete_handler&);
|
||||
#endif // defined(ASIO_HAS_MOVE)
|
||||
};
|
||||
|
||||
} // namespace archetypes
|
||||
|
||||
namespace asio {
|
||||
|
||||
template <typename Signature>
|
||||
class async_result<archetypes::lazy_handler, Signature>
|
||||
{
|
||||
public:
|
||||
// The concrete completion handler type.
|
||||
typedef archetypes::concrete_handler<Signature> completion_handler_type;
|
||||
|
||||
// The return type of the initiating function.
|
||||
typedef int return_type;
|
||||
|
||||
// Construct an async_result from a given handler.
|
||||
explicit async_result(completion_handler_type&)
|
||||
{
|
||||
}
|
||||
|
||||
// Obtain the value to be returned from the initiating function.
|
||||
return_type get()
|
||||
{
|
||||
return 42;
|
||||
}
|
||||
|
||||
private:
|
||||
// Disallow copying and assignment.
|
||||
async_result(const async_result&) ASIO_DELETED;
|
||||
async_result& operator=(const async_result&) ASIO_DELETED;
|
||||
};
|
||||
|
||||
} // namespace asio
|
||||
|
||||
#endif // ARCHETYPES_ASYNC_RESULT_HPP
|
||||
@@ -0,0 +1,54 @@
|
||||
//
|
||||
// gettable_socket_option.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 ARCHETYPES_GETTABLE_SOCKET_OPTION_HPP
|
||||
#define ARCHETYPES_GETTABLE_SOCKET_OPTION_HPP
|
||||
|
||||
#include <cstddef>
|
||||
|
||||
namespace archetypes {
|
||||
|
||||
template <typename PointerType>
|
||||
class gettable_socket_option
|
||||
{
|
||||
public:
|
||||
template <typename Protocol>
|
||||
int level(const Protocol&) const
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
template <typename Protocol>
|
||||
int name(const Protocol&) const
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
template <typename Protocol>
|
||||
PointerType* data(const Protocol&)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
template <typename Protocol>
|
||||
std::size_t size(const Protocol&) const
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
template <typename Protocol>
|
||||
void resize(const Protocol&, std::size_t)
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace archetypes
|
||||
|
||||
#endif // ARCHETYPES_GETTABLE_SOCKET_OPTION_HPP
|
||||
@@ -0,0 +1,32 @@
|
||||
//
|
||||
// io_control_command.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 ARCHETYPES_IO_CONTROL_COMMAND_HPP
|
||||
#define ARCHETYPES_IO_CONTROL_COMMAND_HPP
|
||||
|
||||
namespace archetypes {
|
||||
|
||||
class io_control_command
|
||||
{
|
||||
public:
|
||||
int name() const
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
void* data()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace archetypes
|
||||
|
||||
#endif // ARCHETYPES_IO_CONTROL_COMMAND_HPP
|
||||
@@ -0,0 +1,49 @@
|
||||
//
|
||||
// settable_socket_option.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 ARCHETYPES_SETTABLE_SOCKET_OPTION_HPP
|
||||
#define ARCHETYPES_SETTABLE_SOCKET_OPTION_HPP
|
||||
|
||||
#include <cstddef>
|
||||
|
||||
namespace archetypes {
|
||||
|
||||
template <typename PointerType>
|
||||
class settable_socket_option
|
||||
{
|
||||
public:
|
||||
template <typename Protocol>
|
||||
int level(const Protocol&) const
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
template <typename Protocol>
|
||||
int name(const Protocol&) const
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
template <typename Protocol>
|
||||
const PointerType* data(const Protocol&) const
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
template <typename Protocol>
|
||||
std::size_t size(const Protocol&) const
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace archetypes
|
||||
|
||||
#endif // ARCHETYPES_SETTABLE_SOCKET_OPTION_HPP
|
||||
@@ -0,0 +1,25 @@
|
||||
//
|
||||
// associated_allocator.cpp
|
||||
// ~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
//
|
||||
// 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)
|
||||
//
|
||||
|
||||
// Disable autolinking for unit tests.
|
||||
#if !defined(BOOST_ALL_NO_LIB)
|
||||
#define BOOST_ALL_NO_LIB 1
|
||||
#endif // !defined(BOOST_ALL_NO_LIB)
|
||||
|
||||
// Test that header file is self-contained.
|
||||
#include "asio/associated_allocator.hpp"
|
||||
|
||||
#include "unit_test.hpp"
|
||||
|
||||
ASIO_TEST_SUITE
|
||||
(
|
||||
"associated_allocator",
|
||||
ASIO_TEST_CASE(null_test)
|
||||
)
|
||||
@@ -0,0 +1,25 @@
|
||||
//
|
||||
// associated_executor.cpp
|
||||
// ~~~~~~~~~~~~~~~~~~~~~~~
|
||||
//
|
||||
// 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)
|
||||
//
|
||||
|
||||
// Disable autolinking for unit tests.
|
||||
#if !defined(BOOST_ALL_NO_LIB)
|
||||
#define BOOST_ALL_NO_LIB 1
|
||||
#endif // !defined(BOOST_ALL_NO_LIB)
|
||||
|
||||
// Test that header file is self-contained.
|
||||
#include "asio/associated_executor.hpp"
|
||||
|
||||
#include "unit_test.hpp"
|
||||
|
||||
ASIO_TEST_SUITE
|
||||
(
|
||||
"associated_executor",
|
||||
ASIO_TEST_CASE(null_test)
|
||||
)
|
||||
@@ -0,0 +1,25 @@
|
||||
//
|
||||
// async_result.cpp
|
||||
// ~~~~~~~~~~~~~~~~
|
||||
//
|
||||
// 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)
|
||||
//
|
||||
|
||||
// Disable autolinking for unit tests.
|
||||
#if !defined(BOOST_ALL_NO_LIB)
|
||||
#define BOOST_ALL_NO_LIB 1
|
||||
#endif // !defined(BOOST_ALL_NO_LIB)
|
||||
|
||||
// Test that header file is self-contained.
|
||||
#include "asio/async_result.hpp"
|
||||
|
||||
#include "unit_test.hpp"
|
||||
|
||||
ASIO_TEST_SUITE
|
||||
(
|
||||
"async_result",
|
||||
ASIO_TEST_CASE(null_test)
|
||||
)
|
||||
@@ -0,0 +1,25 @@
|
||||
//
|
||||
// awaitable.cpp
|
||||
// ~~~~~~~~~~~~~
|
||||
//
|
||||
// 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)
|
||||
//
|
||||
|
||||
// Disable autolinking for unit tests.
|
||||
#if !defined(BOOST_ALL_NO_LIB)
|
||||
#define BOOST_ALL_NO_LIB 1
|
||||
#endif // !defined(BOOST_ALL_NO_LIB)
|
||||
|
||||
// Test that header file is self-contained.
|
||||
#include "asio/awaitable.hpp"
|
||||
|
||||
#include "unit_test.hpp"
|
||||
|
||||
ASIO_TEST_SUITE
|
||||
(
|
||||
"awaitable",
|
||||
ASIO_TEST_CASE(null_test)
|
||||
)
|
||||
@@ -0,0 +1,25 @@
|
||||
//
|
||||
// basic_datagram_socket.cpp
|
||||
// ~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
//
|
||||
// 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)
|
||||
//
|
||||
|
||||
// Disable autolinking for unit tests.
|
||||
#if !defined(BOOST_ALL_NO_LIB)
|
||||
#define BOOST_ALL_NO_LIB 1
|
||||
#endif // !defined(BOOST_ALL_NO_LIB)
|
||||
|
||||
// Test that header file is self-contained.
|
||||
#include "asio/basic_datagram_socket.hpp"
|
||||
|
||||
#include "unit_test.hpp"
|
||||
|
||||
ASIO_TEST_SUITE
|
||||
(
|
||||
"basic_datagram_socket",
|
||||
ASIO_TEST_CASE(null_test)
|
||||
)
|
||||
@@ -0,0 +1,25 @@
|
||||
//
|
||||
// basic_deadline_timer.cpp
|
||||
// ~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
//
|
||||
// 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)
|
||||
//
|
||||
|
||||
// Disable autolinking for unit tests.
|
||||
#if !defined(BOOST_ALL_NO_LIB)
|
||||
#define BOOST_ALL_NO_LIB 1
|
||||
#endif // !defined(BOOST_ALL_NO_LIB)
|
||||
|
||||
// Test that header file is self-contained.
|
||||
#include "asio/basic_deadline_timer.hpp"
|
||||
|
||||
#include "unit_test.hpp"
|
||||
|
||||
ASIO_TEST_SUITE
|
||||
(
|
||||
"basic_deadline_timer",
|
||||
ASIO_TEST_CASE(null_test)
|
||||
)
|
||||
@@ -0,0 +1,25 @@
|
||||
//
|
||||
// basic_raw_socket.cpp
|
||||
// ~~~~~~~~~~~~~~~~~~~~
|
||||
//
|
||||
// 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)
|
||||
//
|
||||
|
||||
// Disable autolinking for unit tests.
|
||||
#if !defined(BOOST_ALL_NO_LIB)
|
||||
#define BOOST_ALL_NO_LIB 1
|
||||
#endif // !defined(BOOST_ALL_NO_LIB)
|
||||
|
||||
// Test that header file is self-contained.
|
||||
#include "asio/basic_raw_socket.hpp"
|
||||
|
||||
#include "unit_test.hpp"
|
||||
|
||||
ASIO_TEST_SUITE
|
||||
(
|
||||
"basic_raw_socket",
|
||||
ASIO_TEST_CASE(null_test)
|
||||
)
|
||||
@@ -0,0 +1,25 @@
|
||||
//
|
||||
// basic_seq_packet_socket.cpp
|
||||
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
//
|
||||
// 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)
|
||||
//
|
||||
|
||||
// Disable autolinking for unit tests.
|
||||
#if !defined(BOOST_ALL_NO_LIB)
|
||||
#define BOOST_ALL_NO_LIB 1
|
||||
#endif // !defined(BOOST_ALL_NO_LIB)
|
||||
|
||||
// Test that header file is self-contained.
|
||||
#include "asio/basic_seq_packet_socket.hpp"
|
||||
|
||||
#include "unit_test.hpp"
|
||||
|
||||
ASIO_TEST_SUITE
|
||||
(
|
||||
"basic_seq_packet_socket",
|
||||
ASIO_TEST_CASE(null_test)
|
||||
)
|
||||
@@ -0,0 +1,26 @@
|
||||
//
|
||||
// basic_serial_port.cpp
|
||||
// ~~~~~~~~~~~~~~~~~~~~~
|
||||
//
|
||||
// Copyright (c) 2003-2019 Christopher M. Kohlhoff (chris at kohlhoff dot com)
|
||||
// Copyright (c) 2008 Rep Invariant Systems, Inc. (info@repinvariant.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)
|
||||
//
|
||||
|
||||
// Disable autolinking for unit tests.
|
||||
#if !defined(BOOST_ALL_NO_LIB)
|
||||
#define BOOST_ALL_NO_LIB 1
|
||||
#endif // !defined(BOOST_ALL_NO_LIB)
|
||||
|
||||
// Test that header file is self-contained.
|
||||
#include "asio/basic_serial_port.hpp"
|
||||
|
||||
#include "unit_test.hpp"
|
||||
|
||||
ASIO_TEST_SUITE
|
||||
(
|
||||
"basic_serial_port",
|
||||
ASIO_TEST_CASE(null_test)
|
||||
)
|
||||
@@ -0,0 +1,25 @@
|
||||
//
|
||||
// basic_signal_set.cpp
|
||||
// ~~~~~~~~~~~~~~~~~~~~
|
||||
//
|
||||
// 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)
|
||||
//
|
||||
|
||||
// Disable autolinking for unit tests.
|
||||
#if !defined(BOOST_ALL_NO_LIB)
|
||||
#define BOOST_ALL_NO_LIB 1
|
||||
#endif // !defined(BOOST_ALL_NO_LIB)
|
||||
|
||||
// Test that header file is self-contained.
|
||||
#include "asio/basic_signal_set.hpp"
|
||||
|
||||
#include "unit_test.hpp"
|
||||
|
||||
ASIO_TEST_SUITE
|
||||
(
|
||||
"basic_signal_set",
|
||||
ASIO_TEST_CASE(null_test)
|
||||
)
|
||||
@@ -0,0 +1,25 @@
|
||||
//
|
||||
// basic_socket.cpp
|
||||
// ~~~~~~~~~~~~~~~~
|
||||
//
|
||||
// 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)
|
||||
//
|
||||
|
||||
// Disable autolinking for unit tests.
|
||||
#if !defined(BOOST_ALL_NO_LIB)
|
||||
#define BOOST_ALL_NO_LIB 1
|
||||
#endif // !defined(BOOST_ALL_NO_LIB)
|
||||
|
||||
// Test that header file is self-contained.
|
||||
#include "asio/basic_socket.hpp"
|
||||
|
||||
#include "unit_test.hpp"
|
||||
|
||||
ASIO_TEST_SUITE
|
||||
(
|
||||
"basic_socket",
|
||||
ASIO_TEST_CASE(null_test)
|
||||
)
|
||||
@@ -0,0 +1,25 @@
|
||||
//
|
||||
// basic_socket_acceptor.cpp
|
||||
// ~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
//
|
||||
// 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)
|
||||
//
|
||||
|
||||
// Disable autolinking for unit tests.
|
||||
#if !defined(BOOST_ALL_NO_LIB)
|
||||
#define BOOST_ALL_NO_LIB 1
|
||||
#endif // !defined(BOOST_ALL_NO_LIB)
|
||||
|
||||
// Test that header file is self-contained.
|
||||
#include "asio/basic_socket_acceptor.hpp"
|
||||
|
||||
#include "unit_test.hpp"
|
||||
|
||||
ASIO_TEST_SUITE
|
||||
(
|
||||
"basic_socket_acceptor",
|
||||
ASIO_TEST_CASE(null_test)
|
||||
)
|
||||
@@ -0,0 +1,25 @@
|
||||
//
|
||||
// basic_stream_socket.cpp
|
||||
// ~~~~~~~~~~~~~~~~~~~~~~~
|
||||
//
|
||||
// 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)
|
||||
//
|
||||
|
||||
// Disable autolinking for unit tests.
|
||||
#if !defined(BOOST_ALL_NO_LIB)
|
||||
#define BOOST_ALL_NO_LIB 1
|
||||
#endif // !defined(BOOST_ALL_NO_LIB)
|
||||
|
||||
// Test that header file is self-contained.
|
||||
#include "asio/basic_stream_socket.hpp"
|
||||
|
||||
#include "unit_test.hpp"
|
||||
|
||||
ASIO_TEST_SUITE
|
||||
(
|
||||
"basic_stream_socket",
|
||||
ASIO_TEST_CASE(null_test)
|
||||
)
|
||||
@@ -0,0 +1,25 @@
|
||||
//
|
||||
// basic_streambuf.cpp
|
||||
// ~~~~~~~~~~~~~~~~~~~
|
||||
//
|
||||
// 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)
|
||||
//
|
||||
|
||||
// Disable autolinking for unit tests.
|
||||
#if !defined(BOOST_ALL_NO_LIB)
|
||||
#define BOOST_ALL_NO_LIB 1
|
||||
#endif // !defined(BOOST_ALL_NO_LIB)
|
||||
|
||||
// Test that header file is self-contained.
|
||||
#include "asio/basic_streambuf.hpp"
|
||||
|
||||
#include "unit_test.hpp"
|
||||
|
||||
ASIO_TEST_SUITE
|
||||
(
|
||||
"basic_streambuf",
|
||||
ASIO_TEST_CASE(null_test)
|
||||
)
|
||||
@@ -0,0 +1,25 @@
|
||||
//
|
||||
// basic_waitable_timer.cpp
|
||||
// ~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
//
|
||||
// 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)
|
||||
//
|
||||
|
||||
// Disable autolinking for unit tests.
|
||||
#if !defined(BOOST_ALL_NO_LIB)
|
||||
#define BOOST_ALL_NO_LIB 1
|
||||
#endif // !defined(BOOST_ALL_NO_LIB)
|
||||
|
||||
// Test that header file is self-contained.
|
||||
#include "asio/basic_waitable_timer.hpp"
|
||||
|
||||
#include "unit_test.hpp"
|
||||
|
||||
ASIO_TEST_SUITE
|
||||
(
|
||||
"basic_waitable_timer",
|
||||
ASIO_TEST_CASE(null_test)
|
||||
)
|
||||
@@ -0,0 +1,25 @@
|
||||
//
|
||||
// bind_executor.cpp
|
||||
// ~~~~~~~~~~~~~~~~~
|
||||
//
|
||||
// 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)
|
||||
//
|
||||
|
||||
// Disable autolinking for unit tests.
|
||||
#if !defined(BOOST_ALL_NO_LIB)
|
||||
#define BOOST_ALL_NO_LIB 1
|
||||
#endif // !defined(BOOST_ALL_NO_LIB)
|
||||
|
||||
// Test that header file is self-contained.
|
||||
#include "asio/bind_executor.hpp"
|
||||
|
||||
#include "unit_test.hpp"
|
||||
|
||||
ASIO_TEST_SUITE
|
||||
(
|
||||
"bind_executor",
|
||||
ASIO_TEST_CASE(null_test)
|
||||
)
|
||||
@@ -0,0 +1,595 @@
|
||||
//
|
||||
// buffer.cpp
|
||||
// ~~~~~~~~~~
|
||||
//
|
||||
// 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)
|
||||
//
|
||||
|
||||
// Disable autolinking for unit tests.
|
||||
#if !defined(BOOST_ALL_NO_LIB)
|
||||
#define BOOST_ALL_NO_LIB 1
|
||||
#endif // !defined(BOOST_ALL_NO_LIB)
|
||||
|
||||
// Test that header file is self-contained.
|
||||
#include "asio/buffer.hpp"
|
||||
|
||||
#include "unit_test.hpp"
|
||||
|
||||
#if defined(ASIO_HAS_BOOST_ARRAY)
|
||||
# include <boost/array.hpp>
|
||||
#endif // defined(ASIO_HAS_BOOST_ARRAY)
|
||||
|
||||
#if defined(ASIO_HAS_STD_ARRAY)
|
||||
# include <array>
|
||||
#endif // defined(ASIO_HAS_STD_ARRAY)
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
// buffer_compile test
|
||||
// ~~~~~~~~~~~~~~~~~~~
|
||||
// The following test checks that all overloads of the buffer function compile
|
||||
// and link correctly. Runtime failures are ignored.
|
||||
|
||||
namespace buffer_compile {
|
||||
|
||||
using namespace asio;
|
||||
|
||||
void test()
|
||||
{
|
||||
try
|
||||
{
|
||||
char raw_data[1024];
|
||||
const char const_raw_data[1024] = "";
|
||||
void* void_ptr_data = raw_data;
|
||||
const void* const_void_ptr_data = const_raw_data;
|
||||
#if defined(ASIO_HAS_BOOST_ARRAY)
|
||||
boost::array<char, 1024> array_data;
|
||||
const boost::array<char, 1024>& const_array_data_1 = array_data;
|
||||
boost::array<const char, 1024> const_array_data_2 = { { 0 } };
|
||||
#endif // defined(ASIO_HAS_BOOST_ARRAY)
|
||||
#if defined(ASIO_HAS_STD_ARRAY)
|
||||
std::array<char, 1024> std_array_data;
|
||||
const std::array<char, 1024>& const_std_array_data_1 = std_array_data;
|
||||
std::array<const char, 1024> const_std_array_data_2 = { { 0 } };
|
||||
#endif // defined(ASIO_HAS_STD_ARRAY)
|
||||
std::vector<char> vector_data(1024);
|
||||
const std::vector<char>& const_vector_data = vector_data;
|
||||
std::string string_data(1024, ' ');
|
||||
const std::string const_string_data(1024, ' ');
|
||||
std::vector<mutable_buffer> mutable_buffer_sequence;
|
||||
std::vector<const_buffer> const_buffer_sequence;
|
||||
#if defined(ASIO_HAS_STD_STRING_VIEW)
|
||||
std::string_view string_view_data(string_data);
|
||||
#elif defined(ASIO_HAS_STD_EXPERIMENTAL_STRING_VIEW)
|
||||
std::experimental::string_view string_view_data(string_data);
|
||||
#endif // defined(ASIO_HAS_STD_EXPERIMENTAL_STRING_VIEW)
|
||||
|
||||
// mutable_buffer constructors.
|
||||
|
||||
mutable_buffer mb1;
|
||||
mutable_buffer mb2(void_ptr_data, 1024);
|
||||
mutable_buffer mb3(mb1);
|
||||
(void)mb3;
|
||||
|
||||
// mutable_buffer functions.
|
||||
|
||||
void* ptr1 = mb1.data();
|
||||
(void)ptr1;
|
||||
|
||||
std::size_t n1 = mb1.size();
|
||||
(void)n1;
|
||||
|
||||
// mutable_buffer operators.
|
||||
|
||||
mb1 += 128;
|
||||
mb1 = mb2 + 128;
|
||||
mb1 = 128 + mb2;
|
||||
|
||||
#if !defined(ASIO_NO_DEPRECATED)
|
||||
|
||||
// mutable_buffers_1 constructors.
|
||||
|
||||
mutable_buffers_1 mbc1(mb1);
|
||||
mutable_buffers_1 mbc2(mbc1);
|
||||
|
||||
// mutable_buffers_1 functions.
|
||||
|
||||
mutable_buffers_1::const_iterator iter1 = mbc1.begin();
|
||||
(void)iter1;
|
||||
mutable_buffers_1::const_iterator iter2 = mbc1.end();
|
||||
(void)iter2;
|
||||
|
||||
#endif // !defined(ASIO_NO_DEPRECATED)
|
||||
|
||||
// const_buffer constructors.
|
||||
|
||||
const_buffer cb1;
|
||||
const_buffer cb2(const_void_ptr_data, 1024);
|
||||
const_buffer cb3(cb1);
|
||||
(void)cb3;
|
||||
const_buffer cb4(mb1);
|
||||
(void)cb4;
|
||||
|
||||
// const_buffer functions.
|
||||
|
||||
const void* ptr2 = cb1.data();
|
||||
(void)ptr2;
|
||||
|
||||
std::size_t n2 = cb1.size();
|
||||
(void)n2;
|
||||
|
||||
// const_buffer operators.
|
||||
|
||||
cb1 += 128;
|
||||
cb1 = cb2 + 128;
|
||||
cb1 = 128 + cb2;
|
||||
|
||||
#if !defined(ASIO_NO_DEPRECATED)
|
||||
|
||||
// const_buffers_1 constructors.
|
||||
|
||||
const_buffers_1 cbc1(cb1);
|
||||
const_buffers_1 cbc2(cbc1);
|
||||
|
||||
// const_buffers_1 functions.
|
||||
|
||||
const_buffers_1::const_iterator iter3 = cbc1.begin();
|
||||
(void)iter3;
|
||||
const_buffers_1::const_iterator iter4 = cbc1.end();
|
||||
(void)iter4;
|
||||
|
||||
#endif // !defined(ASIO_NO_DEPRECATED)
|
||||
|
||||
// buffer_size function overloads.
|
||||
|
||||
std::size_t size1 = buffer_size(mb1);
|
||||
(void)size1;
|
||||
std::size_t size2 = buffer_size(cb1);
|
||||
(void)size2;
|
||||
#if !defined(ASIO_NO_DEPRECATED)
|
||||
std::size_t size3 = buffer_size(mbc1);
|
||||
(void)size3;
|
||||
std::size_t size4 = buffer_size(cbc1);
|
||||
(void)size4;
|
||||
#endif // !defined(ASIO_NO_DEPRECATED)
|
||||
std::size_t size5 = buffer_size(mutable_buffer_sequence);
|
||||
(void)size5;
|
||||
std::size_t size6 = buffer_size(const_buffer_sequence);
|
||||
(void)size6;
|
||||
|
||||
// buffer_cast function overloads.
|
||||
|
||||
#if !defined(ASIO_NO_DEPRECATED)
|
||||
void* ptr3 = buffer_cast<void*>(mb1);
|
||||
(void)ptr3;
|
||||
const void* ptr4 = buffer_cast<const void*>(cb1);
|
||||
(void)ptr4;
|
||||
#endif // !defined(ASIO_NO_DEPRECATED)
|
||||
|
||||
// buffer function overloads.
|
||||
|
||||
mb1 = buffer(mb2);
|
||||
mb1 = buffer(mb2, 128);
|
||||
cb1 = buffer(cb2);
|
||||
cb1 = buffer(cb2, 128);
|
||||
mb1 = buffer(void_ptr_data, 1024);
|
||||
cb1 = buffer(const_void_ptr_data, 1024);
|
||||
mb1 = buffer(raw_data);
|
||||
mb1 = buffer(raw_data, 1024);
|
||||
cb1 = buffer(const_raw_data);
|
||||
cb1 = buffer(const_raw_data, 1024);
|
||||
#if defined(ASIO_HAS_BOOST_ARRAY)
|
||||
mb1 = buffer(array_data);
|
||||
mb1 = buffer(array_data, 1024);
|
||||
cb1 = buffer(const_array_data_1);
|
||||
cb1 = buffer(const_array_data_1, 1024);
|
||||
cb1 = buffer(const_array_data_2);
|
||||
cb1 = buffer(const_array_data_2, 1024);
|
||||
#endif // defined(ASIO_HAS_BOOST_ARRAY)
|
||||
#if defined(ASIO_HAS_STD_ARRAY)
|
||||
mb1 = buffer(std_array_data);
|
||||
mb1 = buffer(std_array_data, 1024);
|
||||
cb1 = buffer(const_std_array_data_1);
|
||||
cb1 = buffer(const_std_array_data_1, 1024);
|
||||
cb1 = buffer(const_std_array_data_2);
|
||||
cb1 = buffer(const_std_array_data_2, 1024);
|
||||
#endif // defined(ASIO_HAS_STD_ARRAY)
|
||||
mb1 = buffer(vector_data);
|
||||
mb1 = buffer(vector_data, 1024);
|
||||
cb1 = buffer(const_vector_data);
|
||||
cb1 = buffer(const_vector_data, 1024);
|
||||
mb1 = buffer(string_data);
|
||||
mb1 = buffer(string_data, 1024);
|
||||
cb1 = buffer(const_string_data);
|
||||
cb1 = buffer(const_string_data, 1024);
|
||||
#if defined(ASIO_HAS_STRING_VIEW)
|
||||
cb1 = buffer(string_view_data);
|
||||
cb1 = buffer(string_view_data, 1024);
|
||||
#endif // defined(ASIO_HAS_STRING_VIEW)
|
||||
|
||||
// buffer_copy function overloads.
|
||||
|
||||
std::size_t size7 = buffer_copy(mb1, cb2);
|
||||
(void)size7;
|
||||
#if !defined(ASIO_NO_DEPRECATED)
|
||||
std::size_t size8 = buffer_copy(mb1, cbc2);
|
||||
(void)size8;
|
||||
#endif // !defined(ASIO_NO_DEPRECATED)
|
||||
std::size_t size9 = buffer_copy(mb1, mb2);
|
||||
(void)size9;
|
||||
#if !defined(ASIO_NO_DEPRECATED)
|
||||
std::size_t size10 = buffer_copy(mb1, mbc2);
|
||||
(void)size10;
|
||||
#endif // !defined(ASIO_NO_DEPRECATED)
|
||||
std::size_t size11 = buffer_copy(mb1, const_buffer_sequence);
|
||||
(void)size11;
|
||||
#if !defined(ASIO_NO_DEPRECATED)
|
||||
std::size_t size12 = buffer_copy(mbc1, cb2);
|
||||
(void)size12;
|
||||
std::size_t size13 = buffer_copy(mbc1, cbc2);
|
||||
(void)size13;
|
||||
std::size_t size14 = buffer_copy(mbc1, mb2);
|
||||
(void)size14;
|
||||
std::size_t size15 = buffer_copy(mbc1, mbc2);
|
||||
(void)size15;
|
||||
std::size_t size16 = buffer_copy(mbc1, const_buffer_sequence);
|
||||
(void)size16;
|
||||
#endif // !defined(ASIO_NO_DEPRECATED)
|
||||
std::size_t size17 = buffer_copy(mutable_buffer_sequence, cb2);
|
||||
(void)size17;
|
||||
#if !defined(ASIO_NO_DEPRECATED)
|
||||
std::size_t size18 = buffer_copy(mutable_buffer_sequence, cbc2);
|
||||
(void)size18;
|
||||
#endif // !defined(ASIO_NO_DEPRECATED)
|
||||
std::size_t size19 = buffer_copy(mutable_buffer_sequence, mb2);
|
||||
(void)size19;
|
||||
#if !defined(ASIO_NO_DEPRECATED)
|
||||
std::size_t size20 = buffer_copy(mutable_buffer_sequence, mbc2);
|
||||
(void)size20;
|
||||
#endif // !defined(ASIO_NO_DEPRECATED)
|
||||
std::size_t size21 = buffer_copy(
|
||||
mutable_buffer_sequence, const_buffer_sequence);
|
||||
(void)size21;
|
||||
std::size_t size22 = buffer_copy(mb1, cb2, 128);
|
||||
(void)size22;
|
||||
#if !defined(ASIO_NO_DEPRECATED)
|
||||
std::size_t size23 = buffer_copy(mb1, cbc2, 128);
|
||||
(void)size23;
|
||||
#endif // !defined(ASIO_NO_DEPRECATED)
|
||||
std::size_t size24 = buffer_copy(mb1, mb2, 128);
|
||||
(void)size24;
|
||||
#if !defined(ASIO_NO_DEPRECATED)
|
||||
std::size_t size25 = buffer_copy(mb1, mbc2, 128);
|
||||
(void)size25;
|
||||
#endif // !defined(ASIO_NO_DEPRECATED)
|
||||
std::size_t size26 = buffer_copy(mb1, const_buffer_sequence, 128);
|
||||
(void)size26;
|
||||
#if !defined(ASIO_NO_DEPRECATED)
|
||||
std::size_t size27 = buffer_copy(mbc1, cb2, 128);
|
||||
(void)size27;
|
||||
std::size_t size28 = buffer_copy(mbc1, cbc2, 128);
|
||||
(void)size28;
|
||||
std::size_t size29 = buffer_copy(mbc1, mb2, 128);
|
||||
(void)size29;
|
||||
std::size_t size30 = buffer_copy(mbc1, mbc2, 128);
|
||||
(void)size30;
|
||||
std::size_t size31 = buffer_copy(mbc1, const_buffer_sequence, 128);
|
||||
(void)size31;
|
||||
#endif // !defined(ASIO_NO_DEPRECATED)
|
||||
std::size_t size32 = buffer_copy(mutable_buffer_sequence, cb2, 128);
|
||||
(void)size32;
|
||||
#if !defined(ASIO_NO_DEPRECATED)
|
||||
std::size_t size33 = buffer_copy(mutable_buffer_sequence, cbc2, 128);
|
||||
(void)size33;
|
||||
#endif // !defined(ASIO_NO_DEPRECATED)
|
||||
std::size_t size34 = buffer_copy(mutable_buffer_sequence, mb2, 128);
|
||||
(void)size34;
|
||||
#if !defined(ASIO_NO_DEPRECATED)
|
||||
std::size_t size35 = buffer_copy(mutable_buffer_sequence, mbc2, 128);
|
||||
(void)size35;
|
||||
#endif // !defined(ASIO_NO_DEPRECATED)
|
||||
std::size_t size36 = buffer_copy(
|
||||
mutable_buffer_sequence, const_buffer_sequence, 128);
|
||||
(void)size36;
|
||||
|
||||
// dynamic_buffer function overloads.
|
||||
|
||||
dynamic_string_buffer<char, std::string::traits_type,
|
||||
std::string::allocator_type> db1 = dynamic_buffer(string_data);
|
||||
(void)db1;
|
||||
dynamic_string_buffer<char, std::string::traits_type,
|
||||
std::string::allocator_type> db2 = dynamic_buffer(string_data, 1024);
|
||||
(void)db2;
|
||||
dynamic_vector_buffer<char, std::allocator<char> >
|
||||
db3 = dynamic_buffer(vector_data);
|
||||
(void)db3;
|
||||
dynamic_vector_buffer<char, std::allocator<char> >
|
||||
db4 = dynamic_buffer(vector_data, 1024);
|
||||
(void)db4;
|
||||
|
||||
// dynamic_buffer member functions.
|
||||
|
||||
std::size_t size37 = db1.size();
|
||||
(void)size37;
|
||||
std::size_t size38 = db3.size();
|
||||
(void)size38;
|
||||
|
||||
std::size_t size39 = db1.max_size();
|
||||
(void)size39;
|
||||
std::size_t size40 = db3.max_size();
|
||||
(void)size40;
|
||||
|
||||
#if !defined(ASIO_NO_DYNAMIC_BUFFER_V1)
|
||||
dynamic_string_buffer<char, std::string::traits_type,
|
||||
std::string::allocator_type>::const_buffers_type
|
||||
cb5 = db1.data();
|
||||
(void)cb5;
|
||||
dynamic_vector_buffer<char, std::allocator<char> >::const_buffers_type
|
||||
cb6 = db3.data();
|
||||
(void)cb6;
|
||||
|
||||
dynamic_string_buffer<char, std::string::traits_type,
|
||||
std::string::allocator_type>::mutable_buffers_type mb5
|
||||
= db1.prepare(1024);
|
||||
(void)mb5;
|
||||
dynamic_vector_buffer<char, std::allocator<char> >::mutable_buffers_type
|
||||
mb6 = db3.prepare(1024);
|
||||
(void)mb6;
|
||||
|
||||
db1.commit(1024);
|
||||
db3.commit(1024);
|
||||
#endif // !defined(ASIO_NO_DYNAMIC_BUFFER_V1)
|
||||
|
||||
dynamic_string_buffer<char, std::string::traits_type,
|
||||
std::string::allocator_type>::mutable_buffers_type
|
||||
mb7 = db1.data(0, 1);
|
||||
(void)mb7;
|
||||
dynamic_vector_buffer<char, std::allocator<char> >::mutable_buffers_type
|
||||
mb8 = db3.data(0, 1);
|
||||
(void)mb8;
|
||||
|
||||
dynamic_string_buffer<char, std::string::traits_type,
|
||||
std::string::allocator_type>::const_buffers_type
|
||||
cb7 = static_cast<const dynamic_string_buffer<char,
|
||||
std::string::traits_type,
|
||||
std::string::allocator_type>&>(db1).data(0, 1);
|
||||
(void)cb7;
|
||||
dynamic_vector_buffer<char, std::allocator<char> >::const_buffers_type
|
||||
cb8 = static_cast<const dynamic_vector_buffer<char,
|
||||
std::allocator<char> >&>(db3).data(0, 1);
|
||||
(void)cb8;
|
||||
|
||||
db1.grow(1024);
|
||||
db3.grow(1024);
|
||||
|
||||
db1.shrink(1024);
|
||||
db3.shrink(1024);
|
||||
|
||||
db1.consume(0);
|
||||
db3.consume(0);
|
||||
}
|
||||
catch (std::exception&)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace buffer_compile
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
namespace buffer_copy_runtime {
|
||||
|
||||
using namespace asio;
|
||||
using namespace std;
|
||||
|
||||
void test()
|
||||
{
|
||||
char dest_data[256];
|
||||
char source_data[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
|
||||
|
||||
memset(dest_data, 0, sizeof(dest_data));
|
||||
mutable_buffer mb1 = asio::buffer(dest_data);
|
||||
mutable_buffer mb2 = asio::buffer(source_data);
|
||||
std::size_t n = buffer_copy(mb1, mb2);
|
||||
ASIO_CHECK(n == sizeof(source_data));
|
||||
ASIO_CHECK(memcmp(dest_data, source_data, n) == 0);
|
||||
|
||||
memset(dest_data, 0, sizeof(dest_data));
|
||||
mb1 = asio::buffer(dest_data);
|
||||
const_buffer cb1 = asio::buffer(source_data);
|
||||
n = buffer_copy(mb1, cb1);
|
||||
ASIO_CHECK(n == sizeof(source_data));
|
||||
ASIO_CHECK(memcmp(dest_data, source_data, n) == 0);
|
||||
|
||||
#if !defined(ASIO_NO_DEPRECATED)
|
||||
memset(dest_data, 0, sizeof(dest_data));
|
||||
mb1 = asio::buffer(dest_data);
|
||||
mutable_buffers_1 mbc1 = asio::buffer(source_data);
|
||||
n = buffer_copy(mb1, mbc1);
|
||||
ASIO_CHECK(n == sizeof(source_data));
|
||||
ASIO_CHECK(memcmp(dest_data, source_data, n) == 0);
|
||||
|
||||
memset(dest_data, 0, sizeof(dest_data));
|
||||
mb1 = asio::buffer(dest_data);
|
||||
const_buffers_1 cbc1 = const_buffers_1(asio::buffer(source_data));
|
||||
n = buffer_copy(mb1, cbc1);
|
||||
ASIO_CHECK(n == sizeof(source_data));
|
||||
ASIO_CHECK(memcmp(dest_data, source_data, n) == 0);
|
||||
|
||||
memset(dest_data, 0, sizeof(dest_data));
|
||||
mbc1 = asio::buffer(dest_data);
|
||||
mb1 = asio::buffer(source_data);
|
||||
n = buffer_copy(mbc1, mb1);
|
||||
ASIO_CHECK(n == sizeof(source_data));
|
||||
ASIO_CHECK(memcmp(dest_data, source_data, n) == 0);
|
||||
|
||||
memset(dest_data, 0, sizeof(dest_data));
|
||||
mbc1 = asio::buffer(dest_data);
|
||||
cb1 = asio::buffer(source_data);
|
||||
n = buffer_copy(mbc1, cb1);
|
||||
ASIO_CHECK(n == sizeof(source_data));
|
||||
ASIO_CHECK(memcmp(dest_data, source_data, n) == 0);
|
||||
|
||||
memset(dest_data, 0, sizeof(dest_data));
|
||||
mbc1 = asio::buffer(dest_data);
|
||||
mutable_buffers_1 mbc2 = asio::buffer(source_data);
|
||||
n = buffer_copy(mbc1, mbc2);
|
||||
ASIO_CHECK(n == sizeof(source_data));
|
||||
ASIO_CHECK(memcmp(dest_data, source_data, n) == 0);
|
||||
|
||||
memset(dest_data, 0, sizeof(dest_data));
|
||||
mbc1 = asio::buffer(dest_data);
|
||||
cbc1 = const_buffers_1(asio::buffer(source_data));
|
||||
n = buffer_copy(mbc1, cbc1);
|
||||
ASIO_CHECK(n == sizeof(source_data));
|
||||
ASIO_CHECK(memcmp(dest_data, source_data, n) == 0);
|
||||
#endif // !defined(ASIO_NO_DEPRECATED)
|
||||
|
||||
memset(dest_data, 0, sizeof(dest_data));
|
||||
mb1 = asio::buffer(dest_data);
|
||||
std::vector<mutable_buffer> mv1;
|
||||
mv1.push_back(asio::buffer(source_data, 5));
|
||||
mv1.push_back(asio::buffer(source_data) + 5);
|
||||
n = buffer_copy(mb1, mv1);
|
||||
ASIO_CHECK(n == sizeof(source_data));
|
||||
ASIO_CHECK(memcmp(dest_data, source_data, n) == 0);
|
||||
|
||||
memset(dest_data, 0, sizeof(dest_data));
|
||||
mb1 = asio::buffer(dest_data);
|
||||
std::vector<const_buffer> cv1;
|
||||
cv1.push_back(asio::buffer(source_data, 6));
|
||||
cv1.push_back(asio::buffer(source_data) + 6);
|
||||
n = buffer_copy(mb1, cv1);
|
||||
ASIO_CHECK(n == sizeof(source_data));
|
||||
ASIO_CHECK(memcmp(dest_data, source_data, n) == 0);
|
||||
|
||||
memset(dest_data, 0, sizeof(dest_data));
|
||||
mv1.clear();
|
||||
mv1.push_back(asio::buffer(dest_data, 7));
|
||||
mv1.push_back(asio::buffer(dest_data) + 7);
|
||||
cb1 = asio::buffer(source_data);
|
||||
n = buffer_copy(mv1, cb1);
|
||||
ASIO_CHECK(n == sizeof(source_data));
|
||||
ASIO_CHECK(memcmp(dest_data, source_data, n) == 0);
|
||||
|
||||
memset(dest_data, 0, sizeof(dest_data));
|
||||
mv1.clear();
|
||||
mv1.push_back(asio::buffer(dest_data, 7));
|
||||
mv1.push_back(asio::buffer(dest_data) + 7);
|
||||
cv1.clear();
|
||||
cv1.push_back(asio::buffer(source_data, 8));
|
||||
cv1.push_back(asio::buffer(source_data) + 8);
|
||||
n = buffer_copy(mv1, cv1);
|
||||
ASIO_CHECK(n == sizeof(source_data));
|
||||
ASIO_CHECK(memcmp(dest_data, source_data, n) == 0);
|
||||
|
||||
memset(dest_data, 0, sizeof(dest_data));
|
||||
mb1 = asio::buffer(dest_data);
|
||||
mb2 = asio::buffer(source_data);
|
||||
n = buffer_copy(mb1, mb2, 10);
|
||||
ASIO_CHECK(n == 10);
|
||||
ASIO_CHECK(memcmp(dest_data, source_data, n) == 0);
|
||||
|
||||
memset(dest_data, 0, sizeof(dest_data));
|
||||
mb1 = asio::buffer(dest_data);
|
||||
cb1 = asio::buffer(source_data);
|
||||
n = buffer_copy(mb1, cb1, 10);
|
||||
ASIO_CHECK(n == 10);
|
||||
ASIO_CHECK(memcmp(dest_data, source_data, n) == 0);
|
||||
|
||||
#if !defined(ASIO_NO_DEPRECATED)
|
||||
memset(dest_data, 0, sizeof(dest_data));
|
||||
mb1 = asio::buffer(dest_data);
|
||||
mbc1 = asio::buffer(source_data);
|
||||
n = buffer_copy(mb1, mbc1, 10);
|
||||
ASIO_CHECK(n == 10);
|
||||
ASIO_CHECK(memcmp(dest_data, source_data, n) == 0);
|
||||
|
||||
memset(dest_data, 0, sizeof(dest_data));
|
||||
mb1 = asio::buffer(dest_data);
|
||||
cbc1 = const_buffers_1(asio::buffer(source_data));
|
||||
n = buffer_copy(mb1, cbc1, 10);
|
||||
ASIO_CHECK(n == 10);
|
||||
ASIO_CHECK(memcmp(dest_data, source_data, n) == 0);
|
||||
|
||||
memset(dest_data, 0, sizeof(dest_data));
|
||||
mbc1 = asio::buffer(dest_data);
|
||||
mb1 = asio::buffer(source_data);
|
||||
n = buffer_copy(mbc1, mb1, 10);
|
||||
ASIO_CHECK(n == 10);
|
||||
ASIO_CHECK(memcmp(dest_data, source_data, n) == 0);
|
||||
|
||||
memset(dest_data, 0, sizeof(dest_data));
|
||||
mbc1 = asio::buffer(dest_data);
|
||||
cb1 = asio::buffer(source_data);
|
||||
n = buffer_copy(mbc1, cb1, 10);
|
||||
ASIO_CHECK(n == 10);
|
||||
ASIO_CHECK(memcmp(dest_data, source_data, n) == 0);
|
||||
|
||||
memset(dest_data, 0, sizeof(dest_data));
|
||||
mbc1 = asio::buffer(dest_data);
|
||||
mbc2 = asio::buffer(source_data);
|
||||
n = buffer_copy(mbc1, mbc2, 10);
|
||||
ASIO_CHECK(n == 10);
|
||||
ASIO_CHECK(memcmp(dest_data, source_data, n) == 0);
|
||||
|
||||
memset(dest_data, 0, sizeof(dest_data));
|
||||
mbc1 = asio::buffer(dest_data);
|
||||
cbc1 = const_buffers_1(asio::buffer(source_data));
|
||||
n = buffer_copy(mbc1, cbc1, 10);
|
||||
ASIO_CHECK(n == 10);
|
||||
ASIO_CHECK(memcmp(dest_data, source_data, n) == 0);
|
||||
#endif // !defined(ASIO_NO_DEPRECATED)
|
||||
|
||||
memset(dest_data, 0, sizeof(dest_data));
|
||||
mb1 = asio::buffer(dest_data);
|
||||
mv1.clear();
|
||||
mv1.push_back(asio::buffer(source_data, 5));
|
||||
mv1.push_back(asio::buffer(source_data) + 5);
|
||||
n = buffer_copy(mb1, mv1, 10);
|
||||
ASIO_CHECK(n == 10);
|
||||
ASIO_CHECK(memcmp(dest_data, source_data, n) == 0);
|
||||
|
||||
memset(dest_data, 0, sizeof(dest_data));
|
||||
mb1 = asio::buffer(dest_data);
|
||||
cv1.clear();
|
||||
cv1.push_back(asio::buffer(source_data, 6));
|
||||
cv1.push_back(asio::buffer(source_data) + 6);
|
||||
n = buffer_copy(mb1, cv1, 10);
|
||||
ASIO_CHECK(n == 10);
|
||||
ASIO_CHECK(memcmp(dest_data, source_data, n) == 0);
|
||||
|
||||
memset(dest_data, 0, sizeof(dest_data));
|
||||
mv1.clear();
|
||||
mv1.push_back(asio::buffer(dest_data, 7));
|
||||
mv1.push_back(asio::buffer(dest_data) + 7);
|
||||
cb1 = asio::buffer(source_data);
|
||||
n = buffer_copy(mv1, cb1, 10);
|
||||
ASIO_CHECK(n == 10);
|
||||
ASIO_CHECK(memcmp(dest_data, source_data, n) == 0);
|
||||
|
||||
memset(dest_data, 0, sizeof(dest_data));
|
||||
mv1.clear();
|
||||
mv1.push_back(asio::buffer(dest_data, 7));
|
||||
mv1.push_back(asio::buffer(dest_data) + 7);
|
||||
cv1.clear();
|
||||
cv1.push_back(asio::buffer(source_data, 8));
|
||||
cv1.push_back(asio::buffer(source_data) + 8);
|
||||
n = buffer_copy(mv1, cv1, 10);
|
||||
ASIO_CHECK(n == 10);
|
||||
ASIO_CHECK(memcmp(dest_data, source_data, n) == 0);
|
||||
}
|
||||
|
||||
} // namespace buffer_copy_runtime
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
ASIO_TEST_SUITE
|
||||
(
|
||||
"buffer",
|
||||
ASIO_COMPILE_TEST_CASE(buffer_compile::test)
|
||||
ASIO_TEST_CASE(buffer_copy_runtime::test)
|
||||
)
|
||||
@@ -0,0 +1,338 @@
|
||||
//
|
||||
// buffered_read_stream.cpp
|
||||
// ~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
//
|
||||
// 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)
|
||||
//
|
||||
|
||||
// Disable autolinking for unit tests.
|
||||
#if !defined(BOOST_ALL_NO_LIB)
|
||||
#define BOOST_ALL_NO_LIB 1
|
||||
#endif // !defined(BOOST_ALL_NO_LIB)
|
||||
|
||||
// Test that header file is self-contained.
|
||||
#include "asio/buffered_read_stream.hpp"
|
||||
|
||||
#include <cstring>
|
||||
#include "archetypes/async_result.hpp"
|
||||
#include "asio/buffer.hpp"
|
||||
#include "asio/io_context.hpp"
|
||||
#include "asio/ip/tcp.hpp"
|
||||
#include "asio/system_error.hpp"
|
||||
#include "unit_test.hpp"
|
||||
|
||||
#if defined(ASIO_HAS_BOOST_ARRAY)
|
||||
# include <boost/array.hpp>
|
||||
#else // defined(ASIO_HAS_BOOST_ARRAY)
|
||||
# include <array>
|
||||
#endif // defined(ASIO_HAS_BOOST_ARRAY)
|
||||
|
||||
#if defined(ASIO_HAS_BOOST_BIND)
|
||||
# include <boost/bind.hpp>
|
||||
#else // defined(ASIO_HAS_BOOST_BIND)
|
||||
# include <functional>
|
||||
#endif // defined(ASIO_HAS_BOOST_BIND)
|
||||
|
||||
typedef asio::buffered_read_stream<
|
||||
asio::ip::tcp::socket> stream_type;
|
||||
|
||||
void write_some_handler(const asio::error_code&, std::size_t)
|
||||
{
|
||||
}
|
||||
|
||||
void fill_handler(const asio::error_code&, std::size_t)
|
||||
{
|
||||
}
|
||||
|
||||
void read_some_handler(const asio::error_code&, std::size_t)
|
||||
{
|
||||
}
|
||||
|
||||
void test_compile()
|
||||
{
|
||||
#if defined(ASIO_HAS_BOOST_ARRAY)
|
||||
using boost::array;
|
||||
#else // defined(ASIO_HAS_BOOST_ARRAY)
|
||||
using std::array;
|
||||
#endif // defined(ASIO_HAS_BOOST_ARRAY)
|
||||
|
||||
using namespace asio;
|
||||
|
||||
try
|
||||
{
|
||||
io_context ioc;
|
||||
char mutable_char_buffer[128] = "";
|
||||
const char const_char_buffer[128] = "";
|
||||
array<asio::mutable_buffer, 2> mutable_buffers = {{
|
||||
asio::buffer(mutable_char_buffer, 10),
|
||||
asio::buffer(mutable_char_buffer + 10, 10) }};
|
||||
array<asio::const_buffer, 2> const_buffers = {{
|
||||
asio::buffer(const_char_buffer, 10),
|
||||
asio::buffer(const_char_buffer + 10, 10) }};
|
||||
archetypes::lazy_handler lazy;
|
||||
asio::error_code ec;
|
||||
|
||||
stream_type stream1(ioc);
|
||||
stream_type stream2(ioc, 1024);
|
||||
|
||||
stream_type::executor_type ex = stream1.get_executor();
|
||||
(void)ex;
|
||||
|
||||
stream_type::lowest_layer_type& lowest_layer = stream1.lowest_layer();
|
||||
(void)lowest_layer;
|
||||
|
||||
stream1.write_some(buffer(mutable_char_buffer));
|
||||
stream1.write_some(buffer(const_char_buffer));
|
||||
stream1.write_some(mutable_buffers);
|
||||
stream1.write_some(const_buffers);
|
||||
stream1.write_some(null_buffers());
|
||||
stream1.write_some(buffer(mutable_char_buffer), ec);
|
||||
stream1.write_some(buffer(const_char_buffer), ec);
|
||||
stream1.write_some(mutable_buffers, ec);
|
||||
stream1.write_some(const_buffers, ec);
|
||||
stream1.write_some(null_buffers(), ec);
|
||||
|
||||
stream1.async_write_some(buffer(mutable_char_buffer), &write_some_handler);
|
||||
stream1.async_write_some(buffer(const_char_buffer), &write_some_handler);
|
||||
stream1.async_write_some(mutable_buffers, &write_some_handler);
|
||||
stream1.async_write_some(const_buffers, &write_some_handler);
|
||||
stream1.async_write_some(null_buffers(), &write_some_handler);
|
||||
int i1 = stream1.async_write_some(buffer(mutable_char_buffer), lazy);
|
||||
(void)i1;
|
||||
int i2 = stream1.async_write_some(buffer(const_char_buffer), lazy);
|
||||
(void)i2;
|
||||
int i3 = stream1.async_write_some(mutable_buffers, lazy);
|
||||
(void)i3;
|
||||
int i4 = stream1.async_write_some(const_buffers, lazy);
|
||||
(void)i4;
|
||||
int i5 = stream1.async_write_some(null_buffers(), lazy);
|
||||
(void)i5;
|
||||
|
||||
stream1.fill();
|
||||
stream1.fill(ec);
|
||||
|
||||
stream1.async_fill(&fill_handler);
|
||||
int i6 = stream1.async_fill(lazy);
|
||||
(void)i6;
|
||||
|
||||
stream1.read_some(buffer(mutable_char_buffer));
|
||||
stream1.read_some(mutable_buffers);
|
||||
stream1.read_some(null_buffers());
|
||||
stream1.read_some(buffer(mutable_char_buffer), ec);
|
||||
stream1.read_some(mutable_buffers, ec);
|
||||
stream1.read_some(null_buffers(), ec);
|
||||
|
||||
stream1.async_read_some(buffer(mutable_char_buffer), &read_some_handler);
|
||||
stream1.async_read_some(mutable_buffers, &read_some_handler);
|
||||
stream1.async_read_some(null_buffers(), &read_some_handler);
|
||||
int i7 = stream1.async_read_some(buffer(mutable_char_buffer), lazy);
|
||||
(void)i7;
|
||||
int i8 = stream1.async_read_some(mutable_buffers, lazy);
|
||||
(void)i8;
|
||||
int i9 = stream1.async_read_some(null_buffers(), lazy);
|
||||
(void)i9;
|
||||
}
|
||||
catch (std::exception&)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
void test_sync_operations()
|
||||
{
|
||||
using namespace std; // For memcmp.
|
||||
|
||||
asio::io_context io_context;
|
||||
|
||||
asio::ip::tcp::acceptor acceptor(io_context,
|
||||
asio::ip::tcp::endpoint(asio::ip::tcp::v4(), 0));
|
||||
asio::ip::tcp::endpoint server_endpoint = acceptor.local_endpoint();
|
||||
server_endpoint.address(asio::ip::address_v4::loopback());
|
||||
|
||||
stream_type client_socket(io_context);
|
||||
client_socket.lowest_layer().connect(server_endpoint);
|
||||
|
||||
stream_type server_socket(io_context);
|
||||
acceptor.accept(server_socket.lowest_layer());
|
||||
|
||||
const char write_data[]
|
||||
= "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
|
||||
const asio::const_buffer write_buf = asio::buffer(write_data);
|
||||
|
||||
std::size_t bytes_written = 0;
|
||||
while (bytes_written < sizeof(write_data))
|
||||
{
|
||||
bytes_written += client_socket.write_some(
|
||||
asio::buffer(write_buf + bytes_written));
|
||||
}
|
||||
|
||||
char read_data[sizeof(write_data)];
|
||||
const asio::mutable_buffer read_buf = asio::buffer(read_data);
|
||||
|
||||
std::size_t bytes_read = 0;
|
||||
while (bytes_read < sizeof(read_data))
|
||||
{
|
||||
bytes_read += server_socket.read_some(
|
||||
asio::buffer(read_buf + bytes_read));
|
||||
}
|
||||
|
||||
ASIO_CHECK(bytes_written == sizeof(write_data));
|
||||
ASIO_CHECK(bytes_read == sizeof(read_data));
|
||||
ASIO_CHECK(memcmp(write_data, read_data, sizeof(write_data)) == 0);
|
||||
|
||||
bytes_written = 0;
|
||||
while (bytes_written < sizeof(write_data))
|
||||
{
|
||||
bytes_written += server_socket.write_some(
|
||||
asio::buffer(write_buf + bytes_written));
|
||||
}
|
||||
|
||||
bytes_read = 0;
|
||||
while (bytes_read < sizeof(read_data))
|
||||
{
|
||||
bytes_read += client_socket.read_some(
|
||||
asio::buffer(read_buf + bytes_read));
|
||||
}
|
||||
|
||||
ASIO_CHECK(bytes_written == sizeof(write_data));
|
||||
ASIO_CHECK(bytes_read == sizeof(read_data));
|
||||
ASIO_CHECK(memcmp(write_data, read_data, sizeof(write_data)) == 0);
|
||||
|
||||
server_socket.close();
|
||||
asio::error_code error;
|
||||
bytes_read = client_socket.read_some(
|
||||
asio::buffer(read_buf), error);
|
||||
|
||||
ASIO_CHECK(bytes_read == 0);
|
||||
ASIO_CHECK(error == asio::error::eof);
|
||||
|
||||
client_socket.close(error);
|
||||
}
|
||||
|
||||
void handle_accept(const asio::error_code& e)
|
||||
{
|
||||
ASIO_CHECK(!e);
|
||||
}
|
||||
|
||||
void handle_write(const asio::error_code& e,
|
||||
std::size_t bytes_transferred,
|
||||
std::size_t* total_bytes_written)
|
||||
{
|
||||
ASIO_CHECK(!e);
|
||||
if (e)
|
||||
throw asio::system_error(e); // Terminate test.
|
||||
*total_bytes_written += bytes_transferred;
|
||||
}
|
||||
|
||||
void handle_read(const asio::error_code& e,
|
||||
std::size_t bytes_transferred,
|
||||
std::size_t* total_bytes_read)
|
||||
{
|
||||
ASIO_CHECK(!e);
|
||||
if (e)
|
||||
throw asio::system_error(e); // Terminate test.
|
||||
*total_bytes_read += bytes_transferred;
|
||||
}
|
||||
|
||||
void handle_read_eof(const asio::error_code& e,
|
||||
std::size_t bytes_transferred)
|
||||
{
|
||||
ASIO_CHECK(e == asio::error::eof);
|
||||
ASIO_CHECK(bytes_transferred == 0);
|
||||
}
|
||||
|
||||
void test_async_operations()
|
||||
{
|
||||
using namespace std; // For memcmp.
|
||||
|
||||
#if defined(ASIO_HAS_BOOST_BIND)
|
||||
namespace bindns = boost;
|
||||
#else // defined(ASIO_HAS_BOOST_BIND)
|
||||
namespace bindns = std;
|
||||
using std::placeholders::_1;
|
||||
using std::placeholders::_2;
|
||||
#endif // defined(ASIO_HAS_BOOST_BIND)
|
||||
|
||||
asio::io_context io_context;
|
||||
|
||||
asio::ip::tcp::acceptor acceptor(io_context,
|
||||
asio::ip::tcp::endpoint(asio::ip::tcp::v4(), 0));
|
||||
asio::ip::tcp::endpoint server_endpoint = acceptor.local_endpoint();
|
||||
server_endpoint.address(asio::ip::address_v4::loopback());
|
||||
|
||||
stream_type client_socket(io_context);
|
||||
client_socket.lowest_layer().connect(server_endpoint);
|
||||
|
||||
stream_type server_socket(io_context);
|
||||
acceptor.async_accept(server_socket.lowest_layer(), &handle_accept);
|
||||
io_context.run();
|
||||
io_context.restart();
|
||||
|
||||
const char write_data[]
|
||||
= "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
|
||||
const asio::const_buffer write_buf = asio::buffer(write_data);
|
||||
|
||||
std::size_t bytes_written = 0;
|
||||
while (bytes_written < sizeof(write_data))
|
||||
{
|
||||
client_socket.async_write_some(
|
||||
asio::buffer(write_buf + bytes_written),
|
||||
bindns::bind(handle_write, _1, _2, &bytes_written));
|
||||
io_context.run();
|
||||
io_context.restart();
|
||||
}
|
||||
|
||||
char read_data[sizeof(write_data)];
|
||||
const asio::mutable_buffer read_buf = asio::buffer(read_data);
|
||||
|
||||
std::size_t bytes_read = 0;
|
||||
while (bytes_read < sizeof(read_data))
|
||||
{
|
||||
server_socket.async_read_some(
|
||||
asio::buffer(read_buf + bytes_read),
|
||||
bindns::bind(handle_read, _1, _2, &bytes_read));
|
||||
io_context.run();
|
||||
io_context.restart();
|
||||
}
|
||||
|
||||
ASIO_CHECK(bytes_written == sizeof(write_data));
|
||||
ASIO_CHECK(bytes_read == sizeof(read_data));
|
||||
ASIO_CHECK(memcmp(write_data, read_data, sizeof(write_data)) == 0);
|
||||
|
||||
bytes_written = 0;
|
||||
while (bytes_written < sizeof(write_data))
|
||||
{
|
||||
server_socket.async_write_some(
|
||||
asio::buffer(write_buf + bytes_written),
|
||||
bindns::bind(handle_write, _1, _2, &bytes_written));
|
||||
io_context.run();
|
||||
io_context.restart();
|
||||
}
|
||||
|
||||
bytes_read = 0;
|
||||
while (bytes_read < sizeof(read_data))
|
||||
{
|
||||
client_socket.async_read_some(
|
||||
asio::buffer(read_buf + bytes_read),
|
||||
bindns::bind(handle_read, _1, _2, &bytes_read));
|
||||
io_context.run();
|
||||
io_context.restart();
|
||||
}
|
||||
|
||||
ASIO_CHECK(bytes_written == sizeof(write_data));
|
||||
ASIO_CHECK(bytes_read == sizeof(read_data));
|
||||
ASIO_CHECK(memcmp(write_data, read_data, sizeof(write_data)) == 0);
|
||||
|
||||
server_socket.close();
|
||||
client_socket.async_read_some(asio::buffer(read_buf), handle_read_eof);
|
||||
}
|
||||
|
||||
ASIO_TEST_SUITE
|
||||
(
|
||||
"buffered_read_stream",
|
||||
ASIO_TEST_CASE(test_compile)
|
||||
ASIO_TEST_CASE(test_sync_operations)
|
||||
ASIO_TEST_CASE(test_async_operations)
|
||||
)
|
||||
@@ -0,0 +1,364 @@
|
||||
//
|
||||
// buffered_stream.cpp
|
||||
// ~~~~~~~~~~~~~~~~~~~
|
||||
//
|
||||
// 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)
|
||||
//
|
||||
|
||||
// Disable autolinking for unit tests.
|
||||
#if !defined(BOOST_ALL_NO_LIB)
|
||||
#define BOOST_ALL_NO_LIB 1
|
||||
#endif // !defined(BOOST_ALL_NO_LIB)
|
||||
|
||||
// Test that header file is self-contained.
|
||||
#include "asio/buffered_stream.hpp"
|
||||
|
||||
#include <cstring>
|
||||
#include "archetypes/async_result.hpp"
|
||||
#include "asio/buffer.hpp"
|
||||
#include "asio/io_context.hpp"
|
||||
#include "asio/ip/tcp.hpp"
|
||||
#include "asio/system_error.hpp"
|
||||
#include "unit_test.hpp"
|
||||
|
||||
#if defined(ASIO_HAS_BOOST_ARRAY)
|
||||
# include <boost/array.hpp>
|
||||
#else // defined(ASIO_HAS_BOOST_ARRAY)
|
||||
# include <array>
|
||||
#endif // defined(ASIO_HAS_BOOST_ARRAY)
|
||||
|
||||
#if defined(ASIO_HAS_BOOST_BIND)
|
||||
# include <boost/bind.hpp>
|
||||
#else // defined(ASIO_HAS_BOOST_BIND)
|
||||
# include <functional>
|
||||
#endif // defined(ASIO_HAS_BOOST_BIND)
|
||||
|
||||
typedef asio::buffered_stream<
|
||||
asio::ip::tcp::socket> stream_type;
|
||||
|
||||
void write_some_handler(const asio::error_code&, std::size_t)
|
||||
{
|
||||
}
|
||||
|
||||
void flush_handler(const asio::error_code&, std::size_t)
|
||||
{
|
||||
}
|
||||
|
||||
void fill_handler(const asio::error_code&, std::size_t)
|
||||
{
|
||||
}
|
||||
|
||||
void read_some_handler(const asio::error_code&, std::size_t)
|
||||
{
|
||||
}
|
||||
|
||||
void test_compile()
|
||||
{
|
||||
#if defined(ASIO_HAS_BOOST_ARRAY)
|
||||
using boost::array;
|
||||
#else // defined(ASIO_HAS_BOOST_ARRAY)
|
||||
using std::array;
|
||||
#endif // defined(ASIO_HAS_BOOST_ARRAY)
|
||||
|
||||
using namespace asio;
|
||||
|
||||
try
|
||||
{
|
||||
io_context ioc;
|
||||
char mutable_char_buffer[128] = "";
|
||||
const char const_char_buffer[128] = "";
|
||||
array<asio::mutable_buffer, 2> mutable_buffers = {{
|
||||
asio::buffer(mutable_char_buffer, 10),
|
||||
asio::buffer(mutable_char_buffer + 10, 10) }};
|
||||
array<asio::const_buffer, 2> const_buffers = {{
|
||||
asio::buffer(const_char_buffer, 10),
|
||||
asio::buffer(const_char_buffer + 10, 10) }};
|
||||
archetypes::lazy_handler lazy;
|
||||
asio::error_code ec;
|
||||
|
||||
stream_type stream1(ioc);
|
||||
stream_type stream2(ioc, 1024, 1024);
|
||||
|
||||
stream_type::executor_type ex = stream1.get_executor();
|
||||
(void)ex;
|
||||
|
||||
stream_type::lowest_layer_type& lowest_layer = stream1.lowest_layer();
|
||||
(void)lowest_layer;
|
||||
|
||||
stream1.write_some(buffer(mutable_char_buffer));
|
||||
stream1.write_some(buffer(const_char_buffer));
|
||||
stream1.write_some(mutable_buffers);
|
||||
stream1.write_some(const_buffers);
|
||||
stream1.write_some(null_buffers());
|
||||
stream1.write_some(buffer(mutable_char_buffer), ec);
|
||||
stream1.write_some(buffer(const_char_buffer), ec);
|
||||
stream1.write_some(mutable_buffers, ec);
|
||||
stream1.write_some(const_buffers, ec);
|
||||
stream1.write_some(null_buffers(), ec);
|
||||
|
||||
stream1.async_write_some(buffer(mutable_char_buffer), &write_some_handler);
|
||||
stream1.async_write_some(buffer(const_char_buffer), &write_some_handler);
|
||||
stream1.async_write_some(mutable_buffers, &write_some_handler);
|
||||
stream1.async_write_some(const_buffers, &write_some_handler);
|
||||
stream1.async_write_some(null_buffers(), &write_some_handler);
|
||||
int i1 = stream1.async_write_some(buffer(mutable_char_buffer), lazy);
|
||||
(void)i1;
|
||||
int i2 = stream1.async_write_some(buffer(const_char_buffer), lazy);
|
||||
(void)i2;
|
||||
int i3 = stream1.async_write_some(mutable_buffers, lazy);
|
||||
(void)i3;
|
||||
int i4 = stream1.async_write_some(const_buffers, lazy);
|
||||
(void)i4;
|
||||
int i5 = stream1.async_write_some(null_buffers(), lazy);
|
||||
(void)i5;
|
||||
|
||||
stream1.flush();
|
||||
stream1.flush(ec);
|
||||
|
||||
stream1.async_flush(&flush_handler);
|
||||
int i6 = stream1.async_flush(lazy);
|
||||
(void)i6;
|
||||
|
||||
stream1.fill();
|
||||
stream1.fill(ec);
|
||||
|
||||
stream1.async_fill(&fill_handler);
|
||||
int i7 = stream1.async_fill(lazy);
|
||||
(void)i7;
|
||||
|
||||
stream1.read_some(buffer(mutable_char_buffer));
|
||||
stream1.read_some(mutable_buffers);
|
||||
stream1.read_some(null_buffers());
|
||||
stream1.read_some(buffer(mutable_char_buffer), ec);
|
||||
stream1.read_some(mutable_buffers, ec);
|
||||
stream1.read_some(null_buffers(), ec);
|
||||
|
||||
stream1.async_read_some(buffer(mutable_char_buffer), &read_some_handler);
|
||||
stream1.async_read_some(mutable_buffers, &read_some_handler);
|
||||
stream1.async_read_some(null_buffers(), &read_some_handler);
|
||||
int i8 = stream1.async_read_some(buffer(mutable_char_buffer), lazy);
|
||||
(void)i8;
|
||||
int i9 = stream1.async_read_some(mutable_buffers, lazy);
|
||||
(void)i9;
|
||||
int i10 = stream1.async_read_some(null_buffers(), lazy);
|
||||
(void)i10;
|
||||
}
|
||||
catch (std::exception&)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
void test_sync_operations()
|
||||
{
|
||||
using namespace std; // For memcmp.
|
||||
|
||||
asio::io_context io_context;
|
||||
|
||||
asio::ip::tcp::acceptor acceptor(io_context,
|
||||
asio::ip::tcp::endpoint(asio::ip::tcp::v4(), 0));
|
||||
asio::ip::tcp::endpoint server_endpoint = acceptor.local_endpoint();
|
||||
server_endpoint.address(asio::ip::address_v4::loopback());
|
||||
|
||||
stream_type client_socket(io_context);
|
||||
client_socket.lowest_layer().connect(server_endpoint);
|
||||
|
||||
stream_type server_socket(io_context);
|
||||
acceptor.accept(server_socket.lowest_layer());
|
||||
|
||||
const char write_data[]
|
||||
= "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
|
||||
const asio::const_buffer write_buf = asio::buffer(write_data);
|
||||
|
||||
std::size_t bytes_written = 0;
|
||||
while (bytes_written < sizeof(write_data))
|
||||
{
|
||||
bytes_written += client_socket.write_some(
|
||||
asio::buffer(write_buf + bytes_written));
|
||||
client_socket.flush();
|
||||
}
|
||||
|
||||
char read_data[sizeof(write_data)];
|
||||
const asio::mutable_buffer read_buf = asio::buffer(read_data);
|
||||
|
||||
std::size_t bytes_read = 0;
|
||||
while (bytes_read < sizeof(read_data))
|
||||
{
|
||||
bytes_read += server_socket.read_some(
|
||||
asio::buffer(read_buf + bytes_read));
|
||||
}
|
||||
|
||||
ASIO_CHECK(bytes_written == sizeof(write_data));
|
||||
ASIO_CHECK(bytes_read == sizeof(read_data));
|
||||
ASIO_CHECK(memcmp(write_data, read_data, sizeof(write_data)) == 0);
|
||||
|
||||
bytes_written = 0;
|
||||
while (bytes_written < sizeof(write_data))
|
||||
{
|
||||
bytes_written += server_socket.write_some(
|
||||
asio::buffer(write_buf + bytes_written));
|
||||
server_socket.flush();
|
||||
}
|
||||
|
||||
bytes_read = 0;
|
||||
while (bytes_read < sizeof(read_data))
|
||||
{
|
||||
bytes_read += client_socket.read_some(
|
||||
asio::buffer(read_buf + bytes_read));
|
||||
}
|
||||
|
||||
ASIO_CHECK(bytes_written == sizeof(write_data));
|
||||
ASIO_CHECK(bytes_read == sizeof(read_data));
|
||||
ASIO_CHECK(memcmp(write_data, read_data, sizeof(write_data)) == 0);
|
||||
|
||||
server_socket.close();
|
||||
asio::error_code error;
|
||||
bytes_read = client_socket.read_some(
|
||||
asio::buffer(read_buf), error);
|
||||
|
||||
ASIO_CHECK(bytes_read == 0);
|
||||
ASIO_CHECK(error == asio::error::eof);
|
||||
|
||||
client_socket.close(error);
|
||||
}
|
||||
|
||||
void handle_accept(const asio::error_code& e)
|
||||
{
|
||||
ASIO_CHECK(!e);
|
||||
}
|
||||
|
||||
void handle_write(const asio::error_code& e,
|
||||
std::size_t bytes_transferred,
|
||||
std::size_t* total_bytes_written)
|
||||
{
|
||||
ASIO_CHECK(!e);
|
||||
if (e)
|
||||
throw asio::system_error(e); // Terminate test.
|
||||
*total_bytes_written += bytes_transferred;
|
||||
}
|
||||
|
||||
void handle_flush(const asio::error_code& e)
|
||||
{
|
||||
ASIO_CHECK(!e);
|
||||
}
|
||||
|
||||
void handle_read(const asio::error_code& e,
|
||||
std::size_t bytes_transferred,
|
||||
std::size_t* total_bytes_read)
|
||||
{
|
||||
ASIO_CHECK(!e);
|
||||
if (e)
|
||||
throw asio::system_error(e); // Terminate test.
|
||||
*total_bytes_read += bytes_transferred;
|
||||
}
|
||||
|
||||
void handle_read_eof(const asio::error_code& e,
|
||||
std::size_t bytes_transferred)
|
||||
{
|
||||
ASIO_CHECK(e == asio::error::eof);
|
||||
ASIO_CHECK(bytes_transferred == 0);
|
||||
}
|
||||
|
||||
void test_async_operations()
|
||||
{
|
||||
using namespace std; // For memcmp.
|
||||
|
||||
#if defined(ASIO_HAS_BOOST_BIND)
|
||||
namespace bindns = boost;
|
||||
#else // defined(ASIO_HAS_BOOST_BIND)
|
||||
namespace bindns = std;
|
||||
using std::placeholders::_1;
|
||||
using std::placeholders::_2;
|
||||
#endif // defined(ASIO_HAS_BOOST_BIND)
|
||||
|
||||
asio::io_context io_context;
|
||||
|
||||
asio::ip::tcp::acceptor acceptor(io_context,
|
||||
asio::ip::tcp::endpoint(asio::ip::tcp::v4(), 0));
|
||||
asio::ip::tcp::endpoint server_endpoint = acceptor.local_endpoint();
|
||||
server_endpoint.address(asio::ip::address_v4::loopback());
|
||||
|
||||
stream_type client_socket(io_context);
|
||||
client_socket.lowest_layer().connect(server_endpoint);
|
||||
|
||||
stream_type server_socket(io_context);
|
||||
acceptor.async_accept(server_socket.lowest_layer(), &handle_accept);
|
||||
io_context.run();
|
||||
io_context.restart();
|
||||
|
||||
const char write_data[]
|
||||
= "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
|
||||
const asio::const_buffer write_buf = asio::buffer(write_data);
|
||||
|
||||
std::size_t bytes_written = 0;
|
||||
while (bytes_written < sizeof(write_data))
|
||||
{
|
||||
client_socket.async_write_some(
|
||||
asio::buffer(write_buf + bytes_written),
|
||||
bindns::bind(handle_write, _1, _2, &bytes_written));
|
||||
io_context.run();
|
||||
io_context.restart();
|
||||
client_socket.async_flush(
|
||||
bindns::bind(handle_flush, _1));
|
||||
io_context.run();
|
||||
io_context.restart();
|
||||
}
|
||||
|
||||
char read_data[sizeof(write_data)];
|
||||
const asio::mutable_buffer read_buf = asio::buffer(read_data);
|
||||
|
||||
std::size_t bytes_read = 0;
|
||||
while (bytes_read < sizeof(read_data))
|
||||
{
|
||||
server_socket.async_read_some(
|
||||
asio::buffer(read_buf + bytes_read),
|
||||
bindns::bind(handle_read, _1, _2, &bytes_read));
|
||||
io_context.run();
|
||||
io_context.restart();
|
||||
}
|
||||
|
||||
ASIO_CHECK(bytes_written == sizeof(write_data));
|
||||
ASIO_CHECK(bytes_read == sizeof(read_data));
|
||||
ASIO_CHECK(memcmp(write_data, read_data, sizeof(write_data)) == 0);
|
||||
|
||||
bytes_written = 0;
|
||||
while (bytes_written < sizeof(write_data))
|
||||
{
|
||||
server_socket.async_write_some(
|
||||
asio::buffer(write_buf + bytes_written),
|
||||
bindns::bind(handle_write, _1, _2, &bytes_written));
|
||||
io_context.run();
|
||||
io_context.restart();
|
||||
server_socket.async_flush(
|
||||
bindns::bind(handle_flush, _1));
|
||||
io_context.run();
|
||||
io_context.restart();
|
||||
}
|
||||
|
||||
bytes_read = 0;
|
||||
while (bytes_read < sizeof(read_data))
|
||||
{
|
||||
client_socket.async_read_some(
|
||||
asio::buffer(read_buf + bytes_read),
|
||||
bindns::bind(handle_read, _1, _2, &bytes_read));
|
||||
io_context.run();
|
||||
io_context.restart();
|
||||
}
|
||||
|
||||
ASIO_CHECK(bytes_written == sizeof(write_data));
|
||||
ASIO_CHECK(bytes_read == sizeof(read_data));
|
||||
ASIO_CHECK(memcmp(write_data, read_data, sizeof(write_data)) == 0);
|
||||
|
||||
server_socket.close();
|
||||
client_socket.async_read_some(asio::buffer(read_buf), handle_read_eof);
|
||||
}
|
||||
|
||||
ASIO_TEST_SUITE
|
||||
(
|
||||
"buffered_stream",
|
||||
ASIO_TEST_CASE(test_compile)
|
||||
ASIO_TEST_CASE(test_sync_operations)
|
||||
ASIO_TEST_CASE(test_async_operations)
|
||||
)
|
||||
@@ -0,0 +1,353 @@
|
||||
//
|
||||
// buffered_write_stream.cpp
|
||||
// ~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
//
|
||||
// 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)
|
||||
//
|
||||
|
||||
// Disable autolinking for unit tests.
|
||||
#if !defined(BOOST_ALL_NO_LIB)
|
||||
#define BOOST_ALL_NO_LIB 1
|
||||
#endif // !defined(BOOST_ALL_NO_LIB)
|
||||
|
||||
// Test that header file is self-contained.
|
||||
#include "asio/buffered_write_stream.hpp"
|
||||
|
||||
#include <cstring>
|
||||
#include "archetypes/async_result.hpp"
|
||||
#include "asio/buffer.hpp"
|
||||
#include "asio/io_context.hpp"
|
||||
#include "asio/ip/tcp.hpp"
|
||||
#include "asio/system_error.hpp"
|
||||
#include "unit_test.hpp"
|
||||
|
||||
#if defined(ASIO_HAS_BOOST_ARRAY)
|
||||
# include <boost/array.hpp>
|
||||
#else // defined(ASIO_HAS_BOOST_ARRAY)
|
||||
# include <array>
|
||||
#endif // defined(ASIO_HAS_BOOST_ARRAY)
|
||||
|
||||
#if defined(ASIO_HAS_BOOST_BIND)
|
||||
# include <boost/bind.hpp>
|
||||
#else // defined(ASIO_HAS_BOOST_BIND)
|
||||
# include <functional>
|
||||
#endif // defined(ASIO_HAS_BOOST_BIND)
|
||||
|
||||
typedef asio::buffered_write_stream<
|
||||
asio::ip::tcp::socket> stream_type;
|
||||
|
||||
void write_some_handler(const asio::error_code&, std::size_t)
|
||||
{
|
||||
}
|
||||
|
||||
void flush_handler(const asio::error_code&, std::size_t)
|
||||
{
|
||||
}
|
||||
|
||||
void read_some_handler(const asio::error_code&, std::size_t)
|
||||
{
|
||||
}
|
||||
|
||||
void test_compile()
|
||||
{
|
||||
#if defined(ASIO_HAS_BOOST_ARRAY)
|
||||
using boost::array;
|
||||
#else // defined(ASIO_HAS_BOOST_ARRAY)
|
||||
using std::array;
|
||||
#endif // defined(ASIO_HAS_BOOST_ARRAY)
|
||||
|
||||
using namespace asio;
|
||||
|
||||
try
|
||||
{
|
||||
io_context ioc;
|
||||
char mutable_char_buffer[128] = "";
|
||||
const char const_char_buffer[128] = "";
|
||||
array<asio::mutable_buffer, 2> mutable_buffers = {{
|
||||
asio::buffer(mutable_char_buffer, 10),
|
||||
asio::buffer(mutable_char_buffer + 10, 10) }};
|
||||
array<asio::const_buffer, 2> const_buffers = {{
|
||||
asio::buffer(const_char_buffer, 10),
|
||||
asio::buffer(const_char_buffer + 10, 10) }};
|
||||
archetypes::lazy_handler lazy;
|
||||
asio::error_code ec;
|
||||
|
||||
stream_type stream1(ioc);
|
||||
stream_type stream2(ioc, 1024);
|
||||
|
||||
stream_type::executor_type ex = stream1.get_executor();
|
||||
(void)ex;
|
||||
|
||||
stream_type::lowest_layer_type& lowest_layer = stream1.lowest_layer();
|
||||
(void)lowest_layer;
|
||||
|
||||
stream1.write_some(buffer(mutable_char_buffer));
|
||||
stream1.write_some(buffer(const_char_buffer));
|
||||
stream1.write_some(mutable_buffers);
|
||||
stream1.write_some(const_buffers);
|
||||
stream1.write_some(null_buffers());
|
||||
stream1.write_some(buffer(mutable_char_buffer), ec);
|
||||
stream1.write_some(buffer(const_char_buffer), ec);
|
||||
stream1.write_some(mutable_buffers, ec);
|
||||
stream1.write_some(const_buffers, ec);
|
||||
stream1.write_some(null_buffers(), ec);
|
||||
|
||||
stream1.async_write_some(buffer(mutable_char_buffer), &write_some_handler);
|
||||
stream1.async_write_some(buffer(const_char_buffer), &write_some_handler);
|
||||
stream1.async_write_some(mutable_buffers, &write_some_handler);
|
||||
stream1.async_write_some(const_buffers, &write_some_handler);
|
||||
stream1.async_write_some(null_buffers(), &write_some_handler);
|
||||
int i1 = stream1.async_write_some(buffer(mutable_char_buffer), lazy);
|
||||
(void)i1;
|
||||
int i2 = stream1.async_write_some(buffer(const_char_buffer), lazy);
|
||||
(void)i2;
|
||||
int i3 = stream1.async_write_some(mutable_buffers, lazy);
|
||||
(void)i3;
|
||||
int i4 = stream1.async_write_some(const_buffers, lazy);
|
||||
(void)i4;
|
||||
int i5 = stream1.async_write_some(null_buffers(), lazy);
|
||||
(void)i5;
|
||||
|
||||
stream1.flush();
|
||||
stream1.flush(ec);
|
||||
|
||||
stream1.async_flush(&flush_handler);
|
||||
int i6 = stream1.async_flush(lazy);
|
||||
(void)i6;
|
||||
|
||||
stream1.read_some(buffer(mutable_char_buffer));
|
||||
stream1.read_some(mutable_buffers);
|
||||
stream1.read_some(null_buffers());
|
||||
stream1.read_some(buffer(mutable_char_buffer), ec);
|
||||
stream1.read_some(mutable_buffers, ec);
|
||||
stream1.read_some(null_buffers(), ec);
|
||||
|
||||
stream1.async_read_some(buffer(mutable_char_buffer), &read_some_handler);
|
||||
stream1.async_read_some(mutable_buffers, &read_some_handler);
|
||||
stream1.async_read_some(null_buffers(), &read_some_handler);
|
||||
int i7 = stream1.async_read_some(buffer(mutable_char_buffer), lazy);
|
||||
(void)i7;
|
||||
int i8 = stream1.async_read_some(mutable_buffers, lazy);
|
||||
(void)i8;
|
||||
int i9 = stream1.async_read_some(null_buffers(), lazy);
|
||||
(void)i9;
|
||||
}
|
||||
catch (std::exception&)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
void test_sync_operations()
|
||||
{
|
||||
using namespace std; // For memcmp.
|
||||
|
||||
asio::io_context io_context;
|
||||
|
||||
asio::ip::tcp::acceptor acceptor(io_context,
|
||||
asio::ip::tcp::endpoint(asio::ip::tcp::v4(), 0));
|
||||
asio::ip::tcp::endpoint server_endpoint = acceptor.local_endpoint();
|
||||
server_endpoint.address(asio::ip::address_v4::loopback());
|
||||
|
||||
stream_type client_socket(io_context);
|
||||
client_socket.lowest_layer().connect(server_endpoint);
|
||||
|
||||
stream_type server_socket(io_context);
|
||||
acceptor.accept(server_socket.lowest_layer());
|
||||
|
||||
const char write_data[]
|
||||
= "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
|
||||
const asio::const_buffer write_buf = asio::buffer(write_data);
|
||||
|
||||
std::size_t bytes_written = 0;
|
||||
while (bytes_written < sizeof(write_data))
|
||||
{
|
||||
bytes_written += client_socket.write_some(
|
||||
asio::buffer(write_buf + bytes_written));
|
||||
client_socket.flush();
|
||||
}
|
||||
|
||||
char read_data[sizeof(write_data)];
|
||||
const asio::mutable_buffer read_buf = asio::buffer(read_data);
|
||||
|
||||
std::size_t bytes_read = 0;
|
||||
while (bytes_read < sizeof(read_data))
|
||||
{
|
||||
bytes_read += server_socket.read_some(
|
||||
asio::buffer(read_buf + bytes_read));
|
||||
}
|
||||
|
||||
ASIO_CHECK(bytes_written == sizeof(write_data));
|
||||
ASIO_CHECK(bytes_read == sizeof(read_data));
|
||||
ASIO_CHECK(memcmp(write_data, read_data, sizeof(write_data)) == 0);
|
||||
|
||||
bytes_written = 0;
|
||||
while (bytes_written < sizeof(write_data))
|
||||
{
|
||||
bytes_written += server_socket.write_some(
|
||||
asio::buffer(write_buf + bytes_written));
|
||||
server_socket.flush();
|
||||
}
|
||||
|
||||
bytes_read = 0;
|
||||
while (bytes_read < sizeof(read_data))
|
||||
{
|
||||
bytes_read += client_socket.read_some(
|
||||
asio::buffer(read_buf + bytes_read));
|
||||
}
|
||||
|
||||
ASIO_CHECK(bytes_written == sizeof(write_data));
|
||||
ASIO_CHECK(bytes_read == sizeof(read_data));
|
||||
ASIO_CHECK(memcmp(write_data, read_data, sizeof(write_data)) == 0);
|
||||
|
||||
server_socket.close();
|
||||
asio::error_code error;
|
||||
bytes_read = client_socket.read_some(
|
||||
asio::buffer(read_buf), error);
|
||||
|
||||
ASIO_CHECK(bytes_read == 0);
|
||||
ASIO_CHECK(error == asio::error::eof);
|
||||
|
||||
client_socket.close(error);
|
||||
}
|
||||
|
||||
void handle_accept(const asio::error_code& e)
|
||||
{
|
||||
ASIO_CHECK(!e);
|
||||
}
|
||||
|
||||
void handle_write(const asio::error_code& e,
|
||||
std::size_t bytes_transferred,
|
||||
std::size_t* total_bytes_written)
|
||||
{
|
||||
ASIO_CHECK(!e);
|
||||
if (e)
|
||||
throw asio::system_error(e); // Terminate test.
|
||||
*total_bytes_written += bytes_transferred;
|
||||
}
|
||||
|
||||
void handle_flush(const asio::error_code& e)
|
||||
{
|
||||
ASIO_CHECK(!e);
|
||||
}
|
||||
|
||||
void handle_read(const asio::error_code& e,
|
||||
std::size_t bytes_transferred,
|
||||
std::size_t* total_bytes_read)
|
||||
{
|
||||
ASIO_CHECK(!e);
|
||||
if (e)
|
||||
throw asio::system_error(e); // Terminate test.
|
||||
*total_bytes_read += bytes_transferred;
|
||||
}
|
||||
|
||||
void handle_read_eof(const asio::error_code& e,
|
||||
std::size_t bytes_transferred)
|
||||
{
|
||||
ASIO_CHECK(e == asio::error::eof);
|
||||
ASIO_CHECK(bytes_transferred == 0);
|
||||
}
|
||||
|
||||
void test_async_operations()
|
||||
{
|
||||
using namespace std; // For memcmp.
|
||||
|
||||
#if defined(ASIO_HAS_BOOST_BIND)
|
||||
namespace bindns = boost;
|
||||
#else // defined(ASIO_HAS_BOOST_BIND)
|
||||
namespace bindns = std;
|
||||
using std::placeholders::_1;
|
||||
using std::placeholders::_2;
|
||||
#endif // defined(ASIO_HAS_BOOST_BIND)
|
||||
|
||||
asio::io_context io_context;
|
||||
|
||||
asio::ip::tcp::acceptor acceptor(io_context,
|
||||
asio::ip::tcp::endpoint(asio::ip::tcp::v4(), 0));
|
||||
asio::ip::tcp::endpoint server_endpoint = acceptor.local_endpoint();
|
||||
server_endpoint.address(asio::ip::address_v4::loopback());
|
||||
|
||||
stream_type client_socket(io_context);
|
||||
client_socket.lowest_layer().connect(server_endpoint);
|
||||
|
||||
stream_type server_socket(io_context);
|
||||
acceptor.async_accept(server_socket.lowest_layer(), &handle_accept);
|
||||
io_context.run();
|
||||
io_context.restart();
|
||||
|
||||
const char write_data[]
|
||||
= "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
|
||||
const asio::const_buffer write_buf = asio::buffer(write_data);
|
||||
|
||||
std::size_t bytes_written = 0;
|
||||
while (bytes_written < sizeof(write_data))
|
||||
{
|
||||
client_socket.async_write_some(
|
||||
asio::buffer(write_buf + bytes_written),
|
||||
bindns::bind(handle_write, _1, _2, &bytes_written));
|
||||
io_context.run();
|
||||
io_context.restart();
|
||||
client_socket.async_flush(
|
||||
bindns::bind(handle_flush, _1));
|
||||
io_context.run();
|
||||
io_context.restart();
|
||||
}
|
||||
|
||||
char read_data[sizeof(write_data)];
|
||||
const asio::mutable_buffer read_buf = asio::buffer(read_data);
|
||||
|
||||
std::size_t bytes_read = 0;
|
||||
while (bytes_read < sizeof(read_data))
|
||||
{
|
||||
server_socket.async_read_some(
|
||||
asio::buffer(read_buf + bytes_read),
|
||||
bindns::bind(handle_read, _1, _2, &bytes_read));
|
||||
io_context.run();
|
||||
io_context.restart();
|
||||
}
|
||||
|
||||
ASIO_CHECK(bytes_written == sizeof(write_data));
|
||||
ASIO_CHECK(bytes_read == sizeof(read_data));
|
||||
ASIO_CHECK(memcmp(write_data, read_data, sizeof(write_data)) == 0);
|
||||
|
||||
bytes_written = 0;
|
||||
while (bytes_written < sizeof(write_data))
|
||||
{
|
||||
server_socket.async_write_some(
|
||||
asio::buffer(write_buf + bytes_written),
|
||||
bindns::bind(handle_write, _1, _2, &bytes_written));
|
||||
io_context.run();
|
||||
io_context.restart();
|
||||
server_socket.async_flush(
|
||||
bindns::bind(handle_flush, _1));
|
||||
io_context.run();
|
||||
io_context.restart();
|
||||
}
|
||||
|
||||
bytes_read = 0;
|
||||
while (bytes_read < sizeof(read_data))
|
||||
{
|
||||
client_socket.async_read_some(
|
||||
asio::buffer(read_buf + bytes_read),
|
||||
bindns::bind(handle_read, _1, _2, &bytes_read));
|
||||
io_context.run();
|
||||
io_context.restart();
|
||||
}
|
||||
|
||||
ASIO_CHECK(bytes_written == sizeof(write_data));
|
||||
ASIO_CHECK(bytes_read == sizeof(read_data));
|
||||
ASIO_CHECK(memcmp(write_data, read_data, sizeof(write_data)) == 0);
|
||||
|
||||
server_socket.close();
|
||||
client_socket.async_read_some(asio::buffer(read_buf), handle_read_eof);
|
||||
}
|
||||
|
||||
ASIO_TEST_SUITE
|
||||
(
|
||||
"buffered_write_stream",
|
||||
ASIO_TEST_CASE(test_compile)
|
||||
ASIO_TEST_CASE(test_sync_operations)
|
||||
ASIO_TEST_CASE(test_async_operations)
|
||||
)
|
||||
@@ -0,0 +1,292 @@
|
||||
//
|
||||
// buffers_iterator.cpp
|
||||
// ~~~~~~~~~~~~~~~~~~~~
|
||||
//
|
||||
// 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)
|
||||
//
|
||||
|
||||
// Disable autolinking for unit tests.
|
||||
#if !defined(BOOST_ALL_NO_LIB)
|
||||
#define BOOST_ALL_NO_LIB 1
|
||||
#endif // !defined(BOOST_ALL_NO_LIB)
|
||||
|
||||
// Test that header file is self-contained.
|
||||
#include "asio/buffers_iterator.hpp"
|
||||
|
||||
#include "asio/buffer.hpp"
|
||||
#include "unit_test.hpp"
|
||||
|
||||
#if defined(ASIO_HAS_BOOST_ARRAY)
|
||||
# include <boost/array.hpp>
|
||||
#endif // defined(ASIO_HAS_BOOST_ARRAY)
|
||||
|
||||
#if defined(ASIO_HAS_STD_ARRAY)
|
||||
# include <array>
|
||||
#endif // defined(ASIO_HAS_STD_ARRAY)
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
// buffers_iterator_compile test
|
||||
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
// The following test checks that all operations on the buffers_iterator compile
|
||||
// and link correctly. Runtime failures are ignored.
|
||||
|
||||
namespace buffers_iterator_compile {
|
||||
|
||||
#if defined(ASIO_HAS_BOOST_ARRAY)
|
||||
using boost::array;
|
||||
#elif defined(ASIO_HAS_STD_ARRAY)
|
||||
using std::array;
|
||||
#endif // defined(ASIO_HAS_BOOST_ARRAY)
|
||||
using std::vector;
|
||||
using namespace asio;
|
||||
|
||||
void test()
|
||||
{
|
||||
try
|
||||
{
|
||||
char data1[16], data2[16];
|
||||
const char cdata1[16] = "", cdata2[16] = "";
|
||||
mutable_buffer mb1 = buffer(data1);
|
||||
array<mutable_buffer, 2> mb2 = {{ buffer(data1), buffer(data2) }};
|
||||
std::vector<mutable_buffer> mb3;
|
||||
mb3.push_back(buffer(data1));
|
||||
const_buffer cb1 = buffer(cdata1);
|
||||
array<const_buffer, 2> cb2 = {{ buffer(cdata1), buffer(cdata2) }};
|
||||
vector<const_buffer> cb3;
|
||||
cb3.push_back(buffer(cdata1));
|
||||
|
||||
|
||||
// buffers_iterator constructors.
|
||||
|
||||
buffers_iterator<mutable_buffer, char> bi1;
|
||||
buffers_iterator<mutable_buffer, const char> bi2;
|
||||
buffers_iterator<array<mutable_buffer, 2>, char> bi3;
|
||||
buffers_iterator<array<mutable_buffer, 2>, const char> bi4;
|
||||
buffers_iterator<vector<mutable_buffer>, char> bi5;
|
||||
buffers_iterator<vector<mutable_buffer>, const char> bi6;
|
||||
buffers_iterator<const_buffer, char> bi7;
|
||||
buffers_iterator<const_buffer, const char> bi8;
|
||||
buffers_iterator<array<const_buffer, 2>, char> bi9;
|
||||
buffers_iterator<array<const_buffer, 2>, const char> bi10;
|
||||
buffers_iterator<vector<const_buffer>, char> bi11;
|
||||
buffers_iterator<vector<const_buffer>, const char> bi12;
|
||||
|
||||
buffers_iterator<mutable_buffer, char> bi13(
|
||||
buffers_iterator<mutable_buffer, char>::begin(mb1));
|
||||
buffers_iterator<mutable_buffer, const char> bi14(
|
||||
buffers_iterator<mutable_buffer, const char>::begin(mb1));
|
||||
buffers_iterator<array<mutable_buffer, 2>, char> bi15(
|
||||
buffers_iterator<array<mutable_buffer, 2>, char>::begin(mb2));
|
||||
buffers_iterator<array<mutable_buffer, 2>, const char> bi16(
|
||||
buffers_iterator<array<mutable_buffer, 2>, const char>::begin(mb2));
|
||||
buffers_iterator<vector<mutable_buffer>, char> bi17(
|
||||
buffers_iterator<vector<mutable_buffer>, char>::begin(mb3));
|
||||
buffers_iterator<vector<mutable_buffer>, const char> bi18(
|
||||
buffers_iterator<vector<mutable_buffer>, const char>::begin(mb3));
|
||||
buffers_iterator<const_buffer, char> bi19(
|
||||
buffers_iterator<const_buffer, char>::begin(cb1));
|
||||
buffers_iterator<const_buffer, const char> bi20(
|
||||
buffers_iterator<const_buffer, const char>::begin(cb1));
|
||||
buffers_iterator<array<const_buffer, 2>, char> bi21(
|
||||
buffers_iterator<array<const_buffer, 2>, char>::begin(cb2));
|
||||
buffers_iterator<array<const_buffer, 2>, const char> bi22(
|
||||
buffers_iterator<array<const_buffer, 2>, const char>::begin(cb2));
|
||||
buffers_iterator<vector<const_buffer>, char> bi23(
|
||||
buffers_iterator<vector<const_buffer>, char>::begin(cb3));
|
||||
buffers_iterator<vector<const_buffer>, const char> bi24(
|
||||
buffers_iterator<vector<const_buffer>, const char>::begin(cb3));
|
||||
|
||||
// buffers_iterator member functions.
|
||||
|
||||
bi1 = buffers_iterator<mutable_buffer, char>::begin(mb1);
|
||||
bi2 = buffers_iterator<mutable_buffer, const char>::begin(mb1);
|
||||
bi3 = buffers_iterator<array<mutable_buffer, 2>, char>::begin(mb2);
|
||||
bi4 = buffers_iterator<array<mutable_buffer, 2>, const char>::begin(mb2);
|
||||
bi5 = buffers_iterator<vector<mutable_buffer>, char>::begin(mb3);
|
||||
bi6 = buffers_iterator<vector<mutable_buffer>, const char>::begin(mb3);
|
||||
bi7 = buffers_iterator<const_buffer, char>::begin(cb1);
|
||||
bi8 = buffers_iterator<const_buffer, const char>::begin(cb1);
|
||||
bi9 = buffers_iterator<array<const_buffer, 2>, char>::begin(cb2);
|
||||
bi10 = buffers_iterator<array<const_buffer, 2>, const char>::begin(cb2);
|
||||
bi11 = buffers_iterator<vector<const_buffer>, char>::begin(cb3);
|
||||
bi12 = buffers_iterator<vector<const_buffer>, const char>::begin(cb3);
|
||||
|
||||
bi1 = buffers_iterator<mutable_buffer, char>::end(mb1);
|
||||
bi2 = buffers_iterator<mutable_buffer, const char>::end(mb1);
|
||||
bi3 = buffers_iterator<array<mutable_buffer, 2>, char>::end(mb2);
|
||||
bi4 = buffers_iterator<array<mutable_buffer, 2>, const char>::end(mb2);
|
||||
bi5 = buffers_iterator<vector<mutable_buffer>, char>::end(mb3);
|
||||
bi6 = buffers_iterator<vector<mutable_buffer>, const char>::end(mb3);
|
||||
bi7 = buffers_iterator<const_buffer, char>::end(cb1);
|
||||
bi8 = buffers_iterator<const_buffer, const char>::end(cb1);
|
||||
bi9 = buffers_iterator<array<const_buffer, 2>, char>::end(cb2);
|
||||
bi10 = buffers_iterator<array<const_buffer, 2>, const char>::end(cb2);
|
||||
bi11 = buffers_iterator<vector<const_buffer>, char>::end(cb3);
|
||||
bi12 = buffers_iterator<vector<const_buffer>, const char>::end(cb3);
|
||||
|
||||
// buffers_iterator related functions.
|
||||
|
||||
bi1 = buffers_begin(mb1);
|
||||
bi3 = buffers_begin(mb2);
|
||||
bi5 = buffers_begin(mb3);
|
||||
bi7 = buffers_begin(cb1);
|
||||
bi9 = buffers_begin(cb2);
|
||||
bi11 = buffers_begin(cb3);
|
||||
|
||||
bi1 = buffers_end(mb1);
|
||||
bi3 = buffers_end(mb2);
|
||||
bi5 = buffers_end(mb3);
|
||||
bi7 = buffers_end(cb1);
|
||||
bi9 = buffers_end(cb2);
|
||||
bi11 = buffers_end(cb3);
|
||||
|
||||
// RandomAccessIterator operations.
|
||||
|
||||
--bi1;
|
||||
--bi2;
|
||||
--bi3;
|
||||
--bi4;
|
||||
--bi5;
|
||||
--bi6;
|
||||
--bi7;
|
||||
--bi8;
|
||||
--bi9;
|
||||
--bi10;
|
||||
--bi11;
|
||||
--bi12;
|
||||
|
||||
++bi1;
|
||||
++bi2;
|
||||
++bi3;
|
||||
++bi4;
|
||||
++bi5;
|
||||
++bi6;
|
||||
++bi7;
|
||||
++bi8;
|
||||
++bi9;
|
||||
++bi10;
|
||||
++bi11;
|
||||
++bi12;
|
||||
|
||||
bi1--;
|
||||
bi2--;
|
||||
bi3--;
|
||||
bi4--;
|
||||
bi5--;
|
||||
bi6--;
|
||||
bi7--;
|
||||
bi8--;
|
||||
bi9--;
|
||||
bi10--;
|
||||
bi11--;
|
||||
bi12--;
|
||||
|
||||
bi1++;
|
||||
bi2++;
|
||||
bi3++;
|
||||
bi4++;
|
||||
bi5++;
|
||||
bi6++;
|
||||
bi7++;
|
||||
bi8++;
|
||||
bi9++;
|
||||
bi10++;
|
||||
bi11++;
|
||||
bi12++;
|
||||
|
||||
bi1 -= 1;
|
||||
bi2 -= 1;
|
||||
bi3 -= 1;
|
||||
bi4 -= 1;
|
||||
bi5 -= 1;
|
||||
bi6 -= 1;
|
||||
bi7 -= 1;
|
||||
bi8 -= 1;
|
||||
bi9 -= 1;
|
||||
bi10 -= 1;
|
||||
bi11 -= 1;
|
||||
bi12 -= 1;
|
||||
|
||||
bi1 += 1;
|
||||
bi2 += 1;
|
||||
bi3 += 1;
|
||||
bi4 += 1;
|
||||
bi5 += 1;
|
||||
bi6 += 1;
|
||||
bi7 += 1;
|
||||
bi8 += 1;
|
||||
bi9 += 1;
|
||||
bi10 += 1;
|
||||
bi11 += 1;
|
||||
bi12 += 1;
|
||||
|
||||
bi1 = bi1 - 1;
|
||||
bi2 = bi2 - 1;
|
||||
bi3 = bi3 - 1;
|
||||
bi4 = bi4 - 1;
|
||||
bi5 = bi5 - 1;
|
||||
bi6 = bi6 - 1;
|
||||
bi7 = bi7 - 1;
|
||||
bi8 = bi8 - 1;
|
||||
bi9 = bi9 - 1;
|
||||
bi10 = bi10 - 1;
|
||||
bi11 = bi11 - 1;
|
||||
bi12 = bi12 - 1;
|
||||
|
||||
bi1 = bi1 + 1;
|
||||
bi2 = bi2 + 1;
|
||||
bi3 = bi3 + 1;
|
||||
bi4 = bi4 + 1;
|
||||
bi5 = bi5 + 1;
|
||||
bi6 = bi6 + 1;
|
||||
bi7 = bi7 + 1;
|
||||
bi8 = bi8 + 1;
|
||||
bi9 = bi9 + 1;
|
||||
bi10 = bi10 + 1;
|
||||
bi11 = bi11 + 1;
|
||||
bi12 = bi12 + 1;
|
||||
|
||||
bi1 = (-1) + bi1;
|
||||
bi2 = (-1) + bi2;
|
||||
bi3 = (-1) + bi3;
|
||||
bi4 = (-1) + bi4;
|
||||
bi5 = (-1) + bi5;
|
||||
bi6 = (-1) + bi6;
|
||||
bi7 = (-1) + bi7;
|
||||
bi8 = (-1) + bi8;
|
||||
bi9 = (-1) + bi9;
|
||||
bi10 = (-1) + bi10;
|
||||
bi11 = (-1) + bi11;
|
||||
bi12 = (-1) + bi12;
|
||||
|
||||
(void)static_cast<std::ptrdiff_t>(bi13 - bi1);
|
||||
(void)static_cast<std::ptrdiff_t>(bi14 - bi2);
|
||||
(void)static_cast<std::ptrdiff_t>(bi15 - bi3);
|
||||
(void)static_cast<std::ptrdiff_t>(bi16 - bi4);
|
||||
(void)static_cast<std::ptrdiff_t>(bi17 - bi5);
|
||||
(void)static_cast<std::ptrdiff_t>(bi18 - bi6);
|
||||
(void)static_cast<std::ptrdiff_t>(bi19 - bi7);
|
||||
(void)static_cast<std::ptrdiff_t>(bi20 - bi8);
|
||||
(void)static_cast<std::ptrdiff_t>(bi21 - bi9);
|
||||
(void)static_cast<std::ptrdiff_t>(bi22 - bi10);
|
||||
(void)static_cast<std::ptrdiff_t>(bi23 - bi11);
|
||||
(void)static_cast<std::ptrdiff_t>(bi24 - bi12);
|
||||
}
|
||||
catch (std::exception&)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace buffers_iterator_compile
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
ASIO_TEST_SUITE
|
||||
(
|
||||
"buffers_iterator",
|
||||
ASIO_TEST_CASE(buffers_iterator_compile::test)
|
||||
)
|
||||
@@ -0,0 +1,25 @@
|
||||
//
|
||||
// co_spawn.cpp
|
||||
// ~~~~~~~~~~~~
|
||||
//
|
||||
// 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)
|
||||
//
|
||||
|
||||
// Disable autolinking for unit tests.
|
||||
#if !defined(BOOST_ALL_NO_LIB)
|
||||
#define BOOST_ALL_NO_LIB 1
|
||||
#endif // !defined(BOOST_ALL_NO_LIB)
|
||||
|
||||
// Test that header file is self-contained.
|
||||
#include "asio/co_spawn.hpp"
|
||||
|
||||
#include "unit_test.hpp"
|
||||
|
||||
ASIO_TEST_SUITE
|
||||
(
|
||||
"co_spawn",
|
||||
ASIO_TEST_CASE(null_test)
|
||||
)
|
||||
@@ -0,0 +1,25 @@
|
||||
//
|
||||
// completion_condition.cpp
|
||||
// ~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
//
|
||||
// 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)
|
||||
//
|
||||
|
||||
// Disable autolinking for unit tests.
|
||||
#if !defined(BOOST_ALL_NO_LIB)
|
||||
#define BOOST_ALL_NO_LIB 1
|
||||
#endif // !defined(BOOST_ALL_NO_LIB)
|
||||
|
||||
// Test that header file is self-contained.
|
||||
#include "asio/completion_condition.hpp"
|
||||
|
||||
#include "unit_test.hpp"
|
||||
|
||||
ASIO_TEST_SUITE
|
||||
(
|
||||
"completion_condition",
|
||||
ASIO_TEST_CASE(null_test)
|
||||
)
|
||||
@@ -0,0 +1,185 @@
|
||||
//
|
||||
// compose.cpp
|
||||
// ~~~~~~~~~~~
|
||||
//
|
||||
// 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)
|
||||
//
|
||||
|
||||
// Disable autolinking for unit tests.
|
||||
#if !defined(BOOST_ALL_NO_LIB)
|
||||
#define BOOST_ALL_NO_LIB 1
|
||||
#endif // !defined(BOOST_ALL_NO_LIB)
|
||||
|
||||
// Test that header file is self-contained.
|
||||
#include "asio/compose.hpp"
|
||||
|
||||
#include "unit_test.hpp"
|
||||
|
||||
#include "asio/io_context.hpp"
|
||||
#include "asio/post.hpp"
|
||||
|
||||
#if defined(ASIO_HAS_BOOST_BIND)
|
||||
# include <boost/bind.hpp>
|
||||
#else // defined(ASIO_HAS_BOOST_BIND)
|
||||
# include <functional>
|
||||
#endif // defined(ASIO_HAS_BOOST_BIND)
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
class impl_0_completion_args
|
||||
{
|
||||
public:
|
||||
explicit impl_0_completion_args(asio::io_context& ioc)
|
||||
: ioc_(ioc),
|
||||
state_(starting)
|
||||
{
|
||||
}
|
||||
|
||||
template <typename Self>
|
||||
void operator()(Self& self)
|
||||
{
|
||||
switch (state_)
|
||||
{
|
||||
case starting:
|
||||
state_ = posting;
|
||||
asio::post(ioc_, ASIO_MOVE_CAST(Self)(self));
|
||||
break;
|
||||
case posting:
|
||||
self.complete();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
asio::io_context& ioc_;
|
||||
enum { starting, posting } state_;
|
||||
};
|
||||
|
||||
template <typename CompletionToken>
|
||||
ASIO_INITFN_RESULT_TYPE(CompletionToken, void())
|
||||
async_0_completion_args(asio::io_context& ioc,
|
||||
ASIO_MOVE_ARG(CompletionToken) token)
|
||||
{
|
||||
return asio::async_compose<CompletionToken, void()>(
|
||||
impl_0_completion_args(ioc), token);
|
||||
}
|
||||
|
||||
void compose_0_args_handler(int* count)
|
||||
{
|
||||
++(*count);
|
||||
}
|
||||
|
||||
void compose_0_completion_args_test()
|
||||
{
|
||||
#if defined(ASIO_HAS_BOOST_BIND)
|
||||
namespace bindns = boost;
|
||||
#else // defined(ASIO_HAS_BOOST_BIND)
|
||||
namespace bindns = std;
|
||||
#endif // defined(ASIO_HAS_BOOST_BIND)
|
||||
|
||||
asio::io_context ioc;
|
||||
int count = 0;
|
||||
|
||||
async_0_completion_args(ioc, bindns::bind(&compose_0_args_handler, &count));
|
||||
|
||||
// No handlers can be called until run() is called.
|
||||
ASIO_CHECK(!ioc.stopped());
|
||||
ASIO_CHECK(count == 0);
|
||||
|
||||
ioc.run();
|
||||
|
||||
// The run() call will not return until all work has finished.
|
||||
ASIO_CHECK(ioc.stopped());
|
||||
ASIO_CHECK(count == 1);
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
class impl_1_completion_arg
|
||||
{
|
||||
public:
|
||||
explicit impl_1_completion_arg(asio::io_context& ioc)
|
||||
: ioc_(ioc),
|
||||
state_(starting)
|
||||
{
|
||||
}
|
||||
|
||||
template <typename Self>
|
||||
void operator()(Self& self)
|
||||
{
|
||||
switch (state_)
|
||||
{
|
||||
case starting:
|
||||
state_ = posting;
|
||||
asio::post(ioc_, ASIO_MOVE_CAST(Self)(self));
|
||||
break;
|
||||
case posting:
|
||||
self.complete(42);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
asio::io_context& ioc_;
|
||||
enum { starting, posting } state_;
|
||||
};
|
||||
|
||||
template <typename CompletionToken>
|
||||
ASIO_INITFN_RESULT_TYPE(CompletionToken, void(int))
|
||||
async_1_completion_arg(asio::io_context& ioc,
|
||||
ASIO_MOVE_ARG(CompletionToken) token)
|
||||
{
|
||||
return asio::async_compose<CompletionToken, void(int)>(
|
||||
impl_1_completion_arg(ioc), token);
|
||||
}
|
||||
|
||||
void compose_1_args_handler(int* count, int* result_out, int result)
|
||||
{
|
||||
++(*count);
|
||||
*result_out = result;
|
||||
}
|
||||
|
||||
void compose_1_completion_arg_test()
|
||||
{
|
||||
#if defined(ASIO_HAS_BOOST_BIND)
|
||||
namespace bindns = boost;
|
||||
#else // defined(ASIO_HAS_BOOST_BIND)
|
||||
namespace bindns = std;
|
||||
using std::placeholders::_1;
|
||||
#endif // defined(ASIO_HAS_BOOST_BIND)
|
||||
|
||||
asio::io_context ioc;
|
||||
int count = 0;
|
||||
int result = 0;
|
||||
|
||||
async_1_completion_arg(ioc,
|
||||
bindns::bind(&compose_1_args_handler, &count, &result, _1));
|
||||
|
||||
// No handlers can be called until run() is called.
|
||||
ASIO_CHECK(!ioc.stopped());
|
||||
ASIO_CHECK(count == 0);
|
||||
ASIO_CHECK(result == 0);
|
||||
|
||||
ioc.run();
|
||||
|
||||
// The run() call will not return until all work has finished.
|
||||
ASIO_CHECK(ioc.stopped());
|
||||
ASIO_CHECK(count == 1);
|
||||
ASIO_CHECK(result == 42);
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
ASIO_TEST_SUITE
|
||||
(
|
||||
"compose",
|
||||
ASIO_TEST_CASE(compose_0_completion_args_test)
|
||||
ASIO_TEST_CASE(compose_1_completion_arg_test)
|
||||
)
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,112 @@
|
||||
//
|
||||
// coroutine.cpp
|
||||
// ~~~~~~~~~~~~~
|
||||
//
|
||||
// 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)
|
||||
//
|
||||
|
||||
// Disable autolinking for unit tests.
|
||||
#if !defined(BOOST_ALL_NO_LIB)
|
||||
#define BOOST_ALL_NO_LIB 1
|
||||
#endif // !defined(BOOST_ALL_NO_LIB)
|
||||
|
||||
// Test that header file is self-contained.
|
||||
#include "asio/coroutine.hpp"
|
||||
|
||||
#include "unit_test.hpp"
|
||||
|
||||
// Must come after all other headers.
|
||||
#include "asio/yield.hpp"
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
// Coroutine completes via yield break.
|
||||
|
||||
void yield_break_coro(asio::coroutine& coro)
|
||||
{
|
||||
reenter (coro)
|
||||
{
|
||||
yield return;
|
||||
yield break;
|
||||
}
|
||||
}
|
||||
|
||||
void yield_break_test()
|
||||
{
|
||||
asio::coroutine coro;
|
||||
ASIO_CHECK(!coro.is_complete());
|
||||
yield_break_coro(coro);
|
||||
ASIO_CHECK(!coro.is_complete());
|
||||
yield_break_coro(coro);
|
||||
ASIO_CHECK(coro.is_complete());
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
// Coroutine completes via return.
|
||||
|
||||
void return_coro(asio::coroutine& coro)
|
||||
{
|
||||
reenter (coro)
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
void return_test()
|
||||
{
|
||||
asio::coroutine coro;
|
||||
return_coro(coro);
|
||||
ASIO_CHECK(coro.is_complete());
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
// Coroutine completes via exception.
|
||||
|
||||
void exception_coro(asio::coroutine& coro)
|
||||
{
|
||||
reenter (coro)
|
||||
{
|
||||
throw 1;
|
||||
}
|
||||
}
|
||||
|
||||
void exception_test()
|
||||
{
|
||||
asio::coroutine coro;
|
||||
try { exception_coro(coro); } catch (int) {}
|
||||
ASIO_CHECK(coro.is_complete());
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
// Coroutine completes by falling off the end.
|
||||
|
||||
void fall_off_end_coro(asio::coroutine& coro)
|
||||
{
|
||||
reenter (coro)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
void fall_off_end_test()
|
||||
{
|
||||
asio::coroutine coro;
|
||||
fall_off_end_coro(coro);
|
||||
ASIO_CHECK(coro.is_complete());
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
ASIO_TEST_SUITE
|
||||
(
|
||||
"coroutine",
|
||||
ASIO_TEST_CASE(yield_break_test)
|
||||
ASIO_TEST_CASE(return_test)
|
||||
ASIO_TEST_CASE(exception_test)
|
||||
ASIO_TEST_CASE(fall_off_end_test)
|
||||
)
|
||||
@@ -0,0 +1,392 @@
|
||||
//
|
||||
// deadline_timer.cpp
|
||||
// ~~~~~~~~~~~~~~~~~~
|
||||
//
|
||||
// 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)
|
||||
//
|
||||
|
||||
// Disable autolinking for unit tests.
|
||||
#if !defined(BOOST_ALL_NO_LIB)
|
||||
#define BOOST_ALL_NO_LIB 1
|
||||
#endif // !defined(BOOST_ALL_NO_LIB)
|
||||
|
||||
// Test that header file is self-contained.
|
||||
#include "asio/deadline_timer.hpp"
|
||||
|
||||
#include "unit_test.hpp"
|
||||
|
||||
#if defined(ASIO_HAS_BOOST_DATE_TIME)
|
||||
|
||||
#include <boost/bind.hpp>
|
||||
#include "archetypes/async_result.hpp"
|
||||
#include "asio/executor_work_guard.hpp"
|
||||
#include "asio/io_context.hpp"
|
||||
#include "asio/placeholders.hpp"
|
||||
#include "asio/thread.hpp"
|
||||
|
||||
using namespace boost::posix_time;
|
||||
|
||||
void increment(int* count)
|
||||
{
|
||||
++(*count);
|
||||
}
|
||||
|
||||
void decrement_to_zero(asio::deadline_timer* t, int* count)
|
||||
{
|
||||
if (*count > 0)
|
||||
{
|
||||
--(*count);
|
||||
|
||||
int before_value = *count;
|
||||
|
||||
t->expires_at(t->expires_at() + seconds(1));
|
||||
t->async_wait(boost::bind(decrement_to_zero, t, count));
|
||||
|
||||
// Completion cannot nest, so count value should remain unchanged.
|
||||
ASIO_CHECK(*count == before_value);
|
||||
}
|
||||
}
|
||||
|
||||
void increment_if_not_cancelled(int* count,
|
||||
const asio::error_code& ec)
|
||||
{
|
||||
if (!ec)
|
||||
++(*count);
|
||||
}
|
||||
|
||||
void cancel_timer(asio::deadline_timer* t)
|
||||
{
|
||||
std::size_t num_cancelled = t->cancel();
|
||||
ASIO_CHECK(num_cancelled == 1);
|
||||
}
|
||||
|
||||
void cancel_one_timer(asio::deadline_timer* t)
|
||||
{
|
||||
std::size_t num_cancelled = t->cancel_one();
|
||||
ASIO_CHECK(num_cancelled == 1);
|
||||
}
|
||||
|
||||
ptime now()
|
||||
{
|
||||
#if defined(BOOST_DATE_TIME_HAS_HIGH_PRECISION_CLOCK)
|
||||
return microsec_clock::universal_time();
|
||||
#else // defined(BOOST_DATE_TIME_HAS_HIGH_PRECISION_CLOCK)
|
||||
return second_clock::universal_time();
|
||||
#endif // defined(BOOST_DATE_TIME_HAS_HIGH_PRECISION_CLOCK)
|
||||
}
|
||||
|
||||
void deadline_timer_test()
|
||||
{
|
||||
asio::io_context ioc;
|
||||
int count = 0;
|
||||
|
||||
ptime start = now();
|
||||
|
||||
asio::deadline_timer t1(ioc, seconds(1));
|
||||
t1.wait();
|
||||
|
||||
// The timer must block until after its expiry time.
|
||||
ptime end = now();
|
||||
ptime expected_end = start + seconds(1);
|
||||
ASIO_CHECK(expected_end < end || expected_end == end);
|
||||
|
||||
start = now();
|
||||
|
||||
asio::deadline_timer t2(ioc, seconds(1) + microseconds(500000));
|
||||
t2.wait();
|
||||
|
||||
// The timer must block until after its expiry time.
|
||||
end = now();
|
||||
expected_end = start + seconds(1) + microseconds(500000);
|
||||
ASIO_CHECK(expected_end < end || expected_end == end);
|
||||
|
||||
t2.expires_at(t2.expires_at() + seconds(1));
|
||||
t2.wait();
|
||||
|
||||
// The timer must block until after its expiry time.
|
||||
end = now();
|
||||
expected_end += seconds(1);
|
||||
ASIO_CHECK(expected_end < end || expected_end == end);
|
||||
|
||||
start = now();
|
||||
|
||||
t2.expires_from_now(seconds(1) + microseconds(200000));
|
||||
t2.wait();
|
||||
|
||||
// The timer must block until after its expiry time.
|
||||
end = now();
|
||||
expected_end = start + seconds(1) + microseconds(200000);
|
||||
ASIO_CHECK(expected_end < end || expected_end == end);
|
||||
|
||||
start = now();
|
||||
|
||||
asio::deadline_timer t3(ioc, seconds(5));
|
||||
t3.async_wait(boost::bind(increment, &count));
|
||||
|
||||
// No completions can be delivered until run() is called.
|
||||
ASIO_CHECK(count == 0);
|
||||
|
||||
ioc.run();
|
||||
|
||||
// The run() call will not return until all operations have finished, and
|
||||
// this should not be until after the timer's expiry time.
|
||||
ASIO_CHECK(count == 1);
|
||||
end = now();
|
||||
expected_end = start + seconds(1);
|
||||
ASIO_CHECK(expected_end < end || expected_end == end);
|
||||
|
||||
count = 3;
|
||||
start = now();
|
||||
|
||||
asio::deadline_timer t4(ioc, seconds(1));
|
||||
t4.async_wait(boost::bind(decrement_to_zero, &t4, &count));
|
||||
|
||||
// No completions can be delivered until run() is called.
|
||||
ASIO_CHECK(count == 3);
|
||||
|
||||
ioc.restart();
|
||||
ioc.run();
|
||||
|
||||
// The run() call will not return until all operations have finished, and
|
||||
// this should not be until after the timer's final expiry time.
|
||||
ASIO_CHECK(count == 0);
|
||||
end = now();
|
||||
expected_end = start + seconds(3);
|
||||
ASIO_CHECK(expected_end < end || expected_end == end);
|
||||
|
||||
count = 0;
|
||||
start = now();
|
||||
|
||||
asio::deadline_timer t5(ioc, seconds(10));
|
||||
t5.async_wait(boost::bind(increment_if_not_cancelled, &count,
|
||||
asio::placeholders::error));
|
||||
asio::deadline_timer t6(ioc, seconds(1));
|
||||
t6.async_wait(boost::bind(cancel_timer, &t5));
|
||||
|
||||
// No completions can be delivered until run() is called.
|
||||
ASIO_CHECK(count == 0);
|
||||
|
||||
ioc.restart();
|
||||
ioc.run();
|
||||
|
||||
// The timer should have been cancelled, so count should not have changed.
|
||||
// The total run time should not have been much more than 1 second (and
|
||||
// certainly far less than 10 seconds).
|
||||
ASIO_CHECK(count == 0);
|
||||
end = now();
|
||||
expected_end = start + seconds(2);
|
||||
ASIO_CHECK(end < expected_end);
|
||||
|
||||
// Wait on the timer again without cancelling it. This time the asynchronous
|
||||
// wait should run to completion and increment the counter.
|
||||
t5.async_wait(boost::bind(increment_if_not_cancelled, &count,
|
||||
asio::placeholders::error));
|
||||
|
||||
ioc.restart();
|
||||
ioc.run();
|
||||
|
||||
// The timer should not have been cancelled, so count should have changed.
|
||||
// The total time since the timer was created should be more than 10 seconds.
|
||||
ASIO_CHECK(count == 1);
|
||||
end = now();
|
||||
expected_end = start + seconds(10);
|
||||
ASIO_CHECK(expected_end < end || expected_end == end);
|
||||
|
||||
count = 0;
|
||||
start = now();
|
||||
|
||||
// Start two waits on a timer, one of which will be cancelled. The one
|
||||
// which is not cancelled should still run to completion and increment the
|
||||
// counter.
|
||||
asio::deadline_timer t7(ioc, seconds(3));
|
||||
t7.async_wait(boost::bind(increment_if_not_cancelled, &count,
|
||||
asio::placeholders::error));
|
||||
t7.async_wait(boost::bind(increment_if_not_cancelled, &count,
|
||||
asio::placeholders::error));
|
||||
asio::deadline_timer t8(ioc, seconds(1));
|
||||
t8.async_wait(boost::bind(cancel_one_timer, &t7));
|
||||
|
||||
ioc.restart();
|
||||
ioc.run();
|
||||
|
||||
// One of the waits should not have been cancelled, so count should have
|
||||
// changed. The total time since the timer was created should be more than 3
|
||||
// seconds.
|
||||
ASIO_CHECK(count == 1);
|
||||
end = now();
|
||||
expected_end = start + seconds(3);
|
||||
ASIO_CHECK(expected_end < end || expected_end == end);
|
||||
}
|
||||
|
||||
void timer_handler(const asio::error_code&)
|
||||
{
|
||||
}
|
||||
|
||||
void deadline_timer_cancel_test()
|
||||
{
|
||||
static asio::io_context io_context;
|
||||
struct timer
|
||||
{
|
||||
asio::deadline_timer t;
|
||||
timer() : t(io_context) { t.expires_at(boost::posix_time::pos_infin); }
|
||||
} timers[50];
|
||||
|
||||
timers[2].t.async_wait(&timer_handler);
|
||||
timers[41].t.async_wait(&timer_handler);
|
||||
for (int i = 10; i < 20; ++i)
|
||||
timers[i].t.async_wait(&timer_handler);
|
||||
|
||||
ASIO_CHECK(timers[2].t.cancel() == 1);
|
||||
ASIO_CHECK(timers[41].t.cancel() == 1);
|
||||
for (int i = 10; i < 20; ++i)
|
||||
ASIO_CHECK(timers[i].t.cancel() == 1);
|
||||
}
|
||||
|
||||
struct custom_allocation_timer_handler
|
||||
{
|
||||
custom_allocation_timer_handler(int* count) : count_(count) {}
|
||||
void operator()(const asio::error_code&) {}
|
||||
int* count_;
|
||||
};
|
||||
|
||||
void* asio_handler_allocate(std::size_t size,
|
||||
custom_allocation_timer_handler* handler)
|
||||
{
|
||||
++(*handler->count_);
|
||||
return ::operator new(size);
|
||||
}
|
||||
|
||||
void asio_handler_deallocate(void* pointer, std::size_t,
|
||||
custom_allocation_timer_handler* handler)
|
||||
{
|
||||
--(*handler->count_);
|
||||
::operator delete(pointer);
|
||||
}
|
||||
|
||||
void deadline_timer_custom_allocation_test()
|
||||
{
|
||||
static asio::io_context io_context;
|
||||
struct timer
|
||||
{
|
||||
asio::deadline_timer t;
|
||||
timer() : t(io_context) {}
|
||||
} timers[100];
|
||||
|
||||
int allocation_count = 0;
|
||||
|
||||
for (int i = 0; i < 50; ++i)
|
||||
{
|
||||
timers[i].t.expires_at(boost::posix_time::pos_infin);
|
||||
timers[i].t.async_wait(custom_allocation_timer_handler(&allocation_count));
|
||||
}
|
||||
|
||||
for (int i = 50; i < 100; ++i)
|
||||
{
|
||||
timers[i].t.expires_at(boost::posix_time::neg_infin);
|
||||
timers[i].t.async_wait(custom_allocation_timer_handler(&allocation_count));
|
||||
}
|
||||
|
||||
for (int i = 0; i < 50; ++i)
|
||||
timers[i].t.cancel();
|
||||
|
||||
io_context.run();
|
||||
|
||||
ASIO_CHECK(allocation_count == 0);
|
||||
}
|
||||
|
||||
void io_context_run(asio::io_context* ioc)
|
||||
{
|
||||
ioc->run();
|
||||
}
|
||||
|
||||
void deadline_timer_thread_test()
|
||||
{
|
||||
asio::io_context ioc;
|
||||
asio::executor_work_guard<asio::io_context::executor_type> work
|
||||
= asio::make_work_guard(ioc);
|
||||
asio::deadline_timer t1(ioc);
|
||||
asio::deadline_timer t2(ioc);
|
||||
int count = 0;
|
||||
|
||||
asio::thread th(boost::bind(io_context_run, &ioc));
|
||||
|
||||
t2.expires_from_now(boost::posix_time::seconds(2));
|
||||
t2.wait();
|
||||
|
||||
t1.expires_from_now(boost::posix_time::seconds(2));
|
||||
t1.async_wait(boost::bind(increment, &count));
|
||||
|
||||
t2.expires_from_now(boost::posix_time::seconds(4));
|
||||
t2.wait();
|
||||
|
||||
ioc.stop();
|
||||
th.join();
|
||||
|
||||
ASIO_CHECK(count == 1);
|
||||
}
|
||||
|
||||
void deadline_timer_async_result_test()
|
||||
{
|
||||
asio::io_context ioc;
|
||||
asio::deadline_timer t1(ioc);
|
||||
|
||||
t1.expires_from_now(boost::posix_time::seconds(1));
|
||||
int i = t1.async_wait(archetypes::lazy_handler());
|
||||
ASIO_CHECK(i == 42);
|
||||
|
||||
ioc.run();
|
||||
}
|
||||
|
||||
#if defined(ASIO_HAS_MOVE)
|
||||
asio::deadline_timer make_timer(asio::io_context& ioc, int* count)
|
||||
{
|
||||
asio::deadline_timer t(ioc);
|
||||
t.expires_from_now(boost::posix_time::seconds(1));
|
||||
t.async_wait(boost::bind(increment, count));
|
||||
return t;
|
||||
}
|
||||
#endif // defined(ASIO_HAS_MOVE)
|
||||
|
||||
void deadline_timer_move_test()
|
||||
{
|
||||
#if defined(ASIO_HAS_MOVE)
|
||||
asio::io_context io_context1;
|
||||
asio::io_context io_context2;
|
||||
int count = 0;
|
||||
|
||||
asio::deadline_timer t1 = make_timer(io_context1, &count);
|
||||
asio::deadline_timer t2 = make_timer(io_context2, &count);
|
||||
asio::deadline_timer t3 = std::move(t1);
|
||||
|
||||
t2 = std::move(t1);
|
||||
|
||||
io_context2.run();
|
||||
|
||||
ASIO_CHECK(count == 1);
|
||||
|
||||
io_context1.run();
|
||||
|
||||
ASIO_CHECK(count == 2);
|
||||
#endif // defined(ASIO_HAS_MOVE)
|
||||
}
|
||||
|
||||
ASIO_TEST_SUITE
|
||||
(
|
||||
"deadline_timer",
|
||||
ASIO_TEST_CASE(deadline_timer_test)
|
||||
ASIO_TEST_CASE(deadline_timer_cancel_test)
|
||||
ASIO_TEST_CASE(deadline_timer_custom_allocation_test)
|
||||
ASIO_TEST_CASE(deadline_timer_thread_test)
|
||||
ASIO_TEST_CASE(deadline_timer_async_result_test)
|
||||
ASIO_TEST_CASE(deadline_timer_move_test)
|
||||
)
|
||||
#else // defined(ASIO_HAS_BOOST_DATE_TIME)
|
||||
ASIO_TEST_SUITE
|
||||
(
|
||||
"deadline_timer",
|
||||
ASIO_TEST_CASE(null_test)
|
||||
)
|
||||
#endif // defined(ASIO_HAS_BOOST_DATE_TIME)
|
||||
@@ -0,0 +1,25 @@
|
||||
//
|
||||
// defer.cpp
|
||||
// ~~~~~~~~~
|
||||
//
|
||||
// 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)
|
||||
//
|
||||
|
||||
// Disable autolinking for unit tests.
|
||||
#if !defined(BOOST_ALL_NO_LIB)
|
||||
#define BOOST_ALL_NO_LIB 1
|
||||
#endif // !defined(BOOST_ALL_NO_LIB)
|
||||
|
||||
// Test that header file is self-contained.
|
||||
#include "asio/defer.hpp"
|
||||
|
||||
#include "unit_test.hpp"
|
||||
|
||||
ASIO_TEST_SUITE
|
||||
(
|
||||
"defer",
|
||||
ASIO_TEST_CASE(null_test)
|
||||
)
|
||||
@@ -0,0 +1,25 @@
|
||||
//
|
||||
// detached.cpp
|
||||
// ~~~~~~~~~~~~
|
||||
//
|
||||
// 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)
|
||||
//
|
||||
|
||||
// Disable autolinking for unit tests.
|
||||
#if !defined(BOOST_ALL_NO_LIB)
|
||||
#define BOOST_ALL_NO_LIB 1
|
||||
#endif // !defined(BOOST_ALL_NO_LIB)
|
||||
|
||||
// Test that header file is self-contained.
|
||||
#include "asio/detached.hpp"
|
||||
|
||||
#include "unit_test.hpp"
|
||||
|
||||
ASIO_TEST_SUITE
|
||||
(
|
||||
"detached",
|
||||
ASIO_TEST_CASE(null_test)
|
||||
)
|
||||
@@ -0,0 +1,25 @@
|
||||
//
|
||||
// dispatch.cpp
|
||||
// ~~~~~~~~~~~~
|
||||
//
|
||||
// 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)
|
||||
//
|
||||
|
||||
// Disable autolinking for unit tests.
|
||||
#if !defined(BOOST_ALL_NO_LIB)
|
||||
#define BOOST_ALL_NO_LIB 1
|
||||
#endif // !defined(BOOST_ALL_NO_LIB)
|
||||
|
||||
// Test that header file is self-contained.
|
||||
#include "asio/dispatch.hpp"
|
||||
|
||||
#include "unit_test.hpp"
|
||||
|
||||
ASIO_TEST_SUITE
|
||||
(
|
||||
"dispatch",
|
||||
ASIO_TEST_CASE(null_test)
|
||||
)
|
||||
@@ -0,0 +1,89 @@
|
||||
//
|
||||
// error.cpp
|
||||
// ~~~~~~~~~
|
||||
//
|
||||
// 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)
|
||||
//
|
||||
|
||||
// Disable autolinking for unit tests.
|
||||
#if !defined(BOOST_ALL_NO_LIB)
|
||||
#define BOOST_ALL_NO_LIB 1
|
||||
#endif // !defined(BOOST_ALL_NO_LIB)
|
||||
|
||||
// Test that header file is self-contained.
|
||||
#include "asio/error.hpp"
|
||||
|
||||
#include <sstream>
|
||||
#include "unit_test.hpp"
|
||||
|
||||
void test_error_code(const asio::error_code& code)
|
||||
{
|
||||
asio::error_code error(code);
|
||||
ASIO_CHECK(code == error);
|
||||
|
||||
ASIO_CHECK(!code || error);
|
||||
ASIO_CHECK(!code || !!error);
|
||||
|
||||
asio::error_code error2(error);
|
||||
ASIO_CHECK(error == error2);
|
||||
ASIO_CHECK(!(error != error2));
|
||||
|
||||
asio::error_code error3;
|
||||
error3 = error;
|
||||
ASIO_CHECK(error == error3);
|
||||
ASIO_CHECK(!(error != error3));
|
||||
|
||||
std::ostringstream os;
|
||||
os << error;
|
||||
ASIO_CHECK(!os.str().empty());
|
||||
}
|
||||
|
||||
void error_test()
|
||||
{
|
||||
test_error_code(asio::error::access_denied);
|
||||
test_error_code(asio::error::address_family_not_supported);
|
||||
test_error_code(asio::error::address_in_use);
|
||||
test_error_code(asio::error::already_connected);
|
||||
test_error_code(asio::error::already_started);
|
||||
test_error_code(asio::error::connection_aborted);
|
||||
test_error_code(asio::error::connection_refused);
|
||||
test_error_code(asio::error::connection_reset);
|
||||
test_error_code(asio::error::bad_descriptor);
|
||||
test_error_code(asio::error::eof);
|
||||
test_error_code(asio::error::fault);
|
||||
test_error_code(asio::error::host_not_found);
|
||||
test_error_code(asio::error::host_not_found_try_again);
|
||||
test_error_code(asio::error::host_unreachable);
|
||||
test_error_code(asio::error::in_progress);
|
||||
test_error_code(asio::error::interrupted);
|
||||
test_error_code(asio::error::invalid_argument);
|
||||
test_error_code(asio::error::message_size);
|
||||
test_error_code(asio::error::network_down);
|
||||
test_error_code(asio::error::network_reset);
|
||||
test_error_code(asio::error::network_unreachable);
|
||||
test_error_code(asio::error::no_descriptors);
|
||||
test_error_code(asio::error::no_buffer_space);
|
||||
test_error_code(asio::error::no_data);
|
||||
test_error_code(asio::error::no_memory);
|
||||
test_error_code(asio::error::no_permission);
|
||||
test_error_code(asio::error::no_protocol_option);
|
||||
test_error_code(asio::error::no_recovery);
|
||||
test_error_code(asio::error::not_connected);
|
||||
test_error_code(asio::error::not_socket);
|
||||
test_error_code(asio::error::operation_aborted);
|
||||
test_error_code(asio::error::operation_not_supported);
|
||||
test_error_code(asio::error::service_not_found);
|
||||
test_error_code(asio::error::shut_down);
|
||||
test_error_code(asio::error::timed_out);
|
||||
test_error_code(asio::error::try_again);
|
||||
test_error_code(asio::error::would_block);
|
||||
}
|
||||
|
||||
ASIO_TEST_SUITE
|
||||
(
|
||||
"error",
|
||||
ASIO_TEST_CASE(error_test)
|
||||
)
|
||||
@@ -0,0 +1,25 @@
|
||||
//
|
||||
// execution_context.cpp
|
||||
// ~~~~~~~~~~~~~~~~~~~~~
|
||||
//
|
||||
// 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)
|
||||
//
|
||||
|
||||
// Disable autolinking for unit tests.
|
||||
#if !defined(BOOST_ALL_NO_LIB)
|
||||
#define BOOST_ALL_NO_LIB 1
|
||||
#endif // !defined(BOOST_ALL_NO_LIB)
|
||||
|
||||
// Test that header file is self-contained.
|
||||
#include "asio/execution_context.hpp"
|
||||
|
||||
#include "unit_test.hpp"
|
||||
|
||||
ASIO_TEST_SUITE
|
||||
(
|
||||
"execution_context",
|
||||
ASIO_TEST_CASE(null_test)
|
||||
)
|
||||
@@ -0,0 +1,25 @@
|
||||
//
|
||||
// executor.cpp
|
||||
// ~~~~~~~~~~~~
|
||||
//
|
||||
// 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)
|
||||
//
|
||||
|
||||
// Disable autolinking for unit tests.
|
||||
#if !defined(BOOST_ALL_NO_LIB)
|
||||
#define BOOST_ALL_NO_LIB 1
|
||||
#endif // !defined(BOOST_ALL_NO_LIB)
|
||||
|
||||
// Test that header file is self-contained.
|
||||
#include "asio/executor.hpp"
|
||||
|
||||
#include "unit_test.hpp"
|
||||
|
||||
ASIO_TEST_SUITE
|
||||
(
|
||||
"executor",
|
||||
ASIO_TEST_CASE(null_test)
|
||||
)
|
||||
@@ -0,0 +1,25 @@
|
||||
//
|
||||
// executor_work_guard.cpp
|
||||
// ~~~~~~~~~~~~~~~~~~~~~~~
|
||||
//
|
||||
// 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)
|
||||
//
|
||||
|
||||
// Disable autolinking for unit tests.
|
||||
#if !defined(BOOST_ALL_NO_LIB)
|
||||
#define BOOST_ALL_NO_LIB 1
|
||||
#endif // !defined(BOOST_ALL_NO_LIB)
|
||||
|
||||
// Test that header file is self-contained.
|
||||
#include "asio/executor_work_guard.hpp"
|
||||
|
||||
#include "unit_test.hpp"
|
||||
|
||||
ASIO_TEST_SUITE
|
||||
(
|
||||
"executor_work_guard",
|
||||
ASIO_TEST_CASE(null_test)
|
||||
)
|
||||
@@ -0,0 +1,14 @@
|
||||
.deps
|
||||
.dirstamp
|
||||
*.o
|
||||
*.obj
|
||||
*.exe
|
||||
*.ilk
|
||||
*.manifest
|
||||
*.pdb
|
||||
*.tds
|
||||
basic_endpoint
|
||||
datagram_protocol
|
||||
raw_protocol
|
||||
seq_packet_protocol
|
||||
stream_protocol
|
||||
@@ -0,0 +1,25 @@
|
||||
//
|
||||
// generic/basic_endpoint.cpp
|
||||
// ~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
//
|
||||
// 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)
|
||||
//
|
||||
|
||||
// Disable autolinking for unit tests.
|
||||
#if !defined(BOOST_ALL_NO_LIB)
|
||||
#define BOOST_ALL_NO_LIB 1
|
||||
#endif // !defined(BOOST_ALL_NO_LIB)
|
||||
|
||||
// Test that header file is self-contained.
|
||||
#include "asio/generic/basic_endpoint.hpp"
|
||||
|
||||
#include "../unit_test.hpp"
|
||||
|
||||
ASIO_TEST_SUITE
|
||||
(
|
||||
"generic/basic_endpoint",
|
||||
ASIO_TEST_CASE(null_test)
|
||||
)
|
||||
@@ -0,0 +1,263 @@
|
||||
//
|
||||
// generic/datagram_protocol.cpp
|
||||
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
//
|
||||
// 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)
|
||||
//
|
||||
|
||||
// Disable autolinking for unit tests.
|
||||
#if !defined(BOOST_ALL_NO_LIB)
|
||||
#define BOOST_ALL_NO_LIB 1
|
||||
#endif // !defined(BOOST_ALL_NO_LIB)
|
||||
|
||||
// Test that header file is self-contained.
|
||||
#include "asio/generic/datagram_protocol.hpp"
|
||||
|
||||
#include <cstring>
|
||||
#include "asio/io_context.hpp"
|
||||
#include "asio/ip/udp.hpp"
|
||||
#include "../unit_test.hpp"
|
||||
|
||||
#if defined(__cplusplus_cli) || defined(__cplusplus_winrt)
|
||||
# define generic cpp_generic
|
||||
#endif
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
// generic_datagram_protocol_socket_compile test
|
||||
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
// The following test checks that all public member functions on the class
|
||||
// generic::datagram_socket::socket compile and link correctly. Runtime
|
||||
// failures are ignored.
|
||||
|
||||
namespace generic_datagram_protocol_socket_compile {
|
||||
|
||||
void connect_handler(const asio::error_code&)
|
||||
{
|
||||
}
|
||||
|
||||
void send_handler(const asio::error_code&, std::size_t)
|
||||
{
|
||||
}
|
||||
|
||||
void receive_handler(const asio::error_code&, std::size_t)
|
||||
{
|
||||
}
|
||||
|
||||
void test()
|
||||
{
|
||||
using namespace asio;
|
||||
namespace generic = asio::generic;
|
||||
typedef generic::datagram_protocol dp;
|
||||
|
||||
const int af_inet = ASIO_OS_DEF(AF_INET);
|
||||
const int ipproto_udp = ASIO_OS_DEF(IPPROTO_UDP);
|
||||
const int sock_dgram = ASIO_OS_DEF(SOCK_DGRAM);
|
||||
|
||||
try
|
||||
{
|
||||
io_context ioc;
|
||||
char mutable_char_buffer[128] = "";
|
||||
const char const_char_buffer[128] = "";
|
||||
socket_base::message_flags in_flags = 0;
|
||||
socket_base::send_buffer_size socket_option;
|
||||
socket_base::bytes_readable io_control_command;
|
||||
asio::error_code ec;
|
||||
|
||||
// basic_datagram_socket constructors.
|
||||
|
||||
dp::socket socket1(ioc);
|
||||
dp::socket socket2(ioc, dp(af_inet, ipproto_udp));
|
||||
dp::socket socket3(ioc, dp::endpoint());
|
||||
#if !defined(ASIO_WINDOWS_RUNTIME)
|
||||
dp::socket::native_handle_type native_socket1
|
||||
= ::socket(af_inet, sock_dgram, 0);
|
||||
dp::socket socket4(ioc, dp(af_inet, ipproto_udp), native_socket1);
|
||||
#endif // !defined(ASIO_WINDOWS_RUNTIME)
|
||||
|
||||
#if defined(ASIO_HAS_MOVE)
|
||||
dp::socket socket5(std::move(socket4));
|
||||
asio::ip::udp::socket udp_socket(ioc);
|
||||
dp::socket socket6(std::move(udp_socket));
|
||||
#endif // defined(ASIO_HAS_MOVE)
|
||||
|
||||
// basic_datagram_socket operators.
|
||||
|
||||
#if defined(ASIO_HAS_MOVE)
|
||||
socket1 = dp::socket(ioc);
|
||||
socket1 = std::move(socket2);
|
||||
socket1 = asio::ip::udp::socket(ioc);
|
||||
#endif // defined(ASIO_HAS_MOVE)
|
||||
|
||||
// basic_io_object functions.
|
||||
|
||||
dp::socket::executor_type ex = socket1.get_executor();
|
||||
(void)ex;
|
||||
|
||||
// basic_socket functions.
|
||||
|
||||
dp::socket::lowest_layer_type& lowest_layer = socket1.lowest_layer();
|
||||
(void)lowest_layer;
|
||||
|
||||
socket1.open(dp(af_inet, ipproto_udp));
|
||||
socket1.open(dp(af_inet, ipproto_udp), ec);
|
||||
|
||||
#if !defined(ASIO_WINDOWS_RUNTIME)
|
||||
dp::socket::native_handle_type native_socket2
|
||||
= ::socket(af_inet, sock_dgram, 0);
|
||||
socket1.assign(dp(af_inet, ipproto_udp), native_socket2);
|
||||
dp::socket::native_handle_type native_socket3
|
||||
= ::socket(af_inet, sock_dgram, 0);
|
||||
socket1.assign(dp(af_inet, ipproto_udp), native_socket3, ec);
|
||||
#endif // !defined(ASIO_WINDOWS_RUNTIME)
|
||||
|
||||
bool is_open = socket1.is_open();
|
||||
(void)is_open;
|
||||
|
||||
socket1.close();
|
||||
socket1.close(ec);
|
||||
|
||||
dp::socket::native_handle_type native_socket4 = socket1.native_handle();
|
||||
(void)native_socket4;
|
||||
|
||||
socket1.cancel();
|
||||
socket1.cancel(ec);
|
||||
|
||||
bool at_mark1 = socket1.at_mark();
|
||||
(void)at_mark1;
|
||||
bool at_mark2 = socket1.at_mark(ec);
|
||||
(void)at_mark2;
|
||||
|
||||
std::size_t available1 = socket1.available();
|
||||
(void)available1;
|
||||
std::size_t available2 = socket1.available(ec);
|
||||
(void)available2;
|
||||
|
||||
socket1.bind(dp::endpoint());
|
||||
socket1.bind(dp::endpoint(), ec);
|
||||
|
||||
socket1.connect(dp::endpoint());
|
||||
socket1.connect(dp::endpoint(), ec);
|
||||
|
||||
socket1.async_connect(dp::endpoint(), connect_handler);
|
||||
|
||||
socket1.set_option(socket_option);
|
||||
socket1.set_option(socket_option, ec);
|
||||
|
||||
socket1.get_option(socket_option);
|
||||
socket1.get_option(socket_option, ec);
|
||||
|
||||
socket1.io_control(io_control_command);
|
||||
socket1.io_control(io_control_command, ec);
|
||||
|
||||
dp::endpoint endpoint1 = socket1.local_endpoint();
|
||||
(void)endpoint1;
|
||||
dp::endpoint endpoint2 = socket1.local_endpoint(ec);
|
||||
(void)endpoint2;
|
||||
|
||||
dp::endpoint endpoint3 = socket1.remote_endpoint();
|
||||
(void)endpoint3;
|
||||
dp::endpoint endpoint4 = socket1.remote_endpoint(ec);
|
||||
(void)endpoint4;
|
||||
|
||||
socket1.shutdown(socket_base::shutdown_both);
|
||||
socket1.shutdown(socket_base::shutdown_both, ec);
|
||||
|
||||
// basic_datagram_socket functions.
|
||||
|
||||
socket1.send(buffer(mutable_char_buffer));
|
||||
socket1.send(buffer(const_char_buffer));
|
||||
socket1.send(null_buffers());
|
||||
socket1.send(buffer(mutable_char_buffer), in_flags);
|
||||
socket1.send(buffer(const_char_buffer), in_flags);
|
||||
socket1.send(null_buffers(), in_flags);
|
||||
socket1.send(buffer(mutable_char_buffer), in_flags, ec);
|
||||
socket1.send(buffer(const_char_buffer), in_flags, ec);
|
||||
socket1.send(null_buffers(), in_flags, ec);
|
||||
|
||||
socket1.async_send(buffer(mutable_char_buffer), send_handler);
|
||||
socket1.async_send(buffer(const_char_buffer), send_handler);
|
||||
socket1.async_send(null_buffers(), send_handler);
|
||||
socket1.async_send(buffer(mutable_char_buffer), in_flags, send_handler);
|
||||
socket1.async_send(buffer(const_char_buffer), in_flags, send_handler);
|
||||
socket1.async_send(null_buffers(), in_flags, send_handler);
|
||||
|
||||
socket1.send_to(buffer(mutable_char_buffer),
|
||||
dp::endpoint());
|
||||
socket1.send_to(buffer(const_char_buffer),
|
||||
dp::endpoint());
|
||||
socket1.send_to(null_buffers(),
|
||||
dp::endpoint());
|
||||
socket1.send_to(buffer(mutable_char_buffer),
|
||||
dp::endpoint(), in_flags);
|
||||
socket1.send_to(buffer(const_char_buffer),
|
||||
dp::endpoint(), in_flags);
|
||||
socket1.send_to(null_buffers(),
|
||||
dp::endpoint(), in_flags);
|
||||
socket1.send_to(buffer(mutable_char_buffer),
|
||||
dp::endpoint(), in_flags, ec);
|
||||
socket1.send_to(buffer(const_char_buffer),
|
||||
dp::endpoint(), in_flags, ec);
|
||||
socket1.send_to(null_buffers(),
|
||||
dp::endpoint(), in_flags, ec);
|
||||
|
||||
socket1.async_send_to(buffer(mutable_char_buffer),
|
||||
dp::endpoint(), send_handler);
|
||||
socket1.async_send_to(buffer(const_char_buffer),
|
||||
dp::endpoint(), send_handler);
|
||||
socket1.async_send_to(null_buffers(),
|
||||
dp::endpoint(), send_handler);
|
||||
socket1.async_send_to(buffer(mutable_char_buffer),
|
||||
dp::endpoint(), in_flags, send_handler);
|
||||
socket1.async_send_to(buffer(const_char_buffer),
|
||||
dp::endpoint(), in_flags, send_handler);
|
||||
socket1.async_send_to(null_buffers(),
|
||||
dp::endpoint(), in_flags, send_handler);
|
||||
|
||||
socket1.receive(buffer(mutable_char_buffer));
|
||||
socket1.receive(null_buffers());
|
||||
socket1.receive(buffer(mutable_char_buffer), in_flags);
|
||||
socket1.receive(null_buffers(), in_flags);
|
||||
socket1.receive(buffer(mutable_char_buffer), in_flags, ec);
|
||||
socket1.receive(null_buffers(), in_flags, ec);
|
||||
|
||||
socket1.async_receive(buffer(mutable_char_buffer), receive_handler);
|
||||
socket1.async_receive(null_buffers(), receive_handler);
|
||||
socket1.async_receive(buffer(mutable_char_buffer), in_flags,
|
||||
receive_handler);
|
||||
socket1.async_receive(null_buffers(), in_flags, receive_handler);
|
||||
|
||||
dp::endpoint endpoint;
|
||||
socket1.receive_from(buffer(mutable_char_buffer), endpoint);
|
||||
socket1.receive_from(null_buffers(), endpoint);
|
||||
socket1.receive_from(buffer(mutable_char_buffer), endpoint, in_flags);
|
||||
socket1.receive_from(null_buffers(), endpoint, in_flags);
|
||||
socket1.receive_from(buffer(mutable_char_buffer), endpoint, in_flags, ec);
|
||||
socket1.receive_from(null_buffers(), endpoint, in_flags, ec);
|
||||
|
||||
socket1.async_receive_from(buffer(mutable_char_buffer),
|
||||
endpoint, receive_handler);
|
||||
socket1.async_receive_from(null_buffers(),
|
||||
endpoint, receive_handler);
|
||||
socket1.async_receive_from(buffer(mutable_char_buffer),
|
||||
endpoint, in_flags, receive_handler);
|
||||
socket1.async_receive_from(null_buffers(),
|
||||
endpoint, in_flags, receive_handler);
|
||||
}
|
||||
catch (std::exception&)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace generic_datagram_protocol_socket_compile
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
ASIO_TEST_SUITE
|
||||
(
|
||||
"generic/datagram_protocol",
|
||||
ASIO_TEST_CASE(generic_datagram_protocol_socket_compile::test)
|
||||
)
|
||||
@@ -0,0 +1,263 @@
|
||||
//
|
||||
// generic/raw_protocol.cpp
|
||||
// ~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
//
|
||||
// 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)
|
||||
//
|
||||
|
||||
// Disable autolinking for unit tests.
|
||||
#if !defined(BOOST_ALL_NO_LIB)
|
||||
#define BOOST_ALL_NO_LIB 1
|
||||
#endif // !defined(BOOST_ALL_NO_LIB)
|
||||
|
||||
// Test that header file is self-contained.
|
||||
#include "asio/generic/raw_protocol.hpp"
|
||||
|
||||
#include <cstring>
|
||||
#include "asio/io_context.hpp"
|
||||
#include "asio/ip/icmp.hpp"
|
||||
#include "../unit_test.hpp"
|
||||
|
||||
#if defined(__cplusplus_cli) || defined(__cplusplus_winrt)
|
||||
# define generic cpp_generic
|
||||
#endif
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
// generic_raw_protocol_socket_compile test
|
||||
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
// The following test checks that all public member functions on the class
|
||||
// generic::raw_socket::socket compile and link correctly. Runtime failures
|
||||
// are ignored.
|
||||
|
||||
namespace generic_raw_protocol_socket_compile {
|
||||
|
||||
void connect_handler(const asio::error_code&)
|
||||
{
|
||||
}
|
||||
|
||||
void send_handler(const asio::error_code&, std::size_t)
|
||||
{
|
||||
}
|
||||
|
||||
void receive_handler(const asio::error_code&, std::size_t)
|
||||
{
|
||||
}
|
||||
|
||||
void test()
|
||||
{
|
||||
using namespace asio;
|
||||
namespace generic = asio::generic;
|
||||
typedef generic::raw_protocol rp;
|
||||
|
||||
const int af_inet = ASIO_OS_DEF(AF_INET);
|
||||
const int ipproto_icmp = ASIO_OS_DEF(IPPROTO_ICMP);
|
||||
const int sock_raw = ASIO_OS_DEF(SOCK_RAW);
|
||||
|
||||
try
|
||||
{
|
||||
io_context ioc;
|
||||
char mutable_char_buffer[128] = "";
|
||||
const char const_char_buffer[128] = "";
|
||||
socket_base::message_flags in_flags = 0;
|
||||
socket_base::send_buffer_size socket_option;
|
||||
socket_base::bytes_readable io_control_command;
|
||||
asio::error_code ec;
|
||||
|
||||
// basic_raw_socket constructors.
|
||||
|
||||
rp::socket socket1(ioc);
|
||||
rp::socket socket2(ioc, rp(af_inet, ipproto_icmp));
|
||||
rp::socket socket3(ioc, rp::endpoint());
|
||||
#if !defined(ASIO_WINDOWS_RUNTIME)
|
||||
rp::socket::native_handle_type native_socket1
|
||||
= ::socket(af_inet, sock_raw, 0);
|
||||
rp::socket socket4(ioc, rp(af_inet, ipproto_icmp), native_socket1);
|
||||
#endif // !defined(ASIO_WINDOWS_RUNTIME)
|
||||
|
||||
#if defined(ASIO_HAS_MOVE)
|
||||
rp::socket socket5(std::move(socket4));
|
||||
asio::ip::icmp::socket icmp_socket(ioc);
|
||||
rp::socket socket6(std::move(icmp_socket));
|
||||
#endif // defined(ASIO_HAS_MOVE)
|
||||
|
||||
// basic_datagram_socket operators.
|
||||
|
||||
#if defined(ASIO_HAS_MOVE)
|
||||
socket1 = rp::socket(ioc);
|
||||
socket1 = std::move(socket2);
|
||||
socket1 = asio::ip::icmp::socket(ioc);
|
||||
#endif // defined(ASIO_HAS_MOVE)
|
||||
|
||||
// basic_io_object functions.
|
||||
|
||||
rp::socket::executor_type ex = socket1.get_executor();
|
||||
(void)ex;
|
||||
|
||||
// basic_socket functions.
|
||||
|
||||
rp::socket::lowest_layer_type& lowest_layer = socket1.lowest_layer();
|
||||
(void)lowest_layer;
|
||||
|
||||
socket1.open(rp(af_inet, ipproto_icmp));
|
||||
socket1.open(rp(af_inet, ipproto_icmp), ec);
|
||||
|
||||
#if !defined(ASIO_WINDOWS_RUNTIME)
|
||||
rp::socket::native_handle_type native_socket2
|
||||
= ::socket(af_inet, sock_raw, 0);
|
||||
socket1.assign(rp(af_inet, ipproto_icmp), native_socket2);
|
||||
rp::socket::native_handle_type native_socket3
|
||||
= ::socket(af_inet, sock_raw, 0);
|
||||
socket1.assign(rp(af_inet, ipproto_icmp), native_socket3, ec);
|
||||
#endif // !defined(ASIO_WINDOWS_RUNTIME)
|
||||
|
||||
bool is_open = socket1.is_open();
|
||||
(void)is_open;
|
||||
|
||||
socket1.close();
|
||||
socket1.close(ec);
|
||||
|
||||
rp::socket::native_handle_type native_socket4 = socket1.native_handle();
|
||||
(void)native_socket4;
|
||||
|
||||
socket1.cancel();
|
||||
socket1.cancel(ec);
|
||||
|
||||
bool at_mark1 = socket1.at_mark();
|
||||
(void)at_mark1;
|
||||
bool at_mark2 = socket1.at_mark(ec);
|
||||
(void)at_mark2;
|
||||
|
||||
std::size_t available1 = socket1.available();
|
||||
(void)available1;
|
||||
std::size_t available2 = socket1.available(ec);
|
||||
(void)available2;
|
||||
|
||||
socket1.bind(rp::endpoint());
|
||||
socket1.bind(rp::endpoint(), ec);
|
||||
|
||||
socket1.connect(rp::endpoint());
|
||||
socket1.connect(rp::endpoint(), ec);
|
||||
|
||||
socket1.async_connect(rp::endpoint(), connect_handler);
|
||||
|
||||
socket1.set_option(socket_option);
|
||||
socket1.set_option(socket_option, ec);
|
||||
|
||||
socket1.get_option(socket_option);
|
||||
socket1.get_option(socket_option, ec);
|
||||
|
||||
socket1.io_control(io_control_command);
|
||||
socket1.io_control(io_control_command, ec);
|
||||
|
||||
rp::endpoint endpoint1 = socket1.local_endpoint();
|
||||
(void)endpoint1;
|
||||
rp::endpoint endpoint2 = socket1.local_endpoint(ec);
|
||||
(void)endpoint2;
|
||||
|
||||
rp::endpoint endpoint3 = socket1.remote_endpoint();
|
||||
(void)endpoint3;
|
||||
rp::endpoint endpoint4 = socket1.remote_endpoint(ec);
|
||||
(void)endpoint4;
|
||||
|
||||
socket1.shutdown(socket_base::shutdown_both);
|
||||
socket1.shutdown(socket_base::shutdown_both, ec);
|
||||
|
||||
// basic_raw_socket functions.
|
||||
|
||||
socket1.send(buffer(mutable_char_buffer));
|
||||
socket1.send(buffer(const_char_buffer));
|
||||
socket1.send(null_buffers());
|
||||
socket1.send(buffer(mutable_char_buffer), in_flags);
|
||||
socket1.send(buffer(const_char_buffer), in_flags);
|
||||
socket1.send(null_buffers(), in_flags);
|
||||
socket1.send(buffer(mutable_char_buffer), in_flags, ec);
|
||||
socket1.send(buffer(const_char_buffer), in_flags, ec);
|
||||
socket1.send(null_buffers(), in_flags, ec);
|
||||
|
||||
socket1.async_send(buffer(mutable_char_buffer), send_handler);
|
||||
socket1.async_send(buffer(const_char_buffer), send_handler);
|
||||
socket1.async_send(null_buffers(), send_handler);
|
||||
socket1.async_send(buffer(mutable_char_buffer), in_flags, send_handler);
|
||||
socket1.async_send(buffer(const_char_buffer), in_flags, send_handler);
|
||||
socket1.async_send(null_buffers(), in_flags, send_handler);
|
||||
|
||||
socket1.send_to(buffer(mutable_char_buffer),
|
||||
rp::endpoint());
|
||||
socket1.send_to(buffer(const_char_buffer),
|
||||
rp::endpoint());
|
||||
socket1.send_to(null_buffers(),
|
||||
rp::endpoint());
|
||||
socket1.send_to(buffer(mutable_char_buffer),
|
||||
rp::endpoint(), in_flags);
|
||||
socket1.send_to(buffer(const_char_buffer),
|
||||
rp::endpoint(), in_flags);
|
||||
socket1.send_to(null_buffers(),
|
||||
rp::endpoint(), in_flags);
|
||||
socket1.send_to(buffer(mutable_char_buffer),
|
||||
rp::endpoint(), in_flags, ec);
|
||||
socket1.send_to(buffer(const_char_buffer),
|
||||
rp::endpoint(), in_flags, ec);
|
||||
socket1.send_to(null_buffers(),
|
||||
rp::endpoint(), in_flags, ec);
|
||||
|
||||
socket1.async_send_to(buffer(mutable_char_buffer),
|
||||
rp::endpoint(), send_handler);
|
||||
socket1.async_send_to(buffer(const_char_buffer),
|
||||
rp::endpoint(), send_handler);
|
||||
socket1.async_send_to(null_buffers(),
|
||||
rp::endpoint(), send_handler);
|
||||
socket1.async_send_to(buffer(mutable_char_buffer),
|
||||
rp::endpoint(), in_flags, send_handler);
|
||||
socket1.async_send_to(buffer(const_char_buffer),
|
||||
rp::endpoint(), in_flags, send_handler);
|
||||
socket1.async_send_to(null_buffers(),
|
||||
rp::endpoint(), in_flags, send_handler);
|
||||
|
||||
socket1.receive(buffer(mutable_char_buffer));
|
||||
socket1.receive(null_buffers());
|
||||
socket1.receive(buffer(mutable_char_buffer), in_flags);
|
||||
socket1.receive(null_buffers(), in_flags);
|
||||
socket1.receive(buffer(mutable_char_buffer), in_flags, ec);
|
||||
socket1.receive(null_buffers(), in_flags, ec);
|
||||
|
||||
socket1.async_receive(buffer(mutable_char_buffer), receive_handler);
|
||||
socket1.async_receive(null_buffers(), receive_handler);
|
||||
socket1.async_receive(buffer(mutable_char_buffer), in_flags,
|
||||
receive_handler);
|
||||
socket1.async_receive(null_buffers(), in_flags, receive_handler);
|
||||
|
||||
rp::endpoint endpoint;
|
||||
socket1.receive_from(buffer(mutable_char_buffer), endpoint);
|
||||
socket1.receive_from(null_buffers(), endpoint);
|
||||
socket1.receive_from(buffer(mutable_char_buffer), endpoint, in_flags);
|
||||
socket1.receive_from(null_buffers(), endpoint, in_flags);
|
||||
socket1.receive_from(buffer(mutable_char_buffer), endpoint, in_flags, ec);
|
||||
socket1.receive_from(null_buffers(), endpoint, in_flags, ec);
|
||||
|
||||
socket1.async_receive_from(buffer(mutable_char_buffer),
|
||||
endpoint, receive_handler);
|
||||
socket1.async_receive_from(null_buffers(),
|
||||
endpoint, receive_handler);
|
||||
socket1.async_receive_from(buffer(mutable_char_buffer),
|
||||
endpoint, in_flags, receive_handler);
|
||||
socket1.async_receive_from(null_buffers(),
|
||||
endpoint, in_flags, receive_handler);
|
||||
}
|
||||
catch (std::exception&)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace generic_raw_protocol_socket_compile
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
ASIO_TEST_SUITE
|
||||
(
|
||||
"generic/raw_protocol",
|
||||
ASIO_TEST_CASE(generic_raw_protocol_socket_compile::test)
|
||||
)
|
||||
@@ -0,0 +1,205 @@
|
||||
//
|
||||
// generic/seq_packet_protocol.cpp
|
||||
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
//
|
||||
// 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)
|
||||
//
|
||||
|
||||
// Disable autolinking for unit tests.
|
||||
#if !defined(BOOST_ALL_NO_LIB)
|
||||
#define BOOST_ALL_NO_LIB 1
|
||||
#endif // !defined(BOOST_ALL_NO_LIB)
|
||||
|
||||
// Test that header file is self-contained.
|
||||
#include "asio/generic/seq_packet_protocol.hpp"
|
||||
|
||||
#include <cstring>
|
||||
#include "asio/io_context.hpp"
|
||||
#include "../unit_test.hpp"
|
||||
|
||||
#if defined(__cplusplus_cli) || defined(__cplusplus_winrt)
|
||||
# define generic cpp_generic
|
||||
#endif
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
// generic_seq_packet_protocol_socket_compile test
|
||||
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
// The following test checks that all public member functions on the class
|
||||
// generic::seq_packet_socket::socket compile and link correctly. Runtime
|
||||
// failures are ignored.
|
||||
|
||||
namespace generic_seq_packet_protocol_socket_compile {
|
||||
|
||||
void connect_handler(const asio::error_code&)
|
||||
{
|
||||
}
|
||||
|
||||
void send_handler(const asio::error_code&, std::size_t)
|
||||
{
|
||||
}
|
||||
|
||||
void receive_handler(const asio::error_code&, std::size_t)
|
||||
{
|
||||
}
|
||||
|
||||
void test()
|
||||
{
|
||||
using namespace asio;
|
||||
namespace generic = asio::generic;
|
||||
typedef generic::seq_packet_protocol spp;
|
||||
|
||||
const int af_inet = ASIO_OS_DEF(AF_INET);
|
||||
const int sock_seqpacket = ASIO_OS_DEF(SOCK_SEQPACKET);
|
||||
|
||||
try
|
||||
{
|
||||
io_context ioc;
|
||||
char mutable_char_buffer[128] = "";
|
||||
const char const_char_buffer[128] = "";
|
||||
const socket_base::message_flags in_flags = 0;
|
||||
socket_base::message_flags out_flags = 0;
|
||||
socket_base::send_buffer_size socket_option;
|
||||
socket_base::bytes_readable io_control_command;
|
||||
asio::error_code ec;
|
||||
|
||||
// basic_seq_packet_socket constructors.
|
||||
|
||||
spp::socket socket1(ioc);
|
||||
spp::socket socket2(ioc, spp(af_inet, 0));
|
||||
spp::socket socket3(ioc, spp::endpoint());
|
||||
#if !defined(ASIO_WINDOWS_RUNTIME)
|
||||
spp::socket::native_handle_type native_socket1
|
||||
= ::socket(af_inet, sock_seqpacket, 0);
|
||||
spp::socket socket4(ioc, spp(af_inet, 0), native_socket1);
|
||||
#endif // !defined(ASIO_WINDOWS_RUNTIME)
|
||||
|
||||
#if defined(ASIO_HAS_MOVE)
|
||||
spp::socket socket5(std::move(socket4));
|
||||
#endif // defined(ASIO_HAS_MOVE)
|
||||
|
||||
// basic_seq_packet_socket operators.
|
||||
|
||||
#if defined(ASIO_HAS_MOVE)
|
||||
socket1 = spp::socket(ioc);
|
||||
socket1 = std::move(socket2);
|
||||
#endif // defined(ASIO_HAS_MOVE)
|
||||
|
||||
// basic_io_object functions.
|
||||
|
||||
spp::socket::executor_type ex = socket1.get_executor();
|
||||
(void)ex;
|
||||
|
||||
// basic_socket functions.
|
||||
|
||||
spp::socket::lowest_layer_type& lowest_layer = socket1.lowest_layer();
|
||||
(void)lowest_layer;
|
||||
|
||||
socket1.open(spp(af_inet, 0));
|
||||
socket1.open(spp(af_inet, 0), ec);
|
||||
|
||||
#if !defined(ASIO_WINDOWS_RUNTIME)
|
||||
spp::socket::native_handle_type native_socket2
|
||||
= ::socket(af_inet, sock_seqpacket, 0);
|
||||
socket1.assign(spp(af_inet, 0), native_socket2);
|
||||
spp::socket::native_handle_type native_socket3
|
||||
= ::socket(af_inet, sock_seqpacket, 0);
|
||||
socket1.assign(spp(af_inet, 0), native_socket3, ec);
|
||||
#endif // !defined(ASIO_WINDOWS_RUNTIME)
|
||||
|
||||
bool is_open = socket1.is_open();
|
||||
(void)is_open;
|
||||
|
||||
socket1.close();
|
||||
socket1.close(ec);
|
||||
|
||||
spp::socket::native_handle_type native_socket4 = socket1.native_handle();
|
||||
(void)native_socket4;
|
||||
|
||||
socket1.cancel();
|
||||
socket1.cancel(ec);
|
||||
|
||||
bool at_mark1 = socket1.at_mark();
|
||||
(void)at_mark1;
|
||||
bool at_mark2 = socket1.at_mark(ec);
|
||||
(void)at_mark2;
|
||||
|
||||
std::size_t available1 = socket1.available();
|
||||
(void)available1;
|
||||
std::size_t available2 = socket1.available(ec);
|
||||
(void)available2;
|
||||
|
||||
socket1.bind(spp::endpoint());
|
||||
socket1.bind(spp::endpoint(), ec);
|
||||
|
||||
socket1.connect(spp::endpoint());
|
||||
socket1.connect(spp::endpoint(), ec);
|
||||
|
||||
socket1.async_connect(spp::endpoint(), connect_handler);
|
||||
|
||||
socket1.set_option(socket_option);
|
||||
socket1.set_option(socket_option, ec);
|
||||
|
||||
socket1.get_option(socket_option);
|
||||
socket1.get_option(socket_option, ec);
|
||||
|
||||
socket1.io_control(io_control_command);
|
||||
socket1.io_control(io_control_command, ec);
|
||||
|
||||
spp::endpoint endpoint1 = socket1.local_endpoint();
|
||||
(void)endpoint1;
|
||||
spp::endpoint endpoint2 = socket1.local_endpoint(ec);
|
||||
(void)endpoint2;
|
||||
|
||||
spp::endpoint endpoint3 = socket1.remote_endpoint();
|
||||
(void)endpoint3;
|
||||
spp::endpoint endpoint4 = socket1.remote_endpoint(ec);
|
||||
(void)endpoint4;
|
||||
|
||||
socket1.shutdown(socket_base::shutdown_both);
|
||||
socket1.shutdown(socket_base::shutdown_both, ec);
|
||||
|
||||
// basic_seq_packet_socket functions.
|
||||
|
||||
socket1.send(buffer(mutable_char_buffer), in_flags);
|
||||
socket1.send(buffer(const_char_buffer), in_flags);
|
||||
socket1.send(null_buffers(), in_flags);
|
||||
socket1.send(buffer(mutable_char_buffer), in_flags, ec);
|
||||
socket1.send(buffer(const_char_buffer), in_flags, ec);
|
||||
socket1.send(null_buffers(), in_flags, ec);
|
||||
|
||||
socket1.async_send(buffer(mutable_char_buffer), in_flags, send_handler);
|
||||
socket1.async_send(buffer(const_char_buffer), in_flags, send_handler);
|
||||
socket1.async_send(null_buffers(), in_flags, send_handler);
|
||||
|
||||
socket1.receive(buffer(mutable_char_buffer), out_flags);
|
||||
socket1.receive(null_buffers(), out_flags);
|
||||
socket1.receive(buffer(mutable_char_buffer), in_flags, out_flags);
|
||||
socket1.receive(null_buffers(), in_flags, out_flags);
|
||||
socket1.receive(buffer(mutable_char_buffer), in_flags, out_flags, ec);
|
||||
socket1.receive(null_buffers(), in_flags, out_flags, ec);
|
||||
|
||||
socket1.async_receive(buffer(mutable_char_buffer), out_flags,
|
||||
receive_handler);
|
||||
socket1.async_receive(null_buffers(), out_flags, receive_handler);
|
||||
socket1.async_receive(buffer(mutable_char_buffer), in_flags,
|
||||
out_flags, receive_handler);
|
||||
socket1.async_receive(null_buffers(), in_flags, out_flags, receive_handler);
|
||||
}
|
||||
catch (std::exception&)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace generic_seq_packet_protocol_socket_compile
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
ASIO_TEST_SUITE
|
||||
(
|
||||
"generic/seq_packet_protocol",
|
||||
ASIO_TEST_CASE(generic_seq_packet_protocol_socket_compile::test)
|
||||
)
|
||||
@@ -0,0 +1,248 @@
|
||||
//
|
||||
// generic/stream_protocol.cpp
|
||||
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
//
|
||||
// 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)
|
||||
//
|
||||
|
||||
// Disable autolinking for unit tests.
|
||||
#if !defined(BOOST_ALL_NO_LIB)
|
||||
#define BOOST_ALL_NO_LIB 1
|
||||
#endif // !defined(BOOST_ALL_NO_LIB)
|
||||
|
||||
// Test that header file is self-contained.
|
||||
#include "asio/generic/stream_protocol.hpp"
|
||||
|
||||
#include <cstring>
|
||||
#include "asio/io_context.hpp"
|
||||
#include "asio/ip/tcp.hpp"
|
||||
#include "../unit_test.hpp"
|
||||
|
||||
#if defined(__cplusplus_cli) || defined(__cplusplus_winrt)
|
||||
# define generic cpp_generic
|
||||
#endif
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
// generic_stream_protocol_socket_compile test
|
||||
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
// The following test checks that all public member functions on the class
|
||||
// generic::stream_protocol::socket compile and link correctly. Runtime
|
||||
// failures are ignored.
|
||||
|
||||
namespace generic_stream_protocol_socket_compile {
|
||||
|
||||
void connect_handler(const asio::error_code&)
|
||||
{
|
||||
}
|
||||
|
||||
void send_handler(const asio::error_code&, std::size_t)
|
||||
{
|
||||
}
|
||||
|
||||
void receive_handler(const asio::error_code&, std::size_t)
|
||||
{
|
||||
}
|
||||
|
||||
void write_some_handler(const asio::error_code&, std::size_t)
|
||||
{
|
||||
}
|
||||
|
||||
void read_some_handler(const asio::error_code&, std::size_t)
|
||||
{
|
||||
}
|
||||
|
||||
void test()
|
||||
{
|
||||
using namespace asio;
|
||||
namespace generic = asio::generic;
|
||||
typedef generic::stream_protocol sp;
|
||||
|
||||
const int af_inet = ASIO_OS_DEF(AF_INET);
|
||||
const int ipproto_tcp = ASIO_OS_DEF(IPPROTO_TCP);
|
||||
const int sock_stream = ASIO_OS_DEF(SOCK_STREAM);
|
||||
|
||||
try
|
||||
{
|
||||
io_context ioc;
|
||||
char mutable_char_buffer[128] = "";
|
||||
const char const_char_buffer[128] = "";
|
||||
socket_base::message_flags in_flags = 0;
|
||||
socket_base::keep_alive socket_option;
|
||||
socket_base::bytes_readable io_control_command;
|
||||
asio::error_code ec;
|
||||
|
||||
// basic_stream_socket constructors.
|
||||
|
||||
sp::socket socket1(ioc);
|
||||
sp::socket socket2(ioc, sp(af_inet, ipproto_tcp));
|
||||
sp::socket socket3(ioc, sp::endpoint());
|
||||
#if defined(ASIO_WINDOWS_RUNTIME)
|
||||
Windows::Networking::Sockets::StreamSocket^ native_socket1 = nullptr;
|
||||
#else // defined(ASIO_WINDOWS_RUNTIME)
|
||||
sp::socket::native_handle_type native_socket1
|
||||
= ::socket(af_inet, sock_stream, 0);
|
||||
#endif // defined(ASIO_WINDOWS_RUNTIME)
|
||||
sp::socket socket4(ioc, sp(af_inet, ipproto_tcp), native_socket1);
|
||||
|
||||
#if defined(ASIO_HAS_MOVE)
|
||||
sp::socket socket5(std::move(socket4));
|
||||
asio::ip::tcp::socket tcp_socket(ioc);
|
||||
sp::socket socket6(std::move(tcp_socket));
|
||||
#endif // defined(ASIO_HAS_MOVE)
|
||||
|
||||
// basic_stream_socket operators.
|
||||
|
||||
#if defined(ASIO_HAS_MOVE)
|
||||
socket1 = sp::socket(ioc);
|
||||
socket1 = std::move(socket2);
|
||||
socket1 = asio::ip::tcp::socket(ioc);
|
||||
#endif // defined(ASIO_HAS_MOVE)
|
||||
|
||||
// basic_io_object functions.
|
||||
|
||||
sp::socket::executor_type ex = socket1.get_executor();
|
||||
(void)ex;
|
||||
|
||||
// basic_socket functions.
|
||||
|
||||
sp::socket::lowest_layer_type& lowest_layer = socket1.lowest_layer();
|
||||
(void)lowest_layer;
|
||||
|
||||
socket1.open(sp(af_inet, ipproto_tcp));
|
||||
socket1.open(sp(af_inet, ipproto_tcp), ec);
|
||||
|
||||
#if defined(ASIO_WINDOWS_RUNTIME)
|
||||
Windows::Networking::Sockets::StreamSocket^ native_socket2 = nullptr;
|
||||
#else // defined(ASIO_WINDOWS_RUNTIME)
|
||||
sp::socket::native_handle_type native_socket2
|
||||
= ::socket(af_inet, sock_stream, 0);
|
||||
#endif // defined(ASIO_WINDOWS_RUNTIME)
|
||||
socket1.assign(sp(af_inet, ipproto_tcp), native_socket2);
|
||||
#if defined(ASIO_WINDOWS_RUNTIME)
|
||||
Windows::Networking::Sockets::StreamSocket^ native_socket3 = nullptr;
|
||||
#else // defined(ASIO_WINDOWS_RUNTIME)
|
||||
sp::socket::native_handle_type native_socket3
|
||||
= ::socket(af_inet, sock_stream, 0);
|
||||
#endif // defined(ASIO_WINDOWS_RUNTIME)
|
||||
socket1.assign(sp(af_inet, ipproto_tcp), native_socket3, ec);
|
||||
|
||||
bool is_open = socket1.is_open();
|
||||
(void)is_open;
|
||||
|
||||
socket1.close();
|
||||
socket1.close(ec);
|
||||
|
||||
sp::socket::native_handle_type native_socket4 = socket1.native_handle();
|
||||
(void)native_socket4;
|
||||
|
||||
socket1.cancel();
|
||||
socket1.cancel(ec);
|
||||
|
||||
bool at_mark1 = socket1.at_mark();
|
||||
(void)at_mark1;
|
||||
bool at_mark2 = socket1.at_mark(ec);
|
||||
(void)at_mark2;
|
||||
|
||||
std::size_t available1 = socket1.available();
|
||||
(void)available1;
|
||||
std::size_t available2 = socket1.available(ec);
|
||||
(void)available2;
|
||||
|
||||
socket1.bind(sp::endpoint());
|
||||
socket1.bind(sp::endpoint(), ec);
|
||||
|
||||
socket1.connect(sp::endpoint());
|
||||
socket1.connect(sp::endpoint(), ec);
|
||||
|
||||
socket1.async_connect(sp::endpoint(), connect_handler);
|
||||
|
||||
socket1.set_option(socket_option);
|
||||
socket1.set_option(socket_option, ec);
|
||||
|
||||
socket1.get_option(socket_option);
|
||||
socket1.get_option(socket_option, ec);
|
||||
|
||||
socket1.io_control(io_control_command);
|
||||
socket1.io_control(io_control_command, ec);
|
||||
|
||||
sp::endpoint endpoint1 = socket1.local_endpoint();
|
||||
(void)endpoint1;
|
||||
sp::endpoint endpoint2 = socket1.local_endpoint(ec);
|
||||
(void)endpoint2;
|
||||
|
||||
sp::endpoint endpoint3 = socket1.remote_endpoint();
|
||||
(void)endpoint3;
|
||||
sp::endpoint endpoint4 = socket1.remote_endpoint(ec);
|
||||
(void)endpoint4;
|
||||
|
||||
socket1.shutdown(socket_base::shutdown_both);
|
||||
socket1.shutdown(socket_base::shutdown_both, ec);
|
||||
|
||||
// basic_stream_socket functions.
|
||||
|
||||
socket1.send(buffer(mutable_char_buffer));
|
||||
socket1.send(buffer(const_char_buffer));
|
||||
socket1.send(null_buffers());
|
||||
socket1.send(buffer(mutable_char_buffer), in_flags);
|
||||
socket1.send(buffer(const_char_buffer), in_flags);
|
||||
socket1.send(null_buffers(), in_flags);
|
||||
socket1.send(buffer(mutable_char_buffer), in_flags, ec);
|
||||
socket1.send(buffer(const_char_buffer), in_flags, ec);
|
||||
socket1.send(null_buffers(), in_flags, ec);
|
||||
|
||||
socket1.async_send(buffer(mutable_char_buffer), send_handler);
|
||||
socket1.async_send(buffer(const_char_buffer), send_handler);
|
||||
socket1.async_send(null_buffers(), send_handler);
|
||||
socket1.async_send(buffer(mutable_char_buffer), in_flags, send_handler);
|
||||
socket1.async_send(buffer(const_char_buffer), in_flags, send_handler);
|
||||
socket1.async_send(null_buffers(), in_flags, send_handler);
|
||||
|
||||
socket1.receive(buffer(mutable_char_buffer));
|
||||
socket1.receive(null_buffers());
|
||||
socket1.receive(buffer(mutable_char_buffer), in_flags);
|
||||
socket1.receive(null_buffers(), in_flags);
|
||||
socket1.receive(buffer(mutable_char_buffer), in_flags, ec);
|
||||
socket1.receive(null_buffers(), in_flags, ec);
|
||||
|
||||
socket1.async_receive(buffer(mutable_char_buffer), receive_handler);
|
||||
socket1.async_receive(null_buffers(), receive_handler);
|
||||
socket1.async_receive(buffer(mutable_char_buffer), in_flags,
|
||||
receive_handler);
|
||||
socket1.async_receive(null_buffers(), in_flags, receive_handler);
|
||||
|
||||
socket1.write_some(buffer(mutable_char_buffer));
|
||||
socket1.write_some(buffer(const_char_buffer));
|
||||
socket1.write_some(null_buffers());
|
||||
socket1.write_some(buffer(mutable_char_buffer), ec);
|
||||
socket1.write_some(buffer(const_char_buffer), ec);
|
||||
socket1.write_some(null_buffers(), ec);
|
||||
|
||||
socket1.async_write_some(buffer(mutable_char_buffer), write_some_handler);
|
||||
socket1.async_write_some(buffer(const_char_buffer), write_some_handler);
|
||||
socket1.async_write_some(null_buffers(), write_some_handler);
|
||||
|
||||
socket1.read_some(buffer(mutable_char_buffer));
|
||||
socket1.read_some(buffer(mutable_char_buffer), ec);
|
||||
socket1.read_some(null_buffers(), ec);
|
||||
|
||||
socket1.async_read_some(buffer(mutable_char_buffer), read_some_handler);
|
||||
socket1.async_read_some(null_buffers(), read_some_handler);
|
||||
}
|
||||
catch (std::exception&)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace generic_stream_protocol_socket_compile
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
ASIO_TEST_SUITE
|
||||
(
|
||||
"generic/stream_protocol",
|
||||
ASIO_TEST_CASE(generic_stream_protocol_socket_compile::test)
|
||||
)
|
||||
@@ -0,0 +1,30 @@
|
||||
//
|
||||
// high_resolution_timer.cpp
|
||||
// ~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
//
|
||||
// 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)
|
||||
//
|
||||
|
||||
// Disable autolinking for unit tests.
|
||||
#if !defined(BOOST_ALL_NO_LIB)
|
||||
#define BOOST_ALL_NO_LIB 1
|
||||
#endif // !defined(BOOST_ALL_NO_LIB)
|
||||
|
||||
// Prevent link dependency on the Boost.System library.
|
||||
#if !defined(BOOST_SYSTEM_NO_DEPRECATED)
|
||||
#define BOOST_SYSTEM_NO_DEPRECATED
|
||||
#endif // !defined(BOOST_SYSTEM_NO_DEPRECATED)
|
||||
|
||||
// Test that header file is self-contained.
|
||||
#include "asio/high_resolution_timer.hpp"
|
||||
|
||||
#include "unit_test.hpp"
|
||||
|
||||
ASIO_TEST_SUITE
|
||||
(
|
||||
"high_resolution_timer",
|
||||
ASIO_TEST_CASE(null_test)
|
||||
)
|
||||
@@ -0,0 +1,362 @@
|
||||
//
|
||||
// io_context.cpp
|
||||
// ~~~~~~~~~~~~~~
|
||||
//
|
||||
// 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)
|
||||
//
|
||||
|
||||
// Disable autolinking for unit tests.
|
||||
#if !defined(BOOST_ALL_NO_LIB)
|
||||
#define BOOST_ALL_NO_LIB 1
|
||||
#endif // !defined(BOOST_ALL_NO_LIB)
|
||||
|
||||
// Test that header file is self-contained.
|
||||
#include "asio/io_context.hpp"
|
||||
|
||||
#include <sstream>
|
||||
#include "asio/bind_executor.hpp"
|
||||
#include "asio/dispatch.hpp"
|
||||
#include "asio/post.hpp"
|
||||
#include "asio/thread.hpp"
|
||||
#include "unit_test.hpp"
|
||||
|
||||
#if defined(ASIO_HAS_BOOST_DATE_TIME)
|
||||
# include "asio/deadline_timer.hpp"
|
||||
#else // defined(ASIO_HAS_BOOST_DATE_TIME)
|
||||
# include "asio/steady_timer.hpp"
|
||||
#endif // defined(ASIO_HAS_BOOST_DATE_TIME)
|
||||
|
||||
#if defined(ASIO_HAS_BOOST_BIND)
|
||||
# include <boost/bind.hpp>
|
||||
#else // defined(ASIO_HAS_BOOST_BIND)
|
||||
# include <functional>
|
||||
#endif // defined(ASIO_HAS_BOOST_BIND)
|
||||
|
||||
using namespace asio;
|
||||
|
||||
#if defined(ASIO_HAS_BOOST_BIND)
|
||||
namespace bindns = boost;
|
||||
#else // defined(ASIO_HAS_BOOST_BIND)
|
||||
namespace bindns = std;
|
||||
#endif
|
||||
|
||||
#if defined(ASIO_HAS_BOOST_DATE_TIME)
|
||||
typedef deadline_timer timer;
|
||||
namespace chronons = boost::posix_time;
|
||||
#elif defined(ASIO_HAS_CHRONO)
|
||||
typedef steady_timer timer;
|
||||
namespace chronons = asio::chrono;
|
||||
#endif // defined(ASIO_HAS_BOOST_DATE_TIME)
|
||||
|
||||
void increment(int* count)
|
||||
{
|
||||
++(*count);
|
||||
}
|
||||
|
||||
void decrement_to_zero(io_context* ioc, int* count)
|
||||
{
|
||||
if (*count > 0)
|
||||
{
|
||||
--(*count);
|
||||
|
||||
int before_value = *count;
|
||||
asio::post(*ioc, bindns::bind(decrement_to_zero, ioc, count));
|
||||
|
||||
// Handler execution cannot nest, so count value should remain unchanged.
|
||||
ASIO_CHECK(*count == before_value);
|
||||
}
|
||||
}
|
||||
|
||||
void nested_decrement_to_zero(io_context* ioc, int* count)
|
||||
{
|
||||
if (*count > 0)
|
||||
{
|
||||
--(*count);
|
||||
|
||||
asio::dispatch(*ioc,
|
||||
bindns::bind(nested_decrement_to_zero, ioc, count));
|
||||
|
||||
// Handler execution is nested, so count value should now be zero.
|
||||
ASIO_CHECK(*count == 0);
|
||||
}
|
||||
}
|
||||
|
||||
void sleep_increment(io_context* ioc, int* count)
|
||||
{
|
||||
timer t(*ioc, chronons::seconds(2));
|
||||
t.wait();
|
||||
|
||||
if (++(*count) < 3)
|
||||
asio::post(*ioc, bindns::bind(sleep_increment, ioc, count));
|
||||
}
|
||||
|
||||
void start_sleep_increments(io_context* ioc, int* count)
|
||||
{
|
||||
// Give all threads a chance to start.
|
||||
timer t(*ioc, chronons::seconds(2));
|
||||
t.wait();
|
||||
|
||||
// Start the first of three increments.
|
||||
asio::post(*ioc, bindns::bind(sleep_increment, ioc, count));
|
||||
}
|
||||
|
||||
void throw_exception()
|
||||
{
|
||||
throw 1;
|
||||
}
|
||||
|
||||
void io_context_run(io_context* ioc)
|
||||
{
|
||||
ioc->run();
|
||||
}
|
||||
|
||||
void io_context_test()
|
||||
{
|
||||
io_context ioc;
|
||||
int count = 0;
|
||||
|
||||
asio::post(ioc, bindns::bind(increment, &count));
|
||||
|
||||
// No handlers can be called until run() is called.
|
||||
ASIO_CHECK(!ioc.stopped());
|
||||
ASIO_CHECK(count == 0);
|
||||
|
||||
ioc.run();
|
||||
|
||||
// The run() call will not return until all work has finished.
|
||||
ASIO_CHECK(ioc.stopped());
|
||||
ASIO_CHECK(count == 1);
|
||||
|
||||
count = 0;
|
||||
ioc.restart();
|
||||
asio::post(ioc, bindns::bind(increment, &count));
|
||||
asio::post(ioc, bindns::bind(increment, &count));
|
||||
asio::post(ioc, bindns::bind(increment, &count));
|
||||
asio::post(ioc, bindns::bind(increment, &count));
|
||||
asio::post(ioc, bindns::bind(increment, &count));
|
||||
|
||||
// No handlers can be called until run() is called.
|
||||
ASIO_CHECK(!ioc.stopped());
|
||||
ASIO_CHECK(count == 0);
|
||||
|
||||
ioc.run();
|
||||
|
||||
// The run() call will not return until all work has finished.
|
||||
ASIO_CHECK(ioc.stopped());
|
||||
ASIO_CHECK(count == 5);
|
||||
|
||||
count = 0;
|
||||
ioc.restart();
|
||||
executor_work_guard<io_context::executor_type> w = make_work_guard(ioc);
|
||||
asio::post(ioc, bindns::bind(&io_context::stop, &ioc));
|
||||
ASIO_CHECK(!ioc.stopped());
|
||||
ioc.run();
|
||||
|
||||
// The only operation executed should have been to stop run().
|
||||
ASIO_CHECK(ioc.stopped());
|
||||
ASIO_CHECK(count == 0);
|
||||
|
||||
ioc.restart();
|
||||
asio::post(ioc, bindns::bind(increment, &count));
|
||||
w.reset();
|
||||
|
||||
// No handlers can be called until run() is called.
|
||||
ASIO_CHECK(!ioc.stopped());
|
||||
ASIO_CHECK(count == 0);
|
||||
|
||||
ioc.run();
|
||||
|
||||
// The run() call will not return until all work has finished.
|
||||
ASIO_CHECK(ioc.stopped());
|
||||
ASIO_CHECK(count == 1);
|
||||
|
||||
count = 10;
|
||||
ioc.restart();
|
||||
asio::post(ioc, bindns::bind(decrement_to_zero, &ioc, &count));
|
||||
|
||||
// No handlers can be called until run() is called.
|
||||
ASIO_CHECK(!ioc.stopped());
|
||||
ASIO_CHECK(count == 10);
|
||||
|
||||
ioc.run();
|
||||
|
||||
// The run() call will not return until all work has finished.
|
||||
ASIO_CHECK(ioc.stopped());
|
||||
ASIO_CHECK(count == 0);
|
||||
|
||||
count = 10;
|
||||
ioc.restart();
|
||||
asio::post(ioc, bindns::bind(nested_decrement_to_zero, &ioc, &count));
|
||||
|
||||
// No handlers can be called until run() is called.
|
||||
ASIO_CHECK(!ioc.stopped());
|
||||
ASIO_CHECK(count == 10);
|
||||
|
||||
ioc.run();
|
||||
|
||||
// The run() call will not return until all work has finished.
|
||||
ASIO_CHECK(ioc.stopped());
|
||||
ASIO_CHECK(count == 0);
|
||||
|
||||
count = 10;
|
||||
ioc.restart();
|
||||
asio::dispatch(ioc,
|
||||
bindns::bind(nested_decrement_to_zero, &ioc, &count));
|
||||
|
||||
// No handlers can be called until run() is called, even though nested
|
||||
// delivery was specifically allowed in the previous call.
|
||||
ASIO_CHECK(!ioc.stopped());
|
||||
ASIO_CHECK(count == 10);
|
||||
|
||||
ioc.run();
|
||||
|
||||
// The run() call will not return until all work has finished.
|
||||
ASIO_CHECK(ioc.stopped());
|
||||
ASIO_CHECK(count == 0);
|
||||
|
||||
count = 0;
|
||||
int count2 = 0;
|
||||
ioc.restart();
|
||||
ASIO_CHECK(!ioc.stopped());
|
||||
asio::post(ioc, bindns::bind(start_sleep_increments, &ioc, &count));
|
||||
asio::post(ioc, bindns::bind(start_sleep_increments, &ioc, &count2));
|
||||
thread thread1(bindns::bind(io_context_run, &ioc));
|
||||
thread thread2(bindns::bind(io_context_run, &ioc));
|
||||
thread1.join();
|
||||
thread2.join();
|
||||
|
||||
// The run() calls will not return until all work has finished.
|
||||
ASIO_CHECK(ioc.stopped());
|
||||
ASIO_CHECK(count == 3);
|
||||
ASIO_CHECK(count2 == 3);
|
||||
|
||||
count = 10;
|
||||
io_context ioc2;
|
||||
asio::dispatch(ioc, asio::bind_executor(ioc2,
|
||||
bindns::bind(decrement_to_zero, &ioc2, &count)));
|
||||
ioc.restart();
|
||||
ASIO_CHECK(!ioc.stopped());
|
||||
ioc.run();
|
||||
|
||||
// No decrement_to_zero handlers can be called until run() is called on the
|
||||
// second io_context object.
|
||||
ASIO_CHECK(ioc.stopped());
|
||||
ASIO_CHECK(count == 10);
|
||||
|
||||
ioc2.run();
|
||||
|
||||
// The run() call will not return until all work has finished.
|
||||
ASIO_CHECK(count == 0);
|
||||
|
||||
count = 0;
|
||||
int exception_count = 0;
|
||||
ioc.restart();
|
||||
asio::post(ioc, &throw_exception);
|
||||
asio::post(ioc, bindns::bind(increment, &count));
|
||||
asio::post(ioc, bindns::bind(increment, &count));
|
||||
asio::post(ioc, &throw_exception);
|
||||
asio::post(ioc, bindns::bind(increment, &count));
|
||||
|
||||
// No handlers can be called until run() is called.
|
||||
ASIO_CHECK(!ioc.stopped());
|
||||
ASIO_CHECK(count == 0);
|
||||
ASIO_CHECK(exception_count == 0);
|
||||
|
||||
for (;;)
|
||||
{
|
||||
try
|
||||
{
|
||||
ioc.run();
|
||||
break;
|
||||
}
|
||||
catch (int)
|
||||
{
|
||||
++exception_count;
|
||||
}
|
||||
}
|
||||
|
||||
// The run() calls will not return until all work has finished.
|
||||
ASIO_CHECK(ioc.stopped());
|
||||
ASIO_CHECK(count == 3);
|
||||
ASIO_CHECK(exception_count == 2);
|
||||
}
|
||||
|
||||
class test_service : public asio::io_context::service
|
||||
{
|
||||
public:
|
||||
static asio::io_context::id id;
|
||||
test_service(asio::io_context& s)
|
||||
: asio::io_context::service(s) {}
|
||||
private:
|
||||
virtual void shutdown_service() {}
|
||||
};
|
||||
|
||||
asio::io_context::id test_service::id;
|
||||
|
||||
void io_context_service_test()
|
||||
{
|
||||
asio::io_context ioc1;
|
||||
asio::io_context ioc2;
|
||||
asio::io_context ioc3;
|
||||
|
||||
// Implicit service registration.
|
||||
|
||||
asio::use_service<test_service>(ioc1);
|
||||
|
||||
ASIO_CHECK(asio::has_service<test_service>(ioc1));
|
||||
|
||||
test_service* svc1 = new test_service(ioc1);
|
||||
try
|
||||
{
|
||||
asio::add_service(ioc1, svc1);
|
||||
ASIO_ERROR("add_service did not throw");
|
||||
}
|
||||
catch (asio::service_already_exists&)
|
||||
{
|
||||
}
|
||||
delete svc1;
|
||||
|
||||
// Explicit service registration.
|
||||
|
||||
test_service* svc2 = new test_service(ioc2);
|
||||
asio::add_service(ioc2, svc2);
|
||||
|
||||
ASIO_CHECK(asio::has_service<test_service>(ioc2));
|
||||
ASIO_CHECK(&asio::use_service<test_service>(ioc2) == svc2);
|
||||
|
||||
test_service* svc3 = new test_service(ioc2);
|
||||
try
|
||||
{
|
||||
asio::add_service(ioc2, svc3);
|
||||
ASIO_ERROR("add_service did not throw");
|
||||
}
|
||||
catch (asio::service_already_exists&)
|
||||
{
|
||||
}
|
||||
delete svc3;
|
||||
|
||||
// Explicit registration with invalid owner.
|
||||
|
||||
test_service* svc4 = new test_service(ioc2);
|
||||
try
|
||||
{
|
||||
asio::add_service(ioc3, svc4);
|
||||
ASIO_ERROR("add_service did not throw");
|
||||
}
|
||||
catch (asio::invalid_service_owner&)
|
||||
{
|
||||
}
|
||||
delete svc4;
|
||||
|
||||
ASIO_CHECK(!asio::has_service<test_service>(ioc3));
|
||||
}
|
||||
|
||||
ASIO_TEST_SUITE
|
||||
(
|
||||
"io_context",
|
||||
ASIO_TEST_CASE(io_context_test)
|
||||
ASIO_TEST_CASE(io_context_service_test)
|
||||
)
|
||||
@@ -0,0 +1,325 @@
|
||||
//
|
||||
// io_context_strand.cpp
|
||||
// ~~~~~~~~~~~~~~~~~~~~~
|
||||
//
|
||||
// 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)
|
||||
//
|
||||
|
||||
// Disable autolinking for unit tests.
|
||||
#if !defined(BOOST_ALL_NO_LIB)
|
||||
#define BOOST_ALL_NO_LIB 1
|
||||
#endif // !defined(BOOST_ALL_NO_LIB)
|
||||
|
||||
// Test that header file is self-contained.
|
||||
#include "asio/io_context_strand.hpp"
|
||||
|
||||
#include <sstream>
|
||||
#include "asio/io_context.hpp"
|
||||
#include "asio/dispatch.hpp"
|
||||
#include "asio/post.hpp"
|
||||
#include "asio/thread.hpp"
|
||||
#include "unit_test.hpp"
|
||||
|
||||
#if defined(ASIO_HAS_BOOST_DATE_TIME)
|
||||
# include "asio/deadline_timer.hpp"
|
||||
#else // defined(ASIO_HAS_BOOST_DATE_TIME)
|
||||
# include "asio/steady_timer.hpp"
|
||||
#endif // defined(ASIO_HAS_BOOST_DATE_TIME)
|
||||
|
||||
#if defined(ASIO_HAS_BOOST_BIND)
|
||||
# include <boost/bind.hpp>
|
||||
#else // defined(ASIO_HAS_BOOST_BIND)
|
||||
# include <functional>
|
||||
#endif // defined(ASIO_HAS_BOOST_BIND)
|
||||
|
||||
using namespace asio;
|
||||
|
||||
#if defined(ASIO_HAS_BOOST_BIND)
|
||||
namespace bindns = boost;
|
||||
#else // defined(ASIO_HAS_BOOST_BIND)
|
||||
namespace bindns = std;
|
||||
#endif
|
||||
|
||||
#if defined(ASIO_HAS_BOOST_DATE_TIME)
|
||||
typedef deadline_timer timer;
|
||||
namespace chronons = boost::posix_time;
|
||||
#elif defined(ASIO_HAS_CHRONO)
|
||||
typedef steady_timer timer;
|
||||
namespace chronons = asio::chrono;
|
||||
#endif // defined(ASIO_HAS_BOOST_DATE_TIME)
|
||||
|
||||
void increment(int* count)
|
||||
{
|
||||
++(*count);
|
||||
}
|
||||
|
||||
void increment_without_lock(io_context::strand* s, int* count)
|
||||
{
|
||||
ASIO_CHECK(!s->running_in_this_thread());
|
||||
|
||||
int original_count = *count;
|
||||
|
||||
dispatch(*s, bindns::bind(increment, count));
|
||||
|
||||
// No other functions are currently executing through the locking dispatcher,
|
||||
// so the previous call to dispatch should have successfully nested.
|
||||
ASIO_CHECK(*count == original_count + 1);
|
||||
}
|
||||
|
||||
void increment_with_lock(io_context::strand* s, int* count)
|
||||
{
|
||||
ASIO_CHECK(s->running_in_this_thread());
|
||||
|
||||
int original_count = *count;
|
||||
|
||||
dispatch(*s, bindns::bind(increment, count));
|
||||
|
||||
// The current function already holds the strand's lock, so the
|
||||
// previous call to dispatch should have successfully nested.
|
||||
ASIO_CHECK(*count == original_count + 1);
|
||||
}
|
||||
|
||||
void sleep_increment(io_context* ioc, int* count)
|
||||
{
|
||||
timer t(*ioc, chronons::seconds(2));
|
||||
t.wait();
|
||||
|
||||
++(*count);
|
||||
}
|
||||
|
||||
void increment_by_a(int* count, int a)
|
||||
{
|
||||
(*count) += a;
|
||||
}
|
||||
|
||||
void increment_by_a_b(int* count, int a, int b)
|
||||
{
|
||||
(*count) += a + b;
|
||||
}
|
||||
|
||||
void increment_by_a_b_c(int* count, int a, int b, int c)
|
||||
{
|
||||
(*count) += a + b + c;
|
||||
}
|
||||
|
||||
void increment_by_a_b_c_d(int* count, int a, int b, int c, int d)
|
||||
{
|
||||
(*count) += a + b + c + d;
|
||||
}
|
||||
|
||||
void start_sleep_increments(io_context* ioc, io_context::strand* s, int* count)
|
||||
{
|
||||
// Give all threads a chance to start.
|
||||
timer t(*ioc, chronons::seconds(2));
|
||||
t.wait();
|
||||
|
||||
// Start three increments.
|
||||
post(*s, bindns::bind(sleep_increment, ioc, count));
|
||||
post(*s, bindns::bind(sleep_increment, ioc, count));
|
||||
post(*s, bindns::bind(sleep_increment, ioc, count));
|
||||
}
|
||||
|
||||
void throw_exception()
|
||||
{
|
||||
throw 1;
|
||||
}
|
||||
|
||||
void io_context_run(io_context* ioc)
|
||||
{
|
||||
ioc->run();
|
||||
}
|
||||
|
||||
void strand_test()
|
||||
{
|
||||
io_context ioc;
|
||||
io_context::strand s(ioc);
|
||||
int count = 0;
|
||||
|
||||
post(ioc, bindns::bind(increment_without_lock, &s, &count));
|
||||
|
||||
// No handlers can be called until run() is called.
|
||||
ASIO_CHECK(count == 0);
|
||||
|
||||
ioc.run();
|
||||
|
||||
// The run() call will not return until all work has finished.
|
||||
ASIO_CHECK(count == 1);
|
||||
|
||||
count = 0;
|
||||
ioc.restart();
|
||||
post(s, bindns::bind(increment_with_lock, &s, &count));
|
||||
|
||||
// No handlers can be called until run() is called.
|
||||
ASIO_CHECK(count == 0);
|
||||
|
||||
ioc.run();
|
||||
|
||||
// The run() call will not return until all work has finished.
|
||||
ASIO_CHECK(count == 1);
|
||||
|
||||
count = 0;
|
||||
ioc.restart();
|
||||
post(ioc, bindns::bind(start_sleep_increments, &ioc, &s, &count));
|
||||
thread thread1(bindns::bind(io_context_run, &ioc));
|
||||
thread thread2(bindns::bind(io_context_run, &ioc));
|
||||
|
||||
// Check all events run one after another even though there are two threads.
|
||||
timer timer1(ioc, chronons::seconds(3));
|
||||
timer1.wait();
|
||||
ASIO_CHECK(count == 0);
|
||||
#if defined(ASIO_HAS_BOOST_DATE_TIME)
|
||||
timer1.expires_at(timer1.expires_at() + chronons::seconds(2));
|
||||
#else // defined(ASIO_HAS_BOOST_DATE_TIME)
|
||||
timer1.expires_at(timer1.expiry() + chronons::seconds(2));
|
||||
#endif // defined(ASIO_HAS_BOOST_DATE_TIME)
|
||||
timer1.wait();
|
||||
ASIO_CHECK(count == 1);
|
||||
#if defined(ASIO_HAS_BOOST_DATE_TIME)
|
||||
timer1.expires_at(timer1.expires_at() + chronons::seconds(2));
|
||||
#else // defined(ASIO_HAS_BOOST_DATE_TIME)
|
||||
timer1.expires_at(timer1.expiry() + chronons::seconds(2));
|
||||
#endif // defined(ASIO_HAS_BOOST_DATE_TIME)
|
||||
timer1.wait();
|
||||
ASIO_CHECK(count == 2);
|
||||
|
||||
thread1.join();
|
||||
thread2.join();
|
||||
|
||||
// The run() calls will not return until all work has finished.
|
||||
ASIO_CHECK(count == 3);
|
||||
|
||||
count = 0;
|
||||
int exception_count = 0;
|
||||
ioc.restart();
|
||||
post(s, throw_exception);
|
||||
post(s, bindns::bind(increment, &count));
|
||||
post(s, bindns::bind(increment, &count));
|
||||
post(s, throw_exception);
|
||||
post(s, bindns::bind(increment, &count));
|
||||
|
||||
// No handlers can be called until run() is called.
|
||||
ASIO_CHECK(count == 0);
|
||||
ASIO_CHECK(exception_count == 0);
|
||||
|
||||
for (;;)
|
||||
{
|
||||
try
|
||||
{
|
||||
ioc.run();
|
||||
break;
|
||||
}
|
||||
catch (int)
|
||||
{
|
||||
++exception_count;
|
||||
}
|
||||
}
|
||||
|
||||
// The run() calls will not return until all work has finished.
|
||||
ASIO_CHECK(count == 3);
|
||||
ASIO_CHECK(exception_count == 2);
|
||||
|
||||
count = 0;
|
||||
ioc.restart();
|
||||
|
||||
// Check for clean shutdown when handlers posted through an orphaned strand
|
||||
// are abandoned.
|
||||
{
|
||||
io_context::strand s2(ioc);
|
||||
post(s2, bindns::bind(increment, &count));
|
||||
post(s2, bindns::bind(increment, &count));
|
||||
post(s2, bindns::bind(increment, &count));
|
||||
}
|
||||
|
||||
// No handlers can be called until run() is called.
|
||||
ASIO_CHECK(count == 0);
|
||||
}
|
||||
|
||||
void strand_wrap_test()
|
||||
{
|
||||
#if !defined(ASIO_NO_DEPRECATED)
|
||||
io_context ioc;
|
||||
io_context::strand s(ioc);
|
||||
int count = 0;
|
||||
|
||||
s.wrap(bindns::bind(increment, &count))();
|
||||
|
||||
// No handlers can be called until run() is called.
|
||||
ASIO_CHECK(count == 0);
|
||||
|
||||
ioc.restart();
|
||||
ioc.run();
|
||||
|
||||
// The run() calls will not return until all work has finished.
|
||||
ASIO_CHECK(count == 1);
|
||||
|
||||
count = 0;
|
||||
s.wrap(increment)(&count);
|
||||
|
||||
// No handlers can be called until run() is called.
|
||||
ASIO_CHECK(count == 0);
|
||||
|
||||
ioc.restart();
|
||||
ioc.run();
|
||||
|
||||
// The run() calls will not return until all work has finished.
|
||||
ASIO_CHECK(count == 1);
|
||||
|
||||
count = 0;
|
||||
s.wrap(increment_by_a)(&count, 1);
|
||||
|
||||
// No handlers can be called until run() is called.
|
||||
ASIO_CHECK(count == 0);
|
||||
|
||||
ioc.restart();
|
||||
ioc.run();
|
||||
|
||||
// The run() calls will not return until all work has finished.
|
||||
ASIO_CHECK(count == 1);
|
||||
|
||||
count = 0;
|
||||
s.wrap(increment_by_a_b)(&count, 1, 2);
|
||||
|
||||
// No handlers can be called until run() is called.
|
||||
ASIO_CHECK(count == 0);
|
||||
|
||||
ioc.restart();
|
||||
ioc.run();
|
||||
|
||||
// The run() calls will not return until all work has finished.
|
||||
ASIO_CHECK(count == 3);
|
||||
|
||||
count = 0;
|
||||
s.wrap(increment_by_a_b_c)(&count, 1, 2, 3);
|
||||
|
||||
// No handlers can be called until run() is called.
|
||||
ASIO_CHECK(count == 0);
|
||||
|
||||
ioc.restart();
|
||||
ioc.run();
|
||||
|
||||
// The run() calls will not return until all work has finished.
|
||||
ASIO_CHECK(count == 6);
|
||||
|
||||
count = 0;
|
||||
s.wrap(increment_by_a_b_c_d)(&count, 1, 2, 3, 4);
|
||||
|
||||
// No handlers can be called until run() is called.
|
||||
ASIO_CHECK(count == 0);
|
||||
|
||||
ioc.restart();
|
||||
ioc.run();
|
||||
|
||||
// The run() calls will not return until all work has finished.
|
||||
ASIO_CHECK(count == 10);
|
||||
#endif // !defined(ASIO_NO_DEPRECATED)
|
||||
}
|
||||
|
||||
ASIO_TEST_SUITE
|
||||
(
|
||||
"strand",
|
||||
ASIO_TEST_CASE(strand_test)
|
||||
ASIO_TEST_CASE(strand_wrap_test)
|
||||
)
|
||||
@@ -0,0 +1,27 @@
|
||||
.deps
|
||||
.dirstamp
|
||||
*.o
|
||||
*.obj
|
||||
*.exe
|
||||
*.ilk
|
||||
*.manifest
|
||||
*.pdb
|
||||
*.tds
|
||||
address
|
||||
address_v4*
|
||||
address_v6*
|
||||
basic_endpoint
|
||||
basic_resolver
|
||||
basic_resolver_entry
|
||||
basic_resolver_iterator
|
||||
basic_resolver_query
|
||||
host_name
|
||||
icmp
|
||||
multicast
|
||||
network_v4
|
||||
network_v6
|
||||
resolver_query_base
|
||||
tcp
|
||||
udp
|
||||
unicast
|
||||
v6_only
|
||||
@@ -0,0 +1,144 @@
|
||||
//
|
||||
// address.cpp
|
||||
// ~~~~~~~~~~~
|
||||
//
|
||||
// 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)
|
||||
//
|
||||
|
||||
// Disable autolinking for unit tests.
|
||||
#if !defined(BOOST_ALL_NO_LIB)
|
||||
#define BOOST_ALL_NO_LIB 1
|
||||
#endif // !defined(BOOST_ALL_NO_LIB)
|
||||
|
||||
// Test that header file is self-contained.
|
||||
#include "asio/ip/address.hpp"
|
||||
|
||||
#include "../unit_test.hpp"
|
||||
#include <sstream>
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
// ip_address_compile test
|
||||
// ~~~~~~~~~~~~~~~~~~~~~~~
|
||||
// The following test checks that all public member functions on the class
|
||||
// ip::address compile and link correctly. Runtime failures are ignored.
|
||||
|
||||
namespace ip_address_compile {
|
||||
|
||||
void test()
|
||||
{
|
||||
using namespace asio;
|
||||
namespace ip = asio::ip;
|
||||
|
||||
try
|
||||
{
|
||||
asio::error_code ec;
|
||||
|
||||
// address constructors.
|
||||
|
||||
ip::address addr1;
|
||||
const ip::address_v4 const_addr_v4;
|
||||
ip::address addr2(const_addr_v4);
|
||||
const ip::address_v6 const_addr_v6;
|
||||
ip::address addr3(const_addr_v6);
|
||||
|
||||
// address functions.
|
||||
|
||||
bool b = addr1.is_v4();
|
||||
(void)b;
|
||||
|
||||
b = addr1.is_v6();
|
||||
(void)b;
|
||||
|
||||
b = addr1.is_loopback();
|
||||
(void)b;
|
||||
|
||||
b = addr1.is_unspecified();
|
||||
(void)b;
|
||||
|
||||
b = addr1.is_multicast();
|
||||
(void)b;
|
||||
|
||||
ip::address_v4 addr_v4_value = addr1.to_v4();
|
||||
(void)addr_v4_value;
|
||||
|
||||
ip::address_v6 addr_v6_value = addr1.to_v6();
|
||||
(void)addr_v6_value;
|
||||
|
||||
std::string string_value = addr1.to_string();
|
||||
#if !defined(ASIO_NO_DEPRECATED)
|
||||
string_value = addr1.to_string(ec);
|
||||
#endif // !defined(ASIO_NO_DEPRECATED)
|
||||
|
||||
// address static functions.
|
||||
|
||||
#if !defined(ASIO_NO_DEPRECATED)
|
||||
addr1 = ip::address::from_string("127.0.0.1");
|
||||
addr1 = ip::address::from_string("127.0.0.1", ec);
|
||||
addr1 = ip::address::from_string(string_value);
|
||||
addr1 = ip::address::from_string(string_value, ec);
|
||||
#endif // !defined(ASIO_NO_DEPRECATED)
|
||||
|
||||
// address comparisons.
|
||||
|
||||
b = (addr1 == addr2);
|
||||
(void)b;
|
||||
|
||||
b = (addr1 != addr2);
|
||||
(void)b;
|
||||
|
||||
b = (addr1 < addr2);
|
||||
(void)b;
|
||||
|
||||
b = (addr1 > addr2);
|
||||
(void)b;
|
||||
|
||||
b = (addr1 <= addr2);
|
||||
(void)b;
|
||||
|
||||
b = (addr1 >= addr2);
|
||||
(void)b;
|
||||
|
||||
// address creation functions.
|
||||
|
||||
addr1 = ip::make_address("127.0.0.1");
|
||||
addr1 = ip::make_address("127.0.0.1", ec);
|
||||
addr1 = ip::make_address(string_value);
|
||||
addr1 = ip::make_address(string_value, ec);
|
||||
#if defined(ASIO_HAS_STRING_VIEW)
|
||||
# if defined(ASIO_HAS_STD_STRING_VIEW)
|
||||
std::string_view string_view_value("127.0.0.1");
|
||||
# elif defined(ASIO_HAS_STD_EXPERIMENTAL_STRING_VIEW)
|
||||
std::experimental::string_view string_view_value("127.0.0.1");
|
||||
# endif // defined(ASIO_HAS_STD_EXPERIMENTAL_STRING_VIEW)
|
||||
addr1 = ip::make_address(string_view_value);
|
||||
addr1 = ip::make_address(string_view_value, ec);
|
||||
#endif // defined(ASIO_HAS_STRING_VIEW)
|
||||
|
||||
// address I/O.
|
||||
|
||||
std::ostringstream os;
|
||||
os << addr1;
|
||||
|
||||
#if !defined(BOOST_NO_STD_WSTREAMBUF)
|
||||
std::wostringstream wos;
|
||||
wos << addr1;
|
||||
#endif // !defined(BOOST_NO_STD_WSTREAMBUF)
|
||||
}
|
||||
catch (std::exception&)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace ip_address_compile
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
ASIO_TEST_SUITE
|
||||
(
|
||||
"ip/address",
|
||||
ASIO_TEST_CASE(ip_address_compile::test)
|
||||
)
|
||||
@@ -0,0 +1,324 @@
|
||||
//
|
||||
// address_v4.cpp
|
||||
// ~~~~~~~~~~~~~~
|
||||
//
|
||||
// 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)
|
||||
//
|
||||
|
||||
// Disable autolinking for unit tests.
|
||||
#if !defined(BOOST_ALL_NO_LIB)
|
||||
#define BOOST_ALL_NO_LIB 1
|
||||
#endif // !defined(BOOST_ALL_NO_LIB)
|
||||
|
||||
// Test that header file is self-contained.
|
||||
#include "asio/ip/address_v4.hpp"
|
||||
|
||||
#include "../unit_test.hpp"
|
||||
#include <sstream>
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
// ip_address_v4_compile test
|
||||
// ~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
// The following test checks that all public member functions on the class
|
||||
// ip::address_v4 compile and link correctly. Runtime failures are ignored.
|
||||
|
||||
namespace ip_address_v4_compile {
|
||||
|
||||
void test()
|
||||
{
|
||||
using namespace asio;
|
||||
namespace ip = asio::ip;
|
||||
|
||||
try
|
||||
{
|
||||
asio::error_code ec;
|
||||
|
||||
// address_v4 constructors.
|
||||
|
||||
ip::address_v4 addr1;
|
||||
const ip::address_v4::bytes_type const_bytes_value = { { 127, 0, 0, 1 } };
|
||||
ip::address_v4 addr2(const_bytes_value);
|
||||
const unsigned long const_ulong_value = 0x7F000001;
|
||||
ip::address_v4 addr3(const_ulong_value);
|
||||
|
||||
// address_v4 functions.
|
||||
|
||||
bool b = addr1.is_loopback();
|
||||
(void)b;
|
||||
|
||||
b = addr1.is_unspecified();
|
||||
(void)b;
|
||||
|
||||
#if !defined(ASIO_NO_DEPRECATED)
|
||||
b = addr1.is_class_a();
|
||||
(void)b;
|
||||
|
||||
b = addr1.is_class_b();
|
||||
(void)b;
|
||||
|
||||
b = addr1.is_class_c();
|
||||
(void)b;
|
||||
#endif // !defined(ASIO_NO_DEPRECATED)
|
||||
|
||||
b = addr1.is_multicast();
|
||||
(void)b;
|
||||
|
||||
ip::address_v4::bytes_type bytes_value = addr1.to_bytes();
|
||||
(void)bytes_value;
|
||||
|
||||
ip::address_v4::uint_type uint_value = addr1.to_uint();
|
||||
(void)uint_value;
|
||||
|
||||
#if !defined(ASIO_NO_DEPRECATED)
|
||||
unsigned long ulong_value = addr1.to_ulong();
|
||||
(void)ulong_value;
|
||||
#endif // !defined(ASIO_NO_DEPRECATED)
|
||||
|
||||
std::string string_value = addr1.to_string();
|
||||
#if !defined(ASIO_NO_DEPRECATED)
|
||||
string_value = addr1.to_string(ec);
|
||||
#endif // !defined(ASIO_NO_DEPRECATED)
|
||||
|
||||
// address_v4 static functions.
|
||||
|
||||
#if !defined(ASIO_NO_DEPRECATED)
|
||||
addr1 = ip::address_v4::from_string("127.0.0.1");
|
||||
addr1 = ip::address_v4::from_string("127.0.0.1", ec);
|
||||
addr1 = ip::address_v4::from_string(string_value);
|
||||
addr1 = ip::address_v4::from_string(string_value, ec);
|
||||
#endif // !defined(ASIO_NO_DEPRECATED)
|
||||
|
||||
addr1 = ip::address_v4::any();
|
||||
|
||||
addr1 = ip::address_v4::loopback();
|
||||
|
||||
addr1 = ip::address_v4::broadcast();
|
||||
|
||||
#if !defined(ASIO_NO_DEPRECATED)
|
||||
addr1 = ip::address_v4::broadcast(addr2, addr3);
|
||||
|
||||
addr1 = ip::address_v4::netmask(addr2);
|
||||
#endif // !defined(ASIO_NO_DEPRECATED)
|
||||
|
||||
// address_v4 comparisons.
|
||||
|
||||
b = (addr1 == addr2);
|
||||
(void)b;
|
||||
|
||||
b = (addr1 != addr2);
|
||||
(void)b;
|
||||
|
||||
b = (addr1 < addr2);
|
||||
(void)b;
|
||||
|
||||
b = (addr1 > addr2);
|
||||
(void)b;
|
||||
|
||||
b = (addr1 <= addr2);
|
||||
(void)b;
|
||||
|
||||
b = (addr1 >= addr2);
|
||||
(void)b;
|
||||
|
||||
// address_v4 creation functions.
|
||||
|
||||
addr1 = ip::make_address_v4(const_bytes_value);
|
||||
addr1 = ip::make_address_v4(const_ulong_value);
|
||||
addr1 = ip::make_address_v4("127.0.0.1");
|
||||
addr1 = ip::make_address_v4("127.0.0.1", ec);
|
||||
addr1 = ip::make_address_v4(string_value);
|
||||
addr1 = ip::make_address_v4(string_value, ec);
|
||||
#if defined(ASIO_HAS_STRING_VIEW)
|
||||
# if defined(ASIO_HAS_STD_STRING_VIEW)
|
||||
std::string_view string_view_value("127.0.0.1");
|
||||
# elif defined(ASIO_HAS_STD_EXPERIMENTAL_STRING_VIEW)
|
||||
std::experimental::string_view string_view_value("127.0.0.1");
|
||||
# endif // defined(ASIO_HAS_STD_EXPERIMENTAL_STRING_VIEW)
|
||||
addr1 = ip::make_address_v4(string_view_value);
|
||||
addr1 = ip::make_address_v4(string_view_value, ec);
|
||||
#endif // defined(ASIO_HAS_STRING_VIEW)
|
||||
|
||||
// address_v4 I/O.
|
||||
|
||||
std::ostringstream os;
|
||||
os << addr1;
|
||||
|
||||
#if !defined(BOOST_NO_STD_WSTREAMBUF)
|
||||
std::wostringstream wos;
|
||||
wos << addr1;
|
||||
#endif // !defined(BOOST_NO_STD_WSTREAMBUF)
|
||||
}
|
||||
catch (std::exception&)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace ip_address_v4_compile
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
// ip_address_v4_runtime test
|
||||
// ~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
// The following test checks that the various public member functions meet the
|
||||
// necessary postconditions.
|
||||
|
||||
namespace ip_address_v4_runtime {
|
||||
|
||||
void test()
|
||||
{
|
||||
using asio::ip::address_v4;
|
||||
|
||||
address_v4 a1;
|
||||
ASIO_CHECK(a1.to_bytes()[0] == 0);
|
||||
ASIO_CHECK(a1.to_bytes()[1] == 0);
|
||||
ASIO_CHECK(a1.to_bytes()[2] == 0);
|
||||
ASIO_CHECK(a1.to_bytes()[3] == 0);
|
||||
ASIO_CHECK(a1.to_uint() == 0);
|
||||
#if !defined(ASIO_NO_DEPRECATED)
|
||||
ASIO_CHECK(a1.to_ulong() == 0);
|
||||
#endif // !defined(ASIO_NO_DEPRECATED)
|
||||
|
||||
address_v4::bytes_type b1 = {{ 1, 2, 3, 4 }};
|
||||
address_v4 a2(b1);
|
||||
ASIO_CHECK(a2.to_bytes()[0] == 1);
|
||||
ASIO_CHECK(a2.to_bytes()[1] == 2);
|
||||
ASIO_CHECK(a2.to_bytes()[2] == 3);
|
||||
ASIO_CHECK(a2.to_bytes()[3] == 4);
|
||||
ASIO_CHECK(((a2.to_uint() >> 24) & 0xFF) == b1[0]);
|
||||
ASIO_CHECK(((a2.to_uint() >> 16) & 0xFF) == b1[1]);
|
||||
ASIO_CHECK(((a2.to_uint() >> 8) & 0xFF) == b1[2]);
|
||||
ASIO_CHECK((a2.to_uint() & 0xFF) == b1[3]);
|
||||
#if !defined(ASIO_NO_DEPRECATED)
|
||||
ASIO_CHECK(((a2.to_ulong() >> 24) & 0xFF) == b1[0]);
|
||||
ASIO_CHECK(((a2.to_ulong() >> 16) & 0xFF) == b1[1]);
|
||||
ASIO_CHECK(((a2.to_ulong() >> 8) & 0xFF) == b1[2]);
|
||||
ASIO_CHECK((a2.to_ulong() & 0xFF) == b1[3]);
|
||||
#endif // !defined(ASIO_NO_DEPRECATED)
|
||||
|
||||
address_v4 a3(0x01020304);
|
||||
ASIO_CHECK(a3.to_bytes()[0] == 1);
|
||||
ASIO_CHECK(a3.to_bytes()[1] == 2);
|
||||
ASIO_CHECK(a3.to_bytes()[2] == 3);
|
||||
ASIO_CHECK(a3.to_bytes()[3] == 4);
|
||||
ASIO_CHECK(a3.to_uint() == 0x01020304);
|
||||
#if !defined(ASIO_NO_DEPRECATED)
|
||||
ASIO_CHECK(a3.to_ulong() == 0x01020304);
|
||||
#endif // !defined(ASIO_NO_DEPRECATED)
|
||||
|
||||
ASIO_CHECK(address_v4(0x7F000001).is_loopback());
|
||||
ASIO_CHECK(address_v4(0x7F000002).is_loopback());
|
||||
ASIO_CHECK(!address_v4(0x00000000).is_loopback());
|
||||
ASIO_CHECK(!address_v4(0x01020304).is_loopback());
|
||||
|
||||
ASIO_CHECK(address_v4(0x00000000).is_unspecified());
|
||||
ASIO_CHECK(!address_v4(0x7F000001).is_unspecified());
|
||||
ASIO_CHECK(!address_v4(0x01020304).is_unspecified());
|
||||
|
||||
#if !defined(ASIO_NO_DEPRECATED)
|
||||
ASIO_CHECK(address_v4(0x01000000).is_class_a());
|
||||
ASIO_CHECK(address_v4(0x7F000000).is_class_a());
|
||||
ASIO_CHECK(!address_v4(0x80000000).is_class_a());
|
||||
ASIO_CHECK(!address_v4(0xBFFF0000).is_class_a());
|
||||
ASIO_CHECK(!address_v4(0xC0000000).is_class_a());
|
||||
ASIO_CHECK(!address_v4(0xDFFFFF00).is_class_a());
|
||||
ASIO_CHECK(!address_v4(0xE0000000).is_class_a());
|
||||
ASIO_CHECK(!address_v4(0xEFFFFFFF).is_class_a());
|
||||
ASIO_CHECK(!address_v4(0xF0000000).is_class_a());
|
||||
ASIO_CHECK(!address_v4(0xFFFFFFFF).is_class_a());
|
||||
|
||||
ASIO_CHECK(!address_v4(0x01000000).is_class_b());
|
||||
ASIO_CHECK(!address_v4(0x7F000000).is_class_b());
|
||||
ASIO_CHECK(address_v4(0x80000000).is_class_b());
|
||||
ASIO_CHECK(address_v4(0xBFFF0000).is_class_b());
|
||||
ASIO_CHECK(!address_v4(0xC0000000).is_class_b());
|
||||
ASIO_CHECK(!address_v4(0xDFFFFF00).is_class_b());
|
||||
ASIO_CHECK(!address_v4(0xE0000000).is_class_b());
|
||||
ASIO_CHECK(!address_v4(0xEFFFFFFF).is_class_b());
|
||||
ASIO_CHECK(!address_v4(0xF0000000).is_class_b());
|
||||
ASIO_CHECK(!address_v4(0xFFFFFFFF).is_class_b());
|
||||
|
||||
ASIO_CHECK(!address_v4(0x01000000).is_class_c());
|
||||
ASIO_CHECK(!address_v4(0x7F000000).is_class_c());
|
||||
ASIO_CHECK(!address_v4(0x80000000).is_class_c());
|
||||
ASIO_CHECK(!address_v4(0xBFFF0000).is_class_c());
|
||||
ASIO_CHECK(address_v4(0xC0000000).is_class_c());
|
||||
ASIO_CHECK(address_v4(0xDFFFFF00).is_class_c());
|
||||
ASIO_CHECK(!address_v4(0xE0000000).is_class_c());
|
||||
ASIO_CHECK(!address_v4(0xEFFFFFFF).is_class_c());
|
||||
ASIO_CHECK(!address_v4(0xF0000000).is_class_c());
|
||||
ASIO_CHECK(!address_v4(0xFFFFFFFF).is_class_c());
|
||||
#endif // !defined(ASIO_NO_DEPRECATED)
|
||||
|
||||
ASIO_CHECK(!address_v4(0x01000000).is_multicast());
|
||||
ASIO_CHECK(!address_v4(0x7F000000).is_multicast());
|
||||
ASIO_CHECK(!address_v4(0x80000000).is_multicast());
|
||||
ASIO_CHECK(!address_v4(0xBFFF0000).is_multicast());
|
||||
ASIO_CHECK(!address_v4(0xC0000000).is_multicast());
|
||||
ASIO_CHECK(!address_v4(0xDFFFFF00).is_multicast());
|
||||
ASIO_CHECK(address_v4(0xE0000000).is_multicast());
|
||||
ASIO_CHECK(address_v4(0xEFFFFFFF).is_multicast());
|
||||
ASIO_CHECK(!address_v4(0xF0000000).is_multicast());
|
||||
ASIO_CHECK(!address_v4(0xFFFFFFFF).is_multicast());
|
||||
|
||||
address_v4 a4 = address_v4::any();
|
||||
ASIO_CHECK(a4.to_bytes()[0] == 0);
|
||||
ASIO_CHECK(a4.to_bytes()[1] == 0);
|
||||
ASIO_CHECK(a4.to_bytes()[2] == 0);
|
||||
ASIO_CHECK(a4.to_bytes()[3] == 0);
|
||||
ASIO_CHECK(a4.to_uint() == 0);
|
||||
#if !defined(ASIO_NO_DEPRECATED)
|
||||
ASIO_CHECK(a4.to_ulong() == 0);
|
||||
#endif // !defined(ASIO_NO_DEPRECATED)
|
||||
|
||||
address_v4 a5 = address_v4::loopback();
|
||||
ASIO_CHECK(a5.to_bytes()[0] == 0x7F);
|
||||
ASIO_CHECK(a5.to_bytes()[1] == 0);
|
||||
ASIO_CHECK(a5.to_bytes()[2] == 0);
|
||||
ASIO_CHECK(a5.to_bytes()[3] == 0x01);
|
||||
ASIO_CHECK(a5.to_uint() == 0x7F000001);
|
||||
#if !defined(ASIO_NO_DEPRECATED)
|
||||
ASIO_CHECK(a5.to_ulong() == 0x7F000001);
|
||||
#endif // !defined(ASIO_NO_DEPRECATED)
|
||||
|
||||
address_v4 a6 = address_v4::broadcast();
|
||||
ASIO_CHECK(a6.to_bytes()[0] == 0xFF);
|
||||
ASIO_CHECK(a6.to_bytes()[1] == 0xFF);
|
||||
ASIO_CHECK(a6.to_bytes()[2] == 0xFF);
|
||||
ASIO_CHECK(a6.to_bytes()[3] == 0xFF);
|
||||
ASIO_CHECK(a6.to_uint() == 0xFFFFFFFF);
|
||||
#if !defined(ASIO_NO_DEPRECATED)
|
||||
ASIO_CHECK(a6.to_ulong() == 0xFFFFFFFF);
|
||||
#endif // !defined(ASIO_NO_DEPRECATED)
|
||||
|
||||
#if !defined(ASIO_NO_DEPRECATED)
|
||||
address_v4 class_a_net(0xFF000000);
|
||||
address_v4 class_b_net(0xFFFF0000);
|
||||
address_v4 class_c_net(0xFFFFFF00);
|
||||
address_v4 other_net(0xFFFFFFFF);
|
||||
ASIO_CHECK(address_v4::netmask(address_v4(0x01000000)) == class_a_net);
|
||||
ASIO_CHECK(address_v4::netmask(address_v4(0x7F000000)) == class_a_net);
|
||||
ASIO_CHECK(address_v4::netmask(address_v4(0x80000000)) == class_b_net);
|
||||
ASIO_CHECK(address_v4::netmask(address_v4(0xBFFF0000)) == class_b_net);
|
||||
ASIO_CHECK(address_v4::netmask(address_v4(0xC0000000)) == class_c_net);
|
||||
ASIO_CHECK(address_v4::netmask(address_v4(0xDFFFFF00)) == class_c_net);
|
||||
ASIO_CHECK(address_v4::netmask(address_v4(0xE0000000)) == other_net);
|
||||
ASIO_CHECK(address_v4::netmask(address_v4(0xEFFFFFFF)) == other_net);
|
||||
ASIO_CHECK(address_v4::netmask(address_v4(0xF0000000)) == other_net);
|
||||
ASIO_CHECK(address_v4::netmask(address_v4(0xFFFFFFFF)) == other_net);
|
||||
#endif // !defined(ASIO_NO_DEPRECATED)
|
||||
}
|
||||
|
||||
} // namespace ip_address_v4_runtime
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
ASIO_TEST_SUITE
|
||||
(
|
||||
"ip/address_v4",
|
||||
ASIO_TEST_CASE(ip_address_v4_compile::test)
|
||||
ASIO_TEST_CASE(ip_address_v4_runtime::test)
|
||||
)
|
||||
@@ -0,0 +1,27 @@
|
||||
//
|
||||
// address_v4_iterator.cpp
|
||||
// ~~~~~~~~~~~~~~~~~~~~~~~
|
||||
//
|
||||
// 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)
|
||||
//
|
||||
|
||||
// Disable autolinking for unit tests.
|
||||
#if !defined(BOOST_ALL_NO_LIB)
|
||||
#define BOOST_ALL_NO_LIB 1
|
||||
#endif // !defined(BOOST_ALL_NO_LIB)
|
||||
|
||||
// Test that header file is self-contained.
|
||||
#include "asio/ip/address_v4_iterator.hpp"
|
||||
|
||||
#include "../unit_test.hpp"
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
ASIO_TEST_SUITE
|
||||
(
|
||||
"ip/address_v4_iterator",
|
||||
ASIO_TEST_CASE(null_test)
|
||||
)
|
||||
@@ -0,0 +1,27 @@
|
||||
//
|
||||
// address_v4_range.cpp
|
||||
// ~~~~~~~~~~~~~~~~~~~~
|
||||
//
|
||||
// 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)
|
||||
//
|
||||
|
||||
// Disable autolinking for unit tests.
|
||||
#if !defined(BOOST_ALL_NO_LIB)
|
||||
#define BOOST_ALL_NO_LIB 1
|
||||
#endif // !defined(BOOST_ALL_NO_LIB)
|
||||
|
||||
// Test that header file is self-contained.
|
||||
#include "asio/ip/address_v4_range.hpp"
|
||||
|
||||
#include "../unit_test.hpp"
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
ASIO_TEST_SUITE
|
||||
(
|
||||
"ip/address_v4_range",
|
||||
ASIO_TEST_CASE(null_test)
|
||||
)
|
||||
@@ -0,0 +1,409 @@
|
||||
//
|
||||
// address_v6.cpp
|
||||
// ~~~~~~~~~~~~~~
|
||||
//
|
||||
// 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)
|
||||
//
|
||||
|
||||
// Disable autolinking for unit tests.
|
||||
#if !defined(BOOST_ALL_NO_LIB)
|
||||
#define BOOST_ALL_NO_LIB 1
|
||||
#endif // !defined(BOOST_ALL_NO_LIB)
|
||||
|
||||
// Test that header file is self-contained.
|
||||
#include "asio/ip/address_v6.hpp"
|
||||
|
||||
#include "../unit_test.hpp"
|
||||
#include <sstream>
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
// ip_address_v6_compile test
|
||||
// ~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
// The following test checks that all public member functions on the class
|
||||
// ip::address_v6 compile and link correctly. Runtime failures are ignored.
|
||||
|
||||
namespace ip_address_v6_compile {
|
||||
|
||||
void test()
|
||||
{
|
||||
using namespace asio;
|
||||
namespace ip = asio::ip;
|
||||
|
||||
try
|
||||
{
|
||||
asio::error_code ec;
|
||||
|
||||
// address_v6 constructors.
|
||||
|
||||
ip::address_v6 addr1;
|
||||
const ip::address_v6::bytes_type const_bytes_value = { { 0 } };
|
||||
ip::address_v6 addr2(const_bytes_value);
|
||||
|
||||
// address_v6 functions.
|
||||
|
||||
unsigned long scope_id = addr1.scope_id();
|
||||
addr1.scope_id(scope_id);
|
||||
|
||||
bool b = addr1.is_unspecified();
|
||||
(void)b;
|
||||
|
||||
b = addr1.is_loopback();
|
||||
(void)b;
|
||||
|
||||
b = addr1.is_multicast();
|
||||
(void)b;
|
||||
|
||||
b = addr1.is_link_local();
|
||||
(void)b;
|
||||
|
||||
b = addr1.is_site_local();
|
||||
(void)b;
|
||||
|
||||
b = addr1.is_v4_mapped();
|
||||
(void)b;
|
||||
|
||||
#if !defined(ASIO_NO_DEPRECATED)
|
||||
b = addr1.is_v4_compatible();
|
||||
(void)b;
|
||||
#endif // !defined(ASIO_NO_DEPRECATED)
|
||||
|
||||
b = addr1.is_multicast_node_local();
|
||||
(void)b;
|
||||
|
||||
b = addr1.is_multicast_link_local();
|
||||
(void)b;
|
||||
|
||||
b = addr1.is_multicast_site_local();
|
||||
(void)b;
|
||||
|
||||
b = addr1.is_multicast_org_local();
|
||||
(void)b;
|
||||
|
||||
b = addr1.is_multicast_global();
|
||||
(void)b;
|
||||
|
||||
ip::address_v6::bytes_type bytes_value = addr1.to_bytes();
|
||||
(void)bytes_value;
|
||||
|
||||
std::string string_value = addr1.to_string();
|
||||
#if !defined(ASIO_NO_DEPRECATED)
|
||||
string_value = addr1.to_string(ec);
|
||||
#endif // !defined(ASIO_NO_DEPRECATED)
|
||||
|
||||
#if !defined(ASIO_NO_DEPRECATED)
|
||||
ip::address_v4 addr3 = addr1.to_v4();
|
||||
#endif // !defined(ASIO_NO_DEPRECATED)
|
||||
|
||||
// address_v6 static functions.
|
||||
|
||||
#if !defined(ASIO_NO_DEPRECATED)
|
||||
addr1 = ip::address_v6::from_string("0::0");
|
||||
addr1 = ip::address_v6::from_string("0::0", ec);
|
||||
addr1 = ip::address_v6::from_string(string_value);
|
||||
addr1 = ip::address_v6::from_string(string_value, ec);
|
||||
#endif // !defined(ASIO_NO_DEPRECATED)
|
||||
|
||||
addr1 = ip::address_v6::any();
|
||||
|
||||
addr1 = ip::address_v6::loopback();
|
||||
|
||||
#if !defined(ASIO_NO_DEPRECATED)
|
||||
addr1 = ip::address_v6::v4_mapped(addr3);
|
||||
|
||||
addr1 = ip::address_v6::v4_compatible(addr3);
|
||||
#endif // !defined(ASIO_NO_DEPRECATED)
|
||||
|
||||
// address_v6 comparisons.
|
||||
|
||||
b = (addr1 == addr2);
|
||||
(void)b;
|
||||
|
||||
b = (addr1 != addr2);
|
||||
(void)b;
|
||||
|
||||
b = (addr1 < addr2);
|
||||
(void)b;
|
||||
|
||||
b = (addr1 > addr2);
|
||||
(void)b;
|
||||
|
||||
b = (addr1 <= addr2);
|
||||
(void)b;
|
||||
|
||||
b = (addr1 >= addr2);
|
||||
(void)b;
|
||||
|
||||
// address_v6 creation functions.
|
||||
|
||||
addr1 = ip::make_address_v6(const_bytes_value, scope_id);
|
||||
addr1 = ip::make_address_v6("0::0");
|
||||
addr1 = ip::make_address_v6("0::0", ec);
|
||||
addr1 = ip::make_address_v6(string_value);
|
||||
addr1 = ip::make_address_v6(string_value, ec);
|
||||
#if defined(ASIO_HAS_STRING_VIEW)
|
||||
# if defined(ASIO_HAS_STD_STRING_VIEW)
|
||||
std::string_view string_view_value("0::0");
|
||||
# else // defined(ASIO_HAS_STD_EXPERIMENTAL_STRING_VIEW)
|
||||
std::experimental::string_view string_view_value("0::0");
|
||||
# endif // defined(ASIO_HAS_STD_EXPERIMENTAL_STRING_VIEW)
|
||||
addr1 = ip::make_address_v6(string_view_value);
|
||||
addr1 = ip::make_address_v6(string_view_value, ec);
|
||||
#endif // defined(ASIO_HAS_STRING_VIEW)
|
||||
|
||||
// address_v6 IPv4-mapped conversion.
|
||||
#if defined(ASIO_NO_DEPRECATED)
|
||||
ip::address_v4 addr3;
|
||||
#endif // defined(ASIO_NO_DEPRECATED)
|
||||
addr1 = ip::make_address_v6(ip::v4_mapped, addr3);
|
||||
addr3 = ip::make_address_v4(ip::v4_mapped, addr1);
|
||||
|
||||
// address_v6 I/O.
|
||||
|
||||
std::ostringstream os;
|
||||
os << addr1;
|
||||
|
||||
#if !defined(BOOST_NO_STD_WSTREAMBUF)
|
||||
std::wostringstream wos;
|
||||
wos << addr1;
|
||||
#endif // !defined(BOOST_NO_STD_WSTREAMBUF)
|
||||
}
|
||||
catch (std::exception&)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace ip_address_v6_compile
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
// ip_address_v6_runtime test
|
||||
// ~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
// The following test checks that the various public member functions meet the
|
||||
// necessary postconditions.
|
||||
|
||||
namespace ip_address_v6_runtime {
|
||||
|
||||
void test()
|
||||
{
|
||||
using asio::ip::address_v6;
|
||||
|
||||
address_v6 a1;
|
||||
ASIO_CHECK(a1.is_unspecified());
|
||||
ASIO_CHECK(a1.scope_id() == 0);
|
||||
|
||||
address_v6::bytes_type b1 = {{ 1, 2, 3, 4, 5,
|
||||
6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 }};
|
||||
address_v6 a2(b1, 12345);
|
||||
ASIO_CHECK(a2.to_bytes()[0] == 1);
|
||||
ASIO_CHECK(a2.to_bytes()[1] == 2);
|
||||
ASIO_CHECK(a2.to_bytes()[2] == 3);
|
||||
ASIO_CHECK(a2.to_bytes()[3] == 4);
|
||||
ASIO_CHECK(a2.to_bytes()[4] == 5);
|
||||
ASIO_CHECK(a2.to_bytes()[5] == 6);
|
||||
ASIO_CHECK(a2.to_bytes()[6] == 7);
|
||||
ASIO_CHECK(a2.to_bytes()[7] == 8);
|
||||
ASIO_CHECK(a2.to_bytes()[8] == 9);
|
||||
ASIO_CHECK(a2.to_bytes()[9] == 10);
|
||||
ASIO_CHECK(a2.to_bytes()[10] == 11);
|
||||
ASIO_CHECK(a2.to_bytes()[11] == 12);
|
||||
ASIO_CHECK(a2.to_bytes()[12] == 13);
|
||||
ASIO_CHECK(a2.to_bytes()[13] == 14);
|
||||
ASIO_CHECK(a2.to_bytes()[14] == 15);
|
||||
ASIO_CHECK(a2.to_bytes()[15] == 16);
|
||||
ASIO_CHECK(a2.scope_id() == 12345);
|
||||
|
||||
address_v6 a3;
|
||||
a3.scope_id(12345);
|
||||
ASIO_CHECK(a3.scope_id() == 12345);
|
||||
|
||||
address_v6 unspecified_address;
|
||||
address_v6::bytes_type loopback_bytes = {{ 0 }};
|
||||
loopback_bytes[15] = 1;
|
||||
address_v6 loopback_address(loopback_bytes);
|
||||
address_v6::bytes_type link_local_bytes = {{ 0xFE, 0x80, 1 }};
|
||||
address_v6 link_local_address(link_local_bytes);
|
||||
address_v6::bytes_type site_local_bytes = {{ 0xFE, 0xC0, 1 }};
|
||||
address_v6 site_local_address(site_local_bytes);
|
||||
address_v6::bytes_type v4_mapped_bytes = {{ 0 }};
|
||||
v4_mapped_bytes[10] = 0xFF, v4_mapped_bytes[11] = 0xFF;
|
||||
v4_mapped_bytes[12] = 1, v4_mapped_bytes[13] = 2;
|
||||
v4_mapped_bytes[14] = 3, v4_mapped_bytes[15] = 4;
|
||||
address_v6 v4_mapped_address(v4_mapped_bytes);
|
||||
address_v6::bytes_type v4_compat_bytes = {{ 0 }};
|
||||
v4_compat_bytes[12] = 1, v4_compat_bytes[13] = 2;
|
||||
v4_compat_bytes[14] = 3, v4_compat_bytes[15] = 4;
|
||||
address_v6 v4_compat_address(v4_compat_bytes);
|
||||
address_v6::bytes_type mcast_global_bytes = {{ 0xFF, 0x0E, 1 }};
|
||||
address_v6 mcast_global_address(mcast_global_bytes);
|
||||
address_v6::bytes_type mcast_link_local_bytes = {{ 0xFF, 0x02, 1 }};
|
||||
address_v6 mcast_link_local_address(mcast_link_local_bytes);
|
||||
address_v6::bytes_type mcast_node_local_bytes = {{ 0xFF, 0x01, 1 }};
|
||||
address_v6 mcast_node_local_address(mcast_node_local_bytes);
|
||||
address_v6::bytes_type mcast_org_local_bytes = {{ 0xFF, 0x08, 1 }};
|
||||
address_v6 mcast_org_local_address(mcast_org_local_bytes);
|
||||
address_v6::bytes_type mcast_site_local_bytes = {{ 0xFF, 0x05, 1 }};
|
||||
address_v6 mcast_site_local_address(mcast_site_local_bytes);
|
||||
|
||||
ASIO_CHECK(!unspecified_address.is_loopback());
|
||||
ASIO_CHECK(loopback_address.is_loopback());
|
||||
ASIO_CHECK(!link_local_address.is_loopback());
|
||||
ASIO_CHECK(!site_local_address.is_loopback());
|
||||
ASIO_CHECK(!v4_mapped_address.is_loopback());
|
||||
ASIO_CHECK(!v4_compat_address.is_loopback());
|
||||
ASIO_CHECK(!mcast_global_address.is_loopback());
|
||||
ASIO_CHECK(!mcast_link_local_address.is_loopback());
|
||||
ASIO_CHECK(!mcast_node_local_address.is_loopback());
|
||||
ASIO_CHECK(!mcast_org_local_address.is_loopback());
|
||||
ASIO_CHECK(!mcast_site_local_address.is_loopback());
|
||||
|
||||
ASIO_CHECK(unspecified_address.is_unspecified());
|
||||
ASIO_CHECK(!loopback_address.is_unspecified());
|
||||
ASIO_CHECK(!link_local_address.is_unspecified());
|
||||
ASIO_CHECK(!site_local_address.is_unspecified());
|
||||
ASIO_CHECK(!v4_mapped_address.is_unspecified());
|
||||
ASIO_CHECK(!v4_compat_address.is_unspecified());
|
||||
ASIO_CHECK(!mcast_global_address.is_unspecified());
|
||||
ASIO_CHECK(!mcast_link_local_address.is_unspecified());
|
||||
ASIO_CHECK(!mcast_node_local_address.is_unspecified());
|
||||
ASIO_CHECK(!mcast_org_local_address.is_unspecified());
|
||||
ASIO_CHECK(!mcast_site_local_address.is_unspecified());
|
||||
|
||||
ASIO_CHECK(!unspecified_address.is_link_local());
|
||||
ASIO_CHECK(!loopback_address.is_link_local());
|
||||
ASIO_CHECK(link_local_address.is_link_local());
|
||||
ASIO_CHECK(!site_local_address.is_link_local());
|
||||
ASIO_CHECK(!v4_mapped_address.is_link_local());
|
||||
ASIO_CHECK(!v4_compat_address.is_link_local());
|
||||
ASIO_CHECK(!mcast_global_address.is_link_local());
|
||||
ASIO_CHECK(!mcast_link_local_address.is_link_local());
|
||||
ASIO_CHECK(!mcast_node_local_address.is_link_local());
|
||||
ASIO_CHECK(!mcast_org_local_address.is_link_local());
|
||||
ASIO_CHECK(!mcast_site_local_address.is_link_local());
|
||||
|
||||
ASIO_CHECK(!unspecified_address.is_site_local());
|
||||
ASIO_CHECK(!loopback_address.is_site_local());
|
||||
ASIO_CHECK(!link_local_address.is_site_local());
|
||||
ASIO_CHECK(site_local_address.is_site_local());
|
||||
ASIO_CHECK(!v4_mapped_address.is_site_local());
|
||||
ASIO_CHECK(!v4_compat_address.is_site_local());
|
||||
ASIO_CHECK(!mcast_global_address.is_site_local());
|
||||
ASIO_CHECK(!mcast_link_local_address.is_site_local());
|
||||
ASIO_CHECK(!mcast_node_local_address.is_site_local());
|
||||
ASIO_CHECK(!mcast_org_local_address.is_site_local());
|
||||
ASIO_CHECK(!mcast_site_local_address.is_site_local());
|
||||
|
||||
ASIO_CHECK(!unspecified_address.is_v4_mapped());
|
||||
ASIO_CHECK(!loopback_address.is_v4_mapped());
|
||||
ASIO_CHECK(!link_local_address.is_v4_mapped());
|
||||
ASIO_CHECK(!site_local_address.is_v4_mapped());
|
||||
ASIO_CHECK(v4_mapped_address.is_v4_mapped());
|
||||
ASIO_CHECK(!v4_compat_address.is_v4_mapped());
|
||||
ASIO_CHECK(!mcast_global_address.is_v4_mapped());
|
||||
ASIO_CHECK(!mcast_link_local_address.is_v4_mapped());
|
||||
ASIO_CHECK(!mcast_node_local_address.is_v4_mapped());
|
||||
ASIO_CHECK(!mcast_org_local_address.is_v4_mapped());
|
||||
ASIO_CHECK(!mcast_site_local_address.is_v4_mapped());
|
||||
|
||||
#if !defined(ASIO_NO_DEPRECATED)
|
||||
ASIO_CHECK(!unspecified_address.is_v4_compatible());
|
||||
ASIO_CHECK(!loopback_address.is_v4_compatible());
|
||||
ASIO_CHECK(!link_local_address.is_v4_compatible());
|
||||
ASIO_CHECK(!site_local_address.is_v4_compatible());
|
||||
ASIO_CHECK(!v4_mapped_address.is_v4_compatible());
|
||||
ASIO_CHECK(v4_compat_address.is_v4_compatible());
|
||||
ASIO_CHECK(!mcast_global_address.is_v4_compatible());
|
||||
ASIO_CHECK(!mcast_link_local_address.is_v4_compatible());
|
||||
ASIO_CHECK(!mcast_node_local_address.is_v4_compatible());
|
||||
ASIO_CHECK(!mcast_org_local_address.is_v4_compatible());
|
||||
ASIO_CHECK(!mcast_site_local_address.is_v4_compatible());
|
||||
#endif // !defined(ASIO_NO_DEPRECATED)
|
||||
|
||||
ASIO_CHECK(!unspecified_address.is_multicast());
|
||||
ASIO_CHECK(!loopback_address.is_multicast());
|
||||
ASIO_CHECK(!link_local_address.is_multicast());
|
||||
ASIO_CHECK(!site_local_address.is_multicast());
|
||||
ASIO_CHECK(!v4_mapped_address.is_multicast());
|
||||
ASIO_CHECK(!v4_compat_address.is_multicast());
|
||||
ASIO_CHECK(mcast_global_address.is_multicast());
|
||||
ASIO_CHECK(mcast_link_local_address.is_multicast());
|
||||
ASIO_CHECK(mcast_node_local_address.is_multicast());
|
||||
ASIO_CHECK(mcast_org_local_address.is_multicast());
|
||||
ASIO_CHECK(mcast_site_local_address.is_multicast());
|
||||
|
||||
ASIO_CHECK(!unspecified_address.is_multicast_global());
|
||||
ASIO_CHECK(!loopback_address.is_multicast_global());
|
||||
ASIO_CHECK(!link_local_address.is_multicast_global());
|
||||
ASIO_CHECK(!site_local_address.is_multicast_global());
|
||||
ASIO_CHECK(!v4_mapped_address.is_multicast_global());
|
||||
ASIO_CHECK(!v4_compat_address.is_multicast_global());
|
||||
ASIO_CHECK(mcast_global_address.is_multicast_global());
|
||||
ASIO_CHECK(!mcast_link_local_address.is_multicast_global());
|
||||
ASIO_CHECK(!mcast_node_local_address.is_multicast_global());
|
||||
ASIO_CHECK(!mcast_org_local_address.is_multicast_global());
|
||||
ASIO_CHECK(!mcast_site_local_address.is_multicast_global());
|
||||
|
||||
ASIO_CHECK(!unspecified_address.is_multicast_link_local());
|
||||
ASIO_CHECK(!loopback_address.is_multicast_link_local());
|
||||
ASIO_CHECK(!link_local_address.is_multicast_link_local());
|
||||
ASIO_CHECK(!site_local_address.is_multicast_link_local());
|
||||
ASIO_CHECK(!v4_mapped_address.is_multicast_link_local());
|
||||
ASIO_CHECK(!v4_compat_address.is_multicast_link_local());
|
||||
ASIO_CHECK(!mcast_global_address.is_multicast_link_local());
|
||||
ASIO_CHECK(mcast_link_local_address.is_multicast_link_local());
|
||||
ASIO_CHECK(!mcast_node_local_address.is_multicast_link_local());
|
||||
ASIO_CHECK(!mcast_org_local_address.is_multicast_link_local());
|
||||
ASIO_CHECK(!mcast_site_local_address.is_multicast_link_local());
|
||||
|
||||
ASIO_CHECK(!unspecified_address.is_multicast_node_local());
|
||||
ASIO_CHECK(!loopback_address.is_multicast_node_local());
|
||||
ASIO_CHECK(!link_local_address.is_multicast_node_local());
|
||||
ASIO_CHECK(!site_local_address.is_multicast_node_local());
|
||||
ASIO_CHECK(!v4_mapped_address.is_multicast_node_local());
|
||||
ASIO_CHECK(!v4_compat_address.is_multicast_node_local());
|
||||
ASIO_CHECK(!mcast_global_address.is_multicast_node_local());
|
||||
ASIO_CHECK(!mcast_link_local_address.is_multicast_node_local());
|
||||
ASIO_CHECK(mcast_node_local_address.is_multicast_node_local());
|
||||
ASIO_CHECK(!mcast_org_local_address.is_multicast_node_local());
|
||||
ASIO_CHECK(!mcast_site_local_address.is_multicast_node_local());
|
||||
|
||||
ASIO_CHECK(!unspecified_address.is_multicast_org_local());
|
||||
ASIO_CHECK(!loopback_address.is_multicast_org_local());
|
||||
ASIO_CHECK(!link_local_address.is_multicast_org_local());
|
||||
ASIO_CHECK(!site_local_address.is_multicast_org_local());
|
||||
ASIO_CHECK(!v4_mapped_address.is_multicast_org_local());
|
||||
ASIO_CHECK(!v4_compat_address.is_multicast_org_local());
|
||||
ASIO_CHECK(!mcast_global_address.is_multicast_org_local());
|
||||
ASIO_CHECK(!mcast_link_local_address.is_multicast_org_local());
|
||||
ASIO_CHECK(!mcast_node_local_address.is_multicast_org_local());
|
||||
ASIO_CHECK(mcast_org_local_address.is_multicast_org_local());
|
||||
ASIO_CHECK(!mcast_site_local_address.is_multicast_org_local());
|
||||
|
||||
ASIO_CHECK(!unspecified_address.is_multicast_site_local());
|
||||
ASIO_CHECK(!loopback_address.is_multicast_site_local());
|
||||
ASIO_CHECK(!link_local_address.is_multicast_site_local());
|
||||
ASIO_CHECK(!site_local_address.is_multicast_site_local());
|
||||
ASIO_CHECK(!v4_mapped_address.is_multicast_site_local());
|
||||
ASIO_CHECK(!v4_compat_address.is_multicast_site_local());
|
||||
ASIO_CHECK(!mcast_global_address.is_multicast_site_local());
|
||||
ASIO_CHECK(!mcast_link_local_address.is_multicast_site_local());
|
||||
ASIO_CHECK(!mcast_node_local_address.is_multicast_site_local());
|
||||
ASIO_CHECK(!mcast_org_local_address.is_multicast_site_local());
|
||||
ASIO_CHECK(mcast_site_local_address.is_multicast_site_local());
|
||||
|
||||
ASIO_CHECK(address_v6::loopback().is_loopback());
|
||||
}
|
||||
|
||||
} // namespace ip_address_v6_runtime
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
ASIO_TEST_SUITE
|
||||
(
|
||||
"ip/address_v6",
|
||||
ASIO_TEST_CASE(ip_address_v6_compile::test)
|
||||
ASIO_TEST_CASE(ip_address_v6_runtime::test)
|
||||
)
|
||||
@@ -0,0 +1,27 @@
|
||||
//
|
||||
// address_v6_iterator.cpp
|
||||
// ~~~~~~~~~~~~~~~~~~~~~~~
|
||||
//
|
||||
// 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)
|
||||
//
|
||||
|
||||
// Disable autolinking for unit tests.
|
||||
#if !defined(BOOST_ALL_NO_LIB)
|
||||
#define BOOST_ALL_NO_LIB 1
|
||||
#endif // !defined(BOOST_ALL_NO_LIB)
|
||||
|
||||
// Test that header file is self-contained.
|
||||
#include "asio/ip/address_v6_iterator.hpp"
|
||||
|
||||
#include "../unit_test.hpp"
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
ASIO_TEST_SUITE
|
||||
(
|
||||
"ip/address_v6_iterator",
|
||||
ASIO_TEST_CASE(null_test)
|
||||
)
|
||||
@@ -0,0 +1,27 @@
|
||||
//
|
||||
// address_v6_range.cpp
|
||||
// ~~~~~~~~~~~~~~~~~~~~
|
||||
//
|
||||
// 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)
|
||||
//
|
||||
|
||||
// Disable autolinking for unit tests.
|
||||
#if !defined(BOOST_ALL_NO_LIB)
|
||||
#define BOOST_ALL_NO_LIB 1
|
||||
#endif // !defined(BOOST_ALL_NO_LIB)
|
||||
|
||||
// Test that header file is self-contained.
|
||||
#include "asio/ip/address_v6_range.hpp"
|
||||
|
||||
#include "../unit_test.hpp"
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
ASIO_TEST_SUITE
|
||||
(
|
||||
"ip/address_v6_range",
|
||||
ASIO_TEST_CASE(null_test)
|
||||
)
|
||||
@@ -0,0 +1,25 @@
|
||||
//
|
||||
// basic_endpoint.cpp
|
||||
// ~~~~~~~~~~~~~~~~~~
|
||||
//
|
||||
// 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)
|
||||
//
|
||||
|
||||
// Disable autolinking for unit tests.
|
||||
#if !defined(BOOST_ALL_NO_LIB)
|
||||
#define BOOST_ALL_NO_LIB 1
|
||||
#endif // !defined(BOOST_ALL_NO_LIB)
|
||||
|
||||
// Test that header file is self-contained.
|
||||
#include "asio/ip/basic_endpoint.hpp"
|
||||
|
||||
#include "../unit_test.hpp"
|
||||
|
||||
ASIO_TEST_SUITE
|
||||
(
|
||||
"ip/basic_endpoint",
|
||||
ASIO_TEST_CASE(null_test)
|
||||
)
|
||||
@@ -0,0 +1,25 @@
|
||||
//
|
||||
// basic_resolver.cpp
|
||||
// ~~~~~~~~~~~~~~~~~~
|
||||
//
|
||||
// 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)
|
||||
//
|
||||
|
||||
// Disable autolinking for unit tests.
|
||||
#if !defined(BOOST_ALL_NO_LIB)
|
||||
#define BOOST_ALL_NO_LIB 1
|
||||
#endif // !defined(BOOST_ALL_NO_LIB)
|
||||
|
||||
// Test that header file is self-contained.
|
||||
#include "asio/ip/basic_resolver.hpp"
|
||||
|
||||
#include "../unit_test.hpp"
|
||||
|
||||
ASIO_TEST_SUITE
|
||||
(
|
||||
"ip/basic_resolver",
|
||||
ASIO_TEST_CASE(null_test)
|
||||
)
|
||||
@@ -0,0 +1,25 @@
|
||||
//
|
||||
// basic_resolver_entry.cpp
|
||||
// ~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
//
|
||||
// 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)
|
||||
//
|
||||
|
||||
// Disable autolinking for unit tests.
|
||||
#if !defined(BOOST_ALL_NO_LIB)
|
||||
#define BOOST_ALL_NO_LIB 1
|
||||
#endif // !defined(BOOST_ALL_NO_LIB)
|
||||
|
||||
// Test that header file is self-contained.
|
||||
#include "asio/ip/basic_resolver_entry.hpp"
|
||||
|
||||
#include "../unit_test.hpp"
|
||||
|
||||
ASIO_TEST_SUITE
|
||||
(
|
||||
"ip/basic_resolver_entry",
|
||||
ASIO_TEST_CASE(null_test)
|
||||
)
|
||||
@@ -0,0 +1,25 @@
|
||||
//
|
||||
// basic_resolver_iterator.cpp
|
||||
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
//
|
||||
// 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)
|
||||
//
|
||||
|
||||
// Disable autolinking for unit tests.
|
||||
#if !defined(BOOST_ALL_NO_LIB)
|
||||
#define BOOST_ALL_NO_LIB 1
|
||||
#endif // !defined(BOOST_ALL_NO_LIB)
|
||||
|
||||
// Test that header file is self-contained.
|
||||
#include "asio/ip/basic_resolver_iterator.hpp"
|
||||
|
||||
#include "../unit_test.hpp"
|
||||
|
||||
ASIO_TEST_SUITE
|
||||
(
|
||||
"ip/basic_resolver_iterator",
|
||||
ASIO_TEST_CASE(null_test)
|
||||
)
|
||||
@@ -0,0 +1,25 @@
|
||||
//
|
||||
// basic_resolver_query.cpp
|
||||
// ~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
//
|
||||
// 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)
|
||||
//
|
||||
|
||||
// Disable autolinking for unit tests.
|
||||
#if !defined(BOOST_ALL_NO_LIB)
|
||||
#define BOOST_ALL_NO_LIB 1
|
||||
#endif // !defined(BOOST_ALL_NO_LIB)
|
||||
|
||||
// Test that header file is self-contained.
|
||||
#include "asio/ip/basic_resolver_query.hpp"
|
||||
|
||||
#include "../unit_test.hpp"
|
||||
|
||||
ASIO_TEST_SUITE
|
||||
(
|
||||
"ip/basic_resolver_query",
|
||||
ASIO_TEST_CASE(null_test)
|
||||
)
|
||||
@@ -0,0 +1,55 @@
|
||||
//
|
||||
// host_name.cpp
|
||||
// ~~~~~~~~~~~~~
|
||||
//
|
||||
// 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)
|
||||
//
|
||||
|
||||
// Disable autolinking for unit tests.
|
||||
#if !defined(BOOST_ALL_NO_LIB)
|
||||
#define BOOST_ALL_NO_LIB 1
|
||||
#endif // !defined(BOOST_ALL_NO_LIB)
|
||||
|
||||
// Test that header file is self-contained.
|
||||
#include "asio/ip/host_name.hpp"
|
||||
|
||||
#include "../unit_test.hpp"
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
// ip_host_name_compile test
|
||||
// ~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
// The following test checks that all host_name functions compile and link
|
||||
// correctly. Runtime failures are ignored.
|
||||
|
||||
namespace ip_host_name_compile {
|
||||
|
||||
void test()
|
||||
{
|
||||
using namespace asio;
|
||||
namespace ip = asio::ip;
|
||||
|
||||
try
|
||||
{
|
||||
asio::error_code ec;
|
||||
|
||||
std::string host_name = ip::host_name();
|
||||
std::string host_name2 = ip::host_name(ec);
|
||||
}
|
||||
catch (std::exception&)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace ip_host_name_compile
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
ASIO_TEST_SUITE
|
||||
(
|
||||
"ip/host_name",
|
||||
ASIO_TEST_CASE(ip_host_name_compile::test)
|
||||
)
|
||||
@@ -0,0 +1,577 @@
|
||||
//
|
||||
// icmp.cpp
|
||||
// ~~~~~~~~
|
||||
//
|
||||
// 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)
|
||||
//
|
||||
|
||||
// Disable autolinking for unit tests.
|
||||
#if !defined(BOOST_ALL_NO_LIB)
|
||||
#define BOOST_ALL_NO_LIB 1
|
||||
#endif // !defined(BOOST_ALL_NO_LIB)
|
||||
|
||||
// Test that header file is self-contained.
|
||||
#include "asio/ip/icmp.hpp"
|
||||
|
||||
#include <cstring>
|
||||
#include "asio/io_context.hpp"
|
||||
#include "asio/placeholders.hpp"
|
||||
#include "../unit_test.hpp"
|
||||
#include "../archetypes/async_result.hpp"
|
||||
#include "../archetypes/gettable_socket_option.hpp"
|
||||
#include "../archetypes/io_control_command.hpp"
|
||||
#include "../archetypes/settable_socket_option.hpp"
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
// ip_icmp_socket_compile test
|
||||
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
// The following test checks that all public member functions on the class
|
||||
// ip::icmp::socket compile and link correctly. Runtime failures are ignored.
|
||||
|
||||
namespace ip_icmp_socket_compile {
|
||||
|
||||
struct connect_handler
|
||||
{
|
||||
connect_handler() {}
|
||||
void operator()(const asio::error_code&) {}
|
||||
#if defined(ASIO_HAS_MOVE)
|
||||
connect_handler(connect_handler&&) {}
|
||||
private:
|
||||
connect_handler(const connect_handler&);
|
||||
#endif // defined(ASIO_HAS_MOVE)
|
||||
};
|
||||
|
||||
struct send_handler
|
||||
{
|
||||
send_handler() {}
|
||||
void operator()(const asio::error_code&, std::size_t) {}
|
||||
#if defined(ASIO_HAS_MOVE)
|
||||
send_handler(send_handler&&) {}
|
||||
private:
|
||||
send_handler(const send_handler&);
|
||||
#endif // defined(ASIO_HAS_MOVE)
|
||||
};
|
||||
|
||||
struct receive_handler
|
||||
{
|
||||
receive_handler() {}
|
||||
void operator()(const asio::error_code&, std::size_t) {}
|
||||
#if defined(ASIO_HAS_MOVE)
|
||||
receive_handler(receive_handler&&) {}
|
||||
private:
|
||||
receive_handler(const receive_handler&);
|
||||
#endif // defined(ASIO_HAS_MOVE)
|
||||
};
|
||||
|
||||
void test()
|
||||
{
|
||||
using namespace asio;
|
||||
namespace ip = asio::ip;
|
||||
|
||||
try
|
||||
{
|
||||
io_context ioc;
|
||||
const io_context::executor_type ioc_ex = ioc.get_executor();
|
||||
char mutable_char_buffer[128] = "";
|
||||
const char const_char_buffer[128] = "";
|
||||
socket_base::message_flags in_flags = 0;
|
||||
archetypes::settable_socket_option<void> settable_socket_option1;
|
||||
archetypes::settable_socket_option<int> settable_socket_option2;
|
||||
archetypes::settable_socket_option<double> settable_socket_option3;
|
||||
archetypes::gettable_socket_option<void> gettable_socket_option1;
|
||||
archetypes::gettable_socket_option<int> gettable_socket_option2;
|
||||
archetypes::gettable_socket_option<double> gettable_socket_option3;
|
||||
archetypes::io_control_command io_control_command;
|
||||
archetypes::lazy_handler lazy;
|
||||
asio::error_code ec;
|
||||
|
||||
// basic_datagram_socket constructors.
|
||||
|
||||
ip::icmp::socket socket1(ioc);
|
||||
ip::icmp::socket socket2(ioc, ip::icmp::v4());
|
||||
ip::icmp::socket socket3(ioc, ip::icmp::v6());
|
||||
ip::icmp::socket socket4(ioc, ip::icmp::endpoint(ip::icmp::v4(), 0));
|
||||
ip::icmp::socket socket5(ioc, ip::icmp::endpoint(ip::icmp::v6(), 0));
|
||||
#if !defined(ASIO_WINDOWS_RUNTIME)
|
||||
ip::icmp::socket::native_handle_type native_socket1
|
||||
= ::socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
|
||||
ip::icmp::socket socket6(ioc, ip::icmp::v4(), native_socket1);
|
||||
#endif // !defined(ASIO_WINDOWS_RUNTIME)
|
||||
|
||||
ip::icmp::socket socket7(ioc_ex);
|
||||
ip::icmp::socket socket8(ioc_ex, ip::icmp::v4());
|
||||
ip::icmp::socket socket9(ioc_ex, ip::icmp::v6());
|
||||
ip::icmp::socket socket10(ioc_ex, ip::icmp::endpoint(ip::icmp::v4(), 0));
|
||||
ip::icmp::socket socket11(ioc_ex, ip::icmp::endpoint(ip::icmp::v6(), 0));
|
||||
#if !defined(ASIO_WINDOWS_RUNTIME)
|
||||
ip::icmp::socket::native_handle_type native_socket2
|
||||
= ::socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
|
||||
ip::icmp::socket socket12(ioc_ex, ip::icmp::v4(), native_socket2);
|
||||
#endif // !defined(ASIO_WINDOWS_RUNTIME)
|
||||
|
||||
#if defined(ASIO_HAS_MOVE)
|
||||
ip::icmp::socket socket13(std::move(socket6));
|
||||
#endif // defined(ASIO_HAS_MOVE)
|
||||
|
||||
// basic_datagram_socket operators.
|
||||
|
||||
#if defined(ASIO_HAS_MOVE)
|
||||
socket1 = ip::icmp::socket(ioc);
|
||||
socket1 = std::move(socket2);
|
||||
#endif // defined(ASIO_HAS_MOVE)
|
||||
|
||||
// basic_io_object functions.
|
||||
|
||||
ip::icmp::socket::executor_type ex = socket1.get_executor();
|
||||
(void)ex;
|
||||
|
||||
// basic_socket functions.
|
||||
|
||||
ip::icmp::socket::lowest_layer_type& lowest_layer = socket1.lowest_layer();
|
||||
(void)lowest_layer;
|
||||
|
||||
const ip::icmp::socket& socket14 = socket1;
|
||||
const ip::icmp::socket::lowest_layer_type& lowest_layer2
|
||||
= socket14.lowest_layer();
|
||||
(void)lowest_layer2;
|
||||
|
||||
socket1.open(ip::icmp::v4());
|
||||
socket1.open(ip::icmp::v6());
|
||||
socket1.open(ip::icmp::v4(), ec);
|
||||
socket1.open(ip::icmp::v6(), ec);
|
||||
|
||||
#if !defined(ASIO_WINDOWS_RUNTIME)
|
||||
ip::icmp::socket::native_handle_type native_socket3
|
||||
= ::socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
|
||||
socket1.assign(ip::icmp::v4(), native_socket3);
|
||||
ip::icmp::socket::native_handle_type native_socket4
|
||||
= ::socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
|
||||
socket1.assign(ip::icmp::v4(), native_socket4, ec);
|
||||
#endif // !defined(ASIO_WINDOWS_RUNTIME)
|
||||
|
||||
bool is_open = socket1.is_open();
|
||||
(void)is_open;
|
||||
|
||||
socket1.close();
|
||||
socket1.close(ec);
|
||||
|
||||
socket1.release();
|
||||
socket1.release(ec);
|
||||
|
||||
ip::icmp::socket::native_handle_type native_socket5
|
||||
= socket1.native_handle();
|
||||
(void)native_socket5;
|
||||
|
||||
socket1.cancel();
|
||||
socket1.cancel(ec);
|
||||
|
||||
bool at_mark1 = socket1.at_mark();
|
||||
(void)at_mark1;
|
||||
bool at_mark2 = socket1.at_mark(ec);
|
||||
(void)at_mark2;
|
||||
|
||||
std::size_t available1 = socket1.available();
|
||||
(void)available1;
|
||||
std::size_t available2 = socket1.available(ec);
|
||||
(void)available2;
|
||||
|
||||
socket1.bind(ip::icmp::endpoint(ip::icmp::v4(), 0));
|
||||
socket1.bind(ip::icmp::endpoint(ip::icmp::v6(), 0));
|
||||
socket1.bind(ip::icmp::endpoint(ip::icmp::v4(), 0), ec);
|
||||
socket1.bind(ip::icmp::endpoint(ip::icmp::v6(), 0), ec);
|
||||
|
||||
socket1.connect(ip::icmp::endpoint(ip::icmp::v4(), 0));
|
||||
socket1.connect(ip::icmp::endpoint(ip::icmp::v6(), 0));
|
||||
socket1.connect(ip::icmp::endpoint(ip::icmp::v4(), 0), ec);
|
||||
socket1.connect(ip::icmp::endpoint(ip::icmp::v6(), 0), ec);
|
||||
|
||||
socket1.async_connect(ip::icmp::endpoint(ip::icmp::v4(), 0),
|
||||
connect_handler());
|
||||
socket1.async_connect(ip::icmp::endpoint(ip::icmp::v6(), 0),
|
||||
connect_handler());
|
||||
int i1 = socket1.async_connect(ip::icmp::endpoint(ip::icmp::v4(), 0), lazy);
|
||||
(void)i1;
|
||||
int i2 = socket1.async_connect(ip::icmp::endpoint(ip::icmp::v6(), 0), lazy);
|
||||
(void)i2;
|
||||
|
||||
socket1.set_option(settable_socket_option1);
|
||||
socket1.set_option(settable_socket_option1, ec);
|
||||
socket1.set_option(settable_socket_option2);
|
||||
socket1.set_option(settable_socket_option2, ec);
|
||||
socket1.set_option(settable_socket_option3);
|
||||
socket1.set_option(settable_socket_option3, ec);
|
||||
|
||||
socket1.get_option(gettable_socket_option1);
|
||||
socket1.get_option(gettable_socket_option1, ec);
|
||||
socket1.get_option(gettable_socket_option2);
|
||||
socket1.get_option(gettable_socket_option2, ec);
|
||||
socket1.get_option(gettable_socket_option3);
|
||||
socket1.get_option(gettable_socket_option3, ec);
|
||||
|
||||
socket1.io_control(io_control_command);
|
||||
socket1.io_control(io_control_command, ec);
|
||||
|
||||
bool non_blocking1 = socket1.non_blocking();
|
||||
(void)non_blocking1;
|
||||
socket1.non_blocking(true);
|
||||
socket1.non_blocking(false, ec);
|
||||
|
||||
bool non_blocking2 = socket1.native_non_blocking();
|
||||
(void)non_blocking2;
|
||||
socket1.native_non_blocking(true);
|
||||
socket1.native_non_blocking(false, ec);
|
||||
|
||||
ip::icmp::endpoint endpoint1 = socket1.local_endpoint();
|
||||
(void)endpoint1;
|
||||
ip::icmp::endpoint endpoint2 = socket1.local_endpoint(ec);
|
||||
(void)endpoint2;
|
||||
|
||||
ip::icmp::endpoint endpoint3 = socket1.remote_endpoint();
|
||||
(void)endpoint3;
|
||||
ip::icmp::endpoint endpoint4 = socket1.remote_endpoint(ec);
|
||||
(void)endpoint4;
|
||||
|
||||
socket1.shutdown(socket_base::shutdown_both);
|
||||
socket1.shutdown(socket_base::shutdown_both, ec);
|
||||
|
||||
// basic_datagram_socket functions.
|
||||
|
||||
socket1.send(buffer(mutable_char_buffer));
|
||||
socket1.send(buffer(const_char_buffer));
|
||||
socket1.send(null_buffers());
|
||||
socket1.send(buffer(mutable_char_buffer), in_flags);
|
||||
socket1.send(buffer(const_char_buffer), in_flags);
|
||||
socket1.send(null_buffers(), in_flags);
|
||||
socket1.send(buffer(mutable_char_buffer), in_flags, ec);
|
||||
socket1.send(buffer(const_char_buffer), in_flags, ec);
|
||||
socket1.send(null_buffers(), in_flags, ec);
|
||||
|
||||
socket1.async_send(buffer(mutable_char_buffer), send_handler());
|
||||
socket1.async_send(buffer(const_char_buffer), send_handler());
|
||||
socket1.async_send(null_buffers(), send_handler());
|
||||
socket1.async_send(buffer(mutable_char_buffer), in_flags, send_handler());
|
||||
socket1.async_send(buffer(const_char_buffer), in_flags, send_handler());
|
||||
socket1.async_send(null_buffers(), in_flags, send_handler());
|
||||
int i3 = socket1.async_send(buffer(mutable_char_buffer), lazy);
|
||||
(void)i3;
|
||||
int i4 = socket1.async_send(buffer(const_char_buffer), lazy);
|
||||
(void)i4;
|
||||
int i5 = socket1.async_send(null_buffers(), lazy);
|
||||
(void)i5;
|
||||
int i6 = socket1.async_send(buffer(mutable_char_buffer), in_flags, lazy);
|
||||
(void)i6;
|
||||
int i7 = socket1.async_send(buffer(const_char_buffer), in_flags, lazy);
|
||||
(void)i7;
|
||||
int i8 = socket1.async_send(null_buffers(), in_flags, lazy);
|
||||
(void)i8;
|
||||
|
||||
socket1.send_to(buffer(mutable_char_buffer),
|
||||
ip::icmp::endpoint(ip::icmp::v4(), 0));
|
||||
socket1.send_to(buffer(mutable_char_buffer),
|
||||
ip::icmp::endpoint(ip::icmp::v6(), 0));
|
||||
socket1.send_to(buffer(const_char_buffer),
|
||||
ip::icmp::endpoint(ip::icmp::v4(), 0));
|
||||
socket1.send_to(buffer(const_char_buffer),
|
||||
ip::icmp::endpoint(ip::icmp::v6(), 0));
|
||||
socket1.send_to(null_buffers(),
|
||||
ip::icmp::endpoint(ip::icmp::v4(), 0));
|
||||
socket1.send_to(null_buffers(),
|
||||
ip::icmp::endpoint(ip::icmp::v6(), 0));
|
||||
socket1.send_to(buffer(mutable_char_buffer),
|
||||
ip::icmp::endpoint(ip::icmp::v4(), 0), in_flags);
|
||||
socket1.send_to(buffer(mutable_char_buffer),
|
||||
ip::icmp::endpoint(ip::icmp::v6(), 0), in_flags);
|
||||
socket1.send_to(buffer(const_char_buffer),
|
||||
ip::icmp::endpoint(ip::icmp::v4(), 0), in_flags);
|
||||
socket1.send_to(buffer(const_char_buffer),
|
||||
ip::icmp::endpoint(ip::icmp::v6(), 0), in_flags);
|
||||
socket1.send_to(null_buffers(),
|
||||
ip::icmp::endpoint(ip::icmp::v4(), 0), in_flags);
|
||||
socket1.send_to(null_buffers(),
|
||||
ip::icmp::endpoint(ip::icmp::v6(), 0), in_flags);
|
||||
socket1.send_to(buffer(mutable_char_buffer),
|
||||
ip::icmp::endpoint(ip::icmp::v4(), 0), in_flags, ec);
|
||||
socket1.send_to(buffer(mutable_char_buffer),
|
||||
ip::icmp::endpoint(ip::icmp::v6(), 0), in_flags, ec);
|
||||
socket1.send_to(buffer(const_char_buffer),
|
||||
ip::icmp::endpoint(ip::icmp::v4(), 0), in_flags, ec);
|
||||
socket1.send_to(buffer(const_char_buffer),
|
||||
ip::icmp::endpoint(ip::icmp::v6(), 0), in_flags, ec);
|
||||
socket1.send_to(null_buffers(),
|
||||
ip::icmp::endpoint(ip::icmp::v4(), 0), in_flags, ec);
|
||||
socket1.send_to(null_buffers(),
|
||||
ip::icmp::endpoint(ip::icmp::v6(), 0), in_flags, ec);
|
||||
|
||||
socket1.async_send_to(buffer(mutable_char_buffer),
|
||||
ip::icmp::endpoint(ip::icmp::v4(), 0), send_handler());
|
||||
socket1.async_send_to(buffer(mutable_char_buffer),
|
||||
ip::icmp::endpoint(ip::icmp::v6(), 0), send_handler());
|
||||
socket1.async_send_to(buffer(const_char_buffer),
|
||||
ip::icmp::endpoint(ip::icmp::v4(), 0), send_handler());
|
||||
socket1.async_send_to(buffer(const_char_buffer),
|
||||
ip::icmp::endpoint(ip::icmp::v6(), 0), send_handler());
|
||||
socket1.async_send_to(null_buffers(),
|
||||
ip::icmp::endpoint(ip::icmp::v4(), 0), send_handler());
|
||||
socket1.async_send_to(null_buffers(),
|
||||
ip::icmp::endpoint(ip::icmp::v6(), 0), send_handler());
|
||||
socket1.async_send_to(buffer(mutable_char_buffer),
|
||||
ip::icmp::endpoint(ip::icmp::v4(), 0), in_flags, send_handler());
|
||||
socket1.async_send_to(buffer(mutable_char_buffer),
|
||||
ip::icmp::endpoint(ip::icmp::v6(), 0), in_flags, send_handler());
|
||||
socket1.async_send_to(buffer(const_char_buffer),
|
||||
ip::icmp::endpoint(ip::icmp::v4(), 0), in_flags, send_handler());
|
||||
socket1.async_send_to(buffer(const_char_buffer),
|
||||
ip::icmp::endpoint(ip::icmp::v6(), 0), in_flags, send_handler());
|
||||
socket1.async_send_to(null_buffers(),
|
||||
ip::icmp::endpoint(ip::icmp::v4(), 0), in_flags, send_handler());
|
||||
socket1.async_send_to(null_buffers(),
|
||||
ip::icmp::endpoint(ip::icmp::v6(), 0), in_flags, send_handler());
|
||||
int i9 = socket1.async_send_to(buffer(mutable_char_buffer),
|
||||
ip::icmp::endpoint(ip::icmp::v4(), 0), lazy);
|
||||
(void)i9;
|
||||
int i10 = socket1.async_send_to(buffer(mutable_char_buffer),
|
||||
ip::icmp::endpoint(ip::icmp::v6(), 0), lazy);
|
||||
(void)i10;
|
||||
int i11 = socket1.async_send_to(buffer(const_char_buffer),
|
||||
ip::icmp::endpoint(ip::icmp::v4(), 0), lazy);
|
||||
(void)i11;
|
||||
int i12 = socket1.async_send_to(buffer(const_char_buffer),
|
||||
ip::icmp::endpoint(ip::icmp::v6(), 0), lazy);
|
||||
(void)i12;
|
||||
int i13 = socket1.async_send_to(null_buffers(),
|
||||
ip::icmp::endpoint(ip::icmp::v4(), 0), lazy);
|
||||
(void)i13;
|
||||
int i14 = socket1.async_send_to(null_buffers(),
|
||||
ip::icmp::endpoint(ip::icmp::v6(), 0), lazy);
|
||||
(void)i14;
|
||||
int i15 = socket1.async_send_to(buffer(mutable_char_buffer),
|
||||
ip::icmp::endpoint(ip::icmp::v4(), 0), in_flags, lazy);
|
||||
(void)i15;
|
||||
int i16 = socket1.async_send_to(buffer(mutable_char_buffer),
|
||||
ip::icmp::endpoint(ip::icmp::v6(), 0), in_flags, lazy);
|
||||
(void)i16;
|
||||
int i17 = socket1.async_send_to(buffer(const_char_buffer),
|
||||
ip::icmp::endpoint(ip::icmp::v4(), 0), in_flags, lazy);
|
||||
(void)i17;
|
||||
int i18 = socket1.async_send_to(buffer(const_char_buffer),
|
||||
ip::icmp::endpoint(ip::icmp::v6(), 0), in_flags, lazy);
|
||||
(void)i18;
|
||||
int i19 = socket1.async_send_to(null_buffers(),
|
||||
ip::icmp::endpoint(ip::icmp::v4(), 0), in_flags, lazy);
|
||||
(void)i19;
|
||||
int i20 = socket1.async_send_to(null_buffers(),
|
||||
ip::icmp::endpoint(ip::icmp::v6(), 0), in_flags, lazy);
|
||||
(void)i20;
|
||||
|
||||
socket1.receive(buffer(mutable_char_buffer));
|
||||
socket1.receive(null_buffers());
|
||||
socket1.receive(buffer(mutable_char_buffer), in_flags);
|
||||
socket1.receive(null_buffers(), in_flags);
|
||||
socket1.receive(buffer(mutable_char_buffer), in_flags, ec);
|
||||
socket1.receive(null_buffers(), in_flags, ec);
|
||||
|
||||
socket1.async_receive(buffer(mutable_char_buffer), receive_handler());
|
||||
socket1.async_receive(null_buffers(), receive_handler());
|
||||
socket1.async_receive(buffer(mutable_char_buffer), in_flags,
|
||||
receive_handler());
|
||||
socket1.async_receive(null_buffers(), in_flags, receive_handler());
|
||||
int i21 = socket1.async_receive(buffer(mutable_char_buffer), lazy);
|
||||
(void)i21;
|
||||
int i22 = socket1.async_receive(null_buffers(), lazy);
|
||||
(void)i22;
|
||||
int i23 = socket1.async_receive(buffer(mutable_char_buffer),
|
||||
in_flags, lazy);
|
||||
(void)i23;
|
||||
int i24 = socket1.async_receive(null_buffers(), in_flags, lazy);
|
||||
(void)i24;
|
||||
|
||||
ip::icmp::endpoint endpoint;
|
||||
socket1.receive_from(buffer(mutable_char_buffer), endpoint);
|
||||
socket1.receive_from(null_buffers(), endpoint);
|
||||
socket1.receive_from(buffer(mutable_char_buffer), endpoint, in_flags);
|
||||
socket1.receive_from(null_buffers(), endpoint, in_flags);
|
||||
socket1.receive_from(buffer(mutable_char_buffer), endpoint, in_flags, ec);
|
||||
socket1.receive_from(null_buffers(), endpoint, in_flags, ec);
|
||||
|
||||
socket1.async_receive_from(buffer(mutable_char_buffer),
|
||||
endpoint, receive_handler());
|
||||
socket1.async_receive_from(null_buffers(),
|
||||
endpoint, receive_handler());
|
||||
socket1.async_receive_from(buffer(mutable_char_buffer),
|
||||
endpoint, in_flags, receive_handler());
|
||||
socket1.async_receive_from(null_buffers(),
|
||||
endpoint, in_flags, receive_handler());
|
||||
int i25 = socket1.async_receive_from(buffer(mutable_char_buffer),
|
||||
endpoint, lazy);
|
||||
(void)i25;
|
||||
int i26 = socket1.async_receive_from(null_buffers(),
|
||||
endpoint, lazy);
|
||||
(void)i26;
|
||||
int i27 = socket1.async_receive_from(buffer(mutable_char_buffer),
|
||||
endpoint, in_flags, lazy);
|
||||
(void)i27;
|
||||
int i28 = socket1.async_receive_from(null_buffers(),
|
||||
endpoint, in_flags, lazy);
|
||||
(void)i28;
|
||||
}
|
||||
catch (std::exception&)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace ip_icmp_socket_compile
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
// ip_icmp_resolver_compile test
|
||||
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
// The following test checks that all public member functions on the class
|
||||
// ip::icmp::resolver compile and link correctly. Runtime failures are ignored.
|
||||
|
||||
namespace ip_icmp_resolver_compile {
|
||||
|
||||
struct resolve_handler
|
||||
{
|
||||
resolve_handler() {}
|
||||
void operator()(const asio::error_code&,
|
||||
asio::ip::icmp::resolver::results_type) {}
|
||||
#if defined(ASIO_HAS_MOVE)
|
||||
resolve_handler(resolve_handler&&) {}
|
||||
private:
|
||||
resolve_handler(const resolve_handler&);
|
||||
#endif // defined(ASIO_HAS_MOVE)
|
||||
};
|
||||
|
||||
void test()
|
||||
{
|
||||
using namespace asio;
|
||||
namespace ip = asio::ip;
|
||||
|
||||
try
|
||||
{
|
||||
io_context ioc;
|
||||
const io_context::executor_type ioc_ex = ioc.get_executor();
|
||||
archetypes::lazy_handler lazy;
|
||||
asio::error_code ec;
|
||||
#if !defined(ASIO_NO_DEPRECATED)
|
||||
ip::icmp::resolver::query q(ip::icmp::v4(), "localhost", "0");
|
||||
#endif // !defined(ASIO_NO_DEPRECATED)
|
||||
ip::icmp::endpoint e(ip::address_v4::loopback(), 0);
|
||||
|
||||
// basic_resolver constructors.
|
||||
|
||||
ip::icmp::resolver resolver(ioc);
|
||||
ip::icmp::resolver resolver2(ioc_ex);
|
||||
|
||||
#if defined(ASIO_HAS_MOVE)
|
||||
ip::icmp::resolver resolver3(std::move(resolver));
|
||||
#endif // defined(ASIO_HAS_MOVE)
|
||||
|
||||
// basic_resolver operators.
|
||||
|
||||
#if defined(ASIO_HAS_MOVE)
|
||||
resolver = ip::icmp::resolver(ioc);
|
||||
resolver = std::move(resolver3);
|
||||
#endif // defined(ASIO_HAS_MOVE)
|
||||
|
||||
// basic_io_object functions.
|
||||
|
||||
ip::icmp::resolver::executor_type ex = resolver.get_executor();
|
||||
(void)ex;
|
||||
|
||||
// basic_resolver functions.
|
||||
|
||||
resolver.cancel();
|
||||
|
||||
#if !defined(ASIO_NO_DEPRECATED)
|
||||
ip::icmp::resolver::results_type results1 = resolver.resolve(q);
|
||||
(void)results1;
|
||||
|
||||
ip::icmp::resolver::results_type results2 = resolver.resolve(q, ec);
|
||||
(void)results2;
|
||||
#endif // !defined(ASIO_NO_DEPRECATED)
|
||||
|
||||
ip::icmp::resolver::results_type results3 = resolver.resolve("", "");
|
||||
(void)results3;
|
||||
|
||||
ip::icmp::resolver::results_type results4 = resolver.resolve("", "", ec);
|
||||
(void)results4;
|
||||
|
||||
ip::icmp::resolver::results_type results5 =
|
||||
resolver.resolve("", "", ip::icmp::resolver::flags());
|
||||
(void)results5;
|
||||
|
||||
ip::icmp::resolver::results_type results6 =
|
||||
resolver.resolve("", "", ip::icmp::resolver::flags(), ec);
|
||||
(void)results6;
|
||||
|
||||
ip::icmp::resolver::results_type results7 =
|
||||
resolver.resolve(ip::icmp::v4(), "", "");
|
||||
(void)results7;
|
||||
|
||||
ip::icmp::resolver::results_type results8 =
|
||||
resolver.resolve(ip::icmp::v4(), "", "", ec);
|
||||
(void)results8;
|
||||
|
||||
ip::icmp::resolver::results_type results9 =
|
||||
resolver.resolve(ip::icmp::v4(), "", "", ip::icmp::resolver::flags());
|
||||
(void)results9;
|
||||
|
||||
ip::icmp::resolver::results_type results10 =
|
||||
resolver.resolve(ip::icmp::v4(), "", "", ip::icmp::resolver::flags(), ec);
|
||||
(void)results10;
|
||||
|
||||
ip::icmp::resolver::results_type results11 = resolver.resolve(e);
|
||||
(void)results11;
|
||||
|
||||
ip::icmp::resolver::results_type results12 = resolver.resolve(e, ec);
|
||||
(void)results12;
|
||||
|
||||
#if !defined(ASIO_NO_DEPRECATED)
|
||||
resolver.async_resolve(q, resolve_handler());
|
||||
int i1 = resolver.async_resolve(q, lazy);
|
||||
(void)i1;
|
||||
#endif // !defined(ASIO_NO_DEPRECATED)
|
||||
|
||||
resolver.async_resolve("", "", resolve_handler());
|
||||
int i2 = resolver.async_resolve("", "", lazy);
|
||||
(void)i2;
|
||||
|
||||
resolver.async_resolve("", "",
|
||||
ip::icmp::resolver::flags(), resolve_handler());
|
||||
int i3 = resolver.async_resolve("", "",
|
||||
ip::icmp::resolver::flags(), lazy);
|
||||
(void)i3;
|
||||
resolver.async_resolve(ip::icmp::v4(), "", "", resolve_handler());
|
||||
int i4 = resolver.async_resolve(ip::icmp::v4(), "", "", lazy);
|
||||
(void)i4;
|
||||
|
||||
resolver.async_resolve(ip::icmp::v4(),
|
||||
"", "", ip::icmp::resolver::flags(), resolve_handler());
|
||||
int i5 = resolver.async_resolve(ip::icmp::v4(),
|
||||
"", "", ip::icmp::resolver::flags(), lazy);
|
||||
(void)i5;
|
||||
|
||||
resolver.async_resolve(e, resolve_handler());
|
||||
int i6 = resolver.async_resolve(e, lazy);
|
||||
(void)i6;
|
||||
}
|
||||
catch (std::exception&)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace ip_icmp_resolver_compile
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
ASIO_TEST_SUITE
|
||||
(
|
||||
"ip/icmp",
|
||||
ASIO_TEST_CASE(ip_icmp_socket_compile::test)
|
||||
ASIO_TEST_CASE(ip_icmp_resolver_compile::test)
|
||||
)
|
||||
@@ -0,0 +1,363 @@
|
||||
//
|
||||
// multicast.cpp
|
||||
// ~~~~~~~~~~~~~
|
||||
//
|
||||
// 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)
|
||||
//
|
||||
|
||||
// Disable autolinking for unit tests.
|
||||
#if !defined(BOOST_ALL_NO_LIB)
|
||||
#define BOOST_ALL_NO_LIB 1
|
||||
#endif // !defined(BOOST_ALL_NO_LIB)
|
||||
|
||||
// Test that header file is self-contained.
|
||||
#include "asio/ip/multicast.hpp"
|
||||
|
||||
#include "asio/io_context.hpp"
|
||||
#include "asio/ip/udp.hpp"
|
||||
#include "../unit_test.hpp"
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
// ip_multicast_compile test
|
||||
// ~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
// The following test checks that all nested classes, enums and constants in
|
||||
// ip::multicast compile and link correctly. Runtime failures are ignored.
|
||||
|
||||
namespace ip_multicast_compile {
|
||||
|
||||
void test()
|
||||
{
|
||||
using namespace asio;
|
||||
namespace ip = asio::ip;
|
||||
|
||||
try
|
||||
{
|
||||
io_context ioc;
|
||||
ip::udp::socket sock(ioc);
|
||||
const ip::address address;
|
||||
const ip::address_v4 address_v4;
|
||||
const ip::address_v6 address_v6;
|
||||
|
||||
// join_group class.
|
||||
|
||||
ip::multicast::join_group join_group1;
|
||||
ip::multicast::join_group join_group2(address);
|
||||
ip::multicast::join_group join_group3(address_v4);
|
||||
ip::multicast::join_group join_group4(address_v4, address_v4);
|
||||
ip::multicast::join_group join_group5(address_v6);
|
||||
ip::multicast::join_group join_group6(address_v6, 1);
|
||||
sock.set_option(join_group6);
|
||||
|
||||
// leave_group class.
|
||||
|
||||
ip::multicast::leave_group leave_group1;
|
||||
ip::multicast::leave_group leave_group2(address);
|
||||
ip::multicast::leave_group leave_group3(address_v4);
|
||||
ip::multicast::leave_group leave_group4(address_v4, address_v4);
|
||||
ip::multicast::leave_group leave_group5(address_v6);
|
||||
ip::multicast::leave_group leave_group6(address_v6, 1);
|
||||
sock.set_option(leave_group6);
|
||||
|
||||
// outbound_interface class.
|
||||
|
||||
ip::multicast::outbound_interface outbound_interface1;
|
||||
ip::multicast::outbound_interface outbound_interface2(address_v4);
|
||||
ip::multicast::outbound_interface outbound_interface3(1);
|
||||
sock.set_option(outbound_interface3);
|
||||
|
||||
// hops class.
|
||||
|
||||
ip::multicast::hops hops1(1024);
|
||||
sock.set_option(hops1);
|
||||
ip::multicast::hops hops2;
|
||||
sock.get_option(hops2);
|
||||
hops1 = 1;
|
||||
(void)static_cast<int>(hops1.value());
|
||||
|
||||
// enable_loopback class.
|
||||
|
||||
ip::multicast::enable_loopback enable_loopback1(true);
|
||||
sock.set_option(enable_loopback1);
|
||||
ip::multicast::enable_loopback enable_loopback2;
|
||||
sock.get_option(enable_loopback2);
|
||||
enable_loopback1 = true;
|
||||
(void)static_cast<bool>(enable_loopback1);
|
||||
(void)static_cast<bool>(!enable_loopback1);
|
||||
(void)static_cast<bool>(enable_loopback1.value());
|
||||
}
|
||||
catch (std::exception&)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace ip_multicast_compile
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
// ip_multicast_runtime test
|
||||
// ~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
// The following test checks the runtime operation of the socket options defined
|
||||
// in the ip::multicast namespace.
|
||||
|
||||
namespace ip_multicast_runtime {
|
||||
|
||||
#if defined(__hpux)
|
||||
// HP-UX doesn't declare this function extern "C", so it is declared again here
|
||||
// to avoid a linker error about an undefined symbol.
|
||||
extern "C" unsigned int if_nametoindex(const char*);
|
||||
#endif // defined(__hpux)
|
||||
|
||||
void test()
|
||||
{
|
||||
using namespace asio;
|
||||
namespace ip = asio::ip;
|
||||
|
||||
io_context ioc;
|
||||
asio::error_code ec;
|
||||
|
||||
ip::udp::endpoint ep_v4(ip::address_v4::loopback(), 0);
|
||||
ip::udp::socket sock_v4(ioc);
|
||||
sock_v4.open(ep_v4.protocol(), ec);
|
||||
sock_v4.bind(ep_v4, ec);
|
||||
bool have_v4 = !ec;
|
||||
|
||||
ip::udp::endpoint ep_v6(ip::address_v6::loopback(), 0);
|
||||
ip::udp::socket sock_v6(ioc);
|
||||
sock_v6.open(ep_v6.protocol(), ec);
|
||||
sock_v6.bind(ep_v6, ec);
|
||||
bool have_v6 = !ec;
|
||||
|
||||
ASIO_CHECK(have_v4 || have_v6);
|
||||
|
||||
#if defined(ASIO_WINDOWS) && defined(UNDER_CE)
|
||||
// Windows CE seems to have problems with some multicast group addresses.
|
||||
// The following address works on CE, but as it is not a private multicast
|
||||
// address it will not be used on other platforms.
|
||||
const ip::address multicast_address_v4 = ip::make_address("239.0.0.4", ec);
|
||||
#else // defined(ASIO_WINDOWS) && defined(UNDER_CE)
|
||||
const ip::address multicast_address_v4 = ip::make_address("239.255.0.1", ec);
|
||||
#endif // defined(ASIO_WINDOWS) && defined(UNDER_CE)
|
||||
ASIO_CHECK(!have_v4 || !ec);
|
||||
|
||||
#if (defined(__MACH__) && defined(__APPLE__)) \
|
||||
|| defined(__FreeBSD__) \
|
||||
|| defined(__NetBSD__) \
|
||||
|| defined(__OpenBSD__)
|
||||
const ip::address multicast_address_v6 = ip::make_address("ff02::1%lo0", ec);
|
||||
#else // (defined(__MACH__) && defined(__APPLE__))
|
||||
// || defined(__FreeBSD__)
|
||||
// || defined(__NetBSD__)
|
||||
// || defined(__OpenBSD__)
|
||||
const ip::address multicast_address_v6 = ip::make_address("ff01::1", ec);
|
||||
#endif // (defined(__MACH__) && defined(__APPLE__))
|
||||
// || defined(__FreeBSD__)
|
||||
// || defined(__NetBSD__)
|
||||
// || defined(__OpenBSD__)
|
||||
ASIO_CHECK(!have_v6 || !ec);
|
||||
|
||||
// join_group class.
|
||||
|
||||
if (have_v4)
|
||||
{
|
||||
ip::multicast::join_group join_group(multicast_address_v4);
|
||||
sock_v4.set_option(join_group, ec);
|
||||
ASIO_CHECK_MESSAGE(!ec || ec == error::no_such_device,
|
||||
ec.value() << ", " << ec.message());
|
||||
|
||||
if (!ec)
|
||||
{
|
||||
// leave_group class.
|
||||
|
||||
ip::multicast::leave_group leave_group(multicast_address_v4);
|
||||
sock_v4.set_option(leave_group, ec);
|
||||
ASIO_CHECK_MESSAGE(!ec, ec.value() << ", " << ec.message());
|
||||
}
|
||||
}
|
||||
|
||||
if (have_v6)
|
||||
{
|
||||
ip::multicast::join_group join_group(multicast_address_v6);
|
||||
sock_v6.set_option(join_group, ec);
|
||||
ASIO_CHECK_MESSAGE(!ec || ec == error::no_such_device,
|
||||
ec.value() << ", " << ec.message());
|
||||
|
||||
if (!ec)
|
||||
{
|
||||
// leave_group class.
|
||||
|
||||
ip::multicast::leave_group leave_group(multicast_address_v6);
|
||||
sock_v6.set_option(leave_group, ec);
|
||||
ASIO_CHECK_MESSAGE(!ec, ec.value() << ", " << ec.message());
|
||||
}
|
||||
}
|
||||
|
||||
// outbound_interface class.
|
||||
|
||||
if (have_v4)
|
||||
{
|
||||
ip::multicast::outbound_interface outbound_interface(
|
||||
ip::address_v4::loopback());
|
||||
sock_v4.set_option(outbound_interface, ec);
|
||||
ASIO_CHECK_MESSAGE(!ec, ec.value() << ", " << ec.message());
|
||||
}
|
||||
|
||||
if (have_v6)
|
||||
{
|
||||
#if defined(__hpux)
|
||||
ip::multicast::outbound_interface outbound_interface(if_nametoindex("lo0"));
|
||||
#else
|
||||
ip::multicast::outbound_interface outbound_interface(1);
|
||||
#endif
|
||||
sock_v6.set_option(outbound_interface, ec);
|
||||
ASIO_CHECK_MESSAGE(!ec, ec.value() << ", " << ec.message());
|
||||
}
|
||||
|
||||
// hops class.
|
||||
|
||||
if (have_v4)
|
||||
{
|
||||
ip::multicast::hops hops1(1);
|
||||
ASIO_CHECK(hops1.value() == 1);
|
||||
sock_v4.set_option(hops1, ec);
|
||||
ASIO_CHECK_MESSAGE(!ec, ec.value() << ", " << ec.message());
|
||||
|
||||
ip::multicast::hops hops2;
|
||||
sock_v4.get_option(hops2, ec);
|
||||
ASIO_CHECK_MESSAGE(!ec, ec.value() << ", " << ec.message());
|
||||
ASIO_CHECK(hops2.value() == 1);
|
||||
|
||||
ip::multicast::hops hops3(0);
|
||||
ASIO_CHECK(hops3.value() == 0);
|
||||
sock_v4.set_option(hops3, ec);
|
||||
ASIO_CHECK_MESSAGE(!ec, ec.value() << ", " << ec.message());
|
||||
|
||||
ip::multicast::hops hops4;
|
||||
sock_v4.get_option(hops4, ec);
|
||||
ASIO_CHECK_MESSAGE(!ec, ec.value() << ", " << ec.message());
|
||||
ASIO_CHECK(hops4.value() == 0);
|
||||
}
|
||||
|
||||
if (have_v6)
|
||||
{
|
||||
ip::multicast::hops hops1(1);
|
||||
ASIO_CHECK(hops1.value() == 1);
|
||||
sock_v6.set_option(hops1, ec);
|
||||
ASIO_CHECK_MESSAGE(!ec, ec.value() << ", " << ec.message());
|
||||
|
||||
ip::multicast::hops hops2;
|
||||
sock_v6.get_option(hops2, ec);
|
||||
ASIO_CHECK_MESSAGE(!ec, ec.value() << ", " << ec.message());
|
||||
ASIO_CHECK(hops2.value() == 1);
|
||||
|
||||
ip::multicast::hops hops3(0);
|
||||
ASIO_CHECK(hops3.value() == 0);
|
||||
sock_v6.set_option(hops3, ec);
|
||||
ASIO_CHECK_MESSAGE(!ec, ec.value() << ", " << ec.message());
|
||||
|
||||
ip::multicast::hops hops4;
|
||||
sock_v6.get_option(hops4, ec);
|
||||
ASIO_CHECK_MESSAGE(!ec, ec.value() << ", " << ec.message());
|
||||
ASIO_CHECK(hops4.value() == 0);
|
||||
}
|
||||
|
||||
// enable_loopback class.
|
||||
|
||||
if (have_v4)
|
||||
{
|
||||
ip::multicast::enable_loopback enable_loopback1(true);
|
||||
ASIO_CHECK(enable_loopback1.value());
|
||||
ASIO_CHECK(static_cast<bool>(enable_loopback1));
|
||||
ASIO_CHECK(!!enable_loopback1);
|
||||
sock_v4.set_option(enable_loopback1, ec);
|
||||
#if defined(ASIO_WINDOWS) && defined(UNDER_CE)
|
||||
// Option is not supported under Windows CE.
|
||||
ASIO_CHECK_MESSAGE(ec == asio::error::no_protocol_option,
|
||||
ec.value() << ", " << ec.message());
|
||||
#else // defined(ASIO_WINDOWS) && defined(UNDER_CE)
|
||||
ASIO_CHECK_MESSAGE(!ec, ec.value() << ", " << ec.message());
|
||||
#endif // defined(ASIO_WINDOWS) && defined(UNDER_CE)
|
||||
|
||||
ip::multicast::enable_loopback enable_loopback2;
|
||||
sock_v4.get_option(enable_loopback2, ec);
|
||||
#if defined(ASIO_WINDOWS) && defined(UNDER_CE)
|
||||
// Not supported under Windows CE but can get value.
|
||||
ASIO_CHECK_MESSAGE(!ec, ec.value() << ", " << ec.message());
|
||||
#else // defined(ASIO_WINDOWS) && defined(UNDER_CE)
|
||||
ASIO_CHECK_MESSAGE(!ec, ec.value() << ", " << ec.message());
|
||||
ASIO_CHECK(enable_loopback2.value());
|
||||
ASIO_CHECK(static_cast<bool>(enable_loopback2));
|
||||
ASIO_CHECK(!!enable_loopback2);
|
||||
#endif // defined(ASIO_WINDOWS) && defined(UNDER_CE)
|
||||
|
||||
ip::multicast::enable_loopback enable_loopback3(false);
|
||||
ASIO_CHECK(!enable_loopback3.value());
|
||||
ASIO_CHECK(!static_cast<bool>(enable_loopback3));
|
||||
ASIO_CHECK(!enable_loopback3);
|
||||
sock_v4.set_option(enable_loopback3, ec);
|
||||
#if defined(ASIO_WINDOWS) && defined(UNDER_CE)
|
||||
// Option is not supported under Windows CE.
|
||||
ASIO_CHECK_MESSAGE(ec == asio::error::no_protocol_option,
|
||||
ec.value() << ", " << ec.message());
|
||||
#else // defined(ASIO_WINDOWS) && defined(UNDER_CE)
|
||||
ASIO_CHECK_MESSAGE(!ec, ec.value() << ", " << ec.message());
|
||||
#endif // defined(ASIO_WINDOWS) && defined(UNDER_CE)
|
||||
|
||||
ip::multicast::enable_loopback enable_loopback4;
|
||||
sock_v4.get_option(enable_loopback4, ec);
|
||||
#if defined(ASIO_WINDOWS) && defined(UNDER_CE)
|
||||
// Not supported under Windows CE but can get value.
|
||||
ASIO_CHECK_MESSAGE(!ec, ec.value() << ", " << ec.message());
|
||||
#else // defined(ASIO_WINDOWS) && defined(UNDER_CE)
|
||||
ASIO_CHECK_MESSAGE(!ec, ec.value() << ", " << ec.message());
|
||||
ASIO_CHECK(!enable_loopback4.value());
|
||||
ASIO_CHECK(!static_cast<bool>(enable_loopback4));
|
||||
ASIO_CHECK(!enable_loopback4);
|
||||
#endif // defined(ASIO_WINDOWS) && defined(UNDER_CE)
|
||||
}
|
||||
|
||||
if (have_v6)
|
||||
{
|
||||
ip::multicast::enable_loopback enable_loopback1(true);
|
||||
ASIO_CHECK(enable_loopback1.value());
|
||||
ASIO_CHECK(static_cast<bool>(enable_loopback1));
|
||||
ASIO_CHECK(!!enable_loopback1);
|
||||
sock_v6.set_option(enable_loopback1, ec);
|
||||
ASIO_CHECK_MESSAGE(!ec, ec.value() << ", " << ec.message());
|
||||
|
||||
ip::multicast::enable_loopback enable_loopback2;
|
||||
sock_v6.get_option(enable_loopback2, ec);
|
||||
ASIO_CHECK_MESSAGE(!ec, ec.value() << ", " << ec.message());
|
||||
ASIO_CHECK(enable_loopback2.value());
|
||||
ASIO_CHECK(static_cast<bool>(enable_loopback2));
|
||||
ASIO_CHECK(!!enable_loopback2);
|
||||
|
||||
ip::multicast::enable_loopback enable_loopback3(false);
|
||||
ASIO_CHECK(!enable_loopback3.value());
|
||||
ASIO_CHECK(!static_cast<bool>(enable_loopback3));
|
||||
ASIO_CHECK(!enable_loopback3);
|
||||
sock_v6.set_option(enable_loopback3, ec);
|
||||
ASIO_CHECK_MESSAGE(!ec, ec.value() << ", " << ec.message());
|
||||
|
||||
ip::multicast::enable_loopback enable_loopback4;
|
||||
sock_v6.get_option(enable_loopback4, ec);
|
||||
ASIO_CHECK_MESSAGE(!ec, ec.value() << ", " << ec.message());
|
||||
ASIO_CHECK(!enable_loopback4.value());
|
||||
ASIO_CHECK(!static_cast<bool>(enable_loopback4));
|
||||
ASIO_CHECK(!enable_loopback4);
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace ip_multicast_runtime
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
ASIO_TEST_SUITE
|
||||
(
|
||||
"ip/multicast",
|
||||
ASIO_TEST_CASE(ip_multicast_compile::test)
|
||||
ASIO_TEST_CASE(ip_multicast_runtime::test)
|
||||
)
|
||||
@@ -0,0 +1,314 @@
|
||||
//
|
||||
// network_v4.cpp
|
||||
// ~~~~~~~~~~~~~~
|
||||
//
|
||||
// Copyright (c) 2003-2019 Christopher M. Kohlhoff (chris at kohlhoff dot com)
|
||||
// Copyright (c) 2014 Oliver Kowalke (oliver dot kowalke at gmail 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)
|
||||
//
|
||||
|
||||
// Disable autolinking for unit tests.
|
||||
#if !defined(BOOST_ALL_NO_LIB)
|
||||
#define BOOST_ALL_NO_LIB 1
|
||||
#endif // !defined(BOOST_ALL_NO_LIB)
|
||||
|
||||
// Test that header file is self-contained.
|
||||
#include "asio/ip/network_v4.hpp"
|
||||
|
||||
#include "../unit_test.hpp"
|
||||
#include <sstream>
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
// ip_network_v4_compile test
|
||||
// ~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
// The following test checks that all public member functions on the class
|
||||
// ip::network_v4 compile and link correctly. Runtime failures are ignored.
|
||||
|
||||
namespace ip_network_v4_compile {
|
||||
|
||||
void test()
|
||||
{
|
||||
using namespace asio;
|
||||
namespace ip = asio::ip;
|
||||
|
||||
try
|
||||
{
|
||||
asio::error_code ec;
|
||||
|
||||
// network_v4 constructors.
|
||||
|
||||
ip::network_v4 net1(ip::make_address_v4("192.168.1.0"), 32);
|
||||
ip::network_v4 net2(ip::make_address_v4("192.168.1.0"),
|
||||
ip::make_address_v4("255.255.255.0"));
|
||||
|
||||
// network_v4 functions.
|
||||
|
||||
ip::address_v4 addr1 = net1.address();
|
||||
(void)addr1;
|
||||
|
||||
unsigned short prefix_len = net1.prefix_length();
|
||||
(void)prefix_len;
|
||||
|
||||
ip::address_v4 addr2 = net1.netmask();
|
||||
(void)addr2;
|
||||
|
||||
ip::address_v4 addr3 = net1.network();
|
||||
(void)addr3;
|
||||
|
||||
ip::address_v4 addr4 = net1.broadcast();
|
||||
(void)addr4;
|
||||
|
||||
ip::address_v4_range hosts = net1.hosts();
|
||||
(void)hosts;
|
||||
|
||||
ip::network_v4 net3 = net1.canonical();
|
||||
(void)net3;
|
||||
|
||||
bool b1 = net1.is_host();
|
||||
(void)b1;
|
||||
|
||||
bool b2 = net1.is_subnet_of(net2);
|
||||
(void)b2;
|
||||
|
||||
std::string s1 = net1.to_string();
|
||||
(void)s1;
|
||||
|
||||
std::string s2 = net1.to_string(ec);
|
||||
(void)s2;
|
||||
|
||||
// network_v4 comparisons.
|
||||
|
||||
bool b3 = (net1 == net2);
|
||||
(void)b3;
|
||||
|
||||
bool b4 = (net1 != net2);
|
||||
(void)b4;
|
||||
|
||||
// network_v4 creation functions.
|
||||
|
||||
net1 = ip::make_network_v4(ip::address_v4(), 24);
|
||||
net1 = ip::make_network_v4(ip::address_v4(), ip::address_v4());
|
||||
net1 = ip::make_network_v4("10.0.0.0/8");
|
||||
net1 = ip::make_network_v4("10.0.0.0/8", ec);
|
||||
net1 = ip::make_network_v4(s1);
|
||||
net1 = ip::make_network_v4(s1, ec);
|
||||
#if defined(ASIO_HAS_STRING_VIEW)
|
||||
# if defined(ASIO_HAS_STD_STRING_VIEW)
|
||||
std::string_view string_view_value("10.0.0.0/8");
|
||||
# elif defined(ASIO_HAS_STD_EXPERIMENTAL_STRING_VIEW)
|
||||
std::experimental::string_view string_view_value("10.0.0.0/8");
|
||||
# endif // defined(ASIO_HAS_STD_EXPERIMENTAL_STRING_VIEW)
|
||||
net1 = ip::make_network_v4(string_view_value);
|
||||
net1 = ip::make_network_v4(string_view_value, ec);
|
||||
#endif // defined(ASIO_HAS_STRING_VIEW)
|
||||
|
||||
// network_v4 I/O.
|
||||
|
||||
std::ostringstream os;
|
||||
os << net1;
|
||||
|
||||
#if !defined(BOOST_NO_STD_WSTREAMBUF)
|
||||
std::wostringstream wos;
|
||||
wos << net1;
|
||||
#endif // !defined(BOOST_NO_STD_WSTREAMBUF)
|
||||
}
|
||||
catch (std::exception&)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace ip_network_v4_compile
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
// ip_network_v4_runtime test
|
||||
// ~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
// The following test checks that the various public member functions meet the
|
||||
// necessary postconditions.
|
||||
|
||||
namespace ip_network_v4_runtime {
|
||||
|
||||
void test()
|
||||
{
|
||||
using asio::ip::address_v4;
|
||||
using asio::ip::make_address_v4;
|
||||
using asio::ip::network_v4;
|
||||
using asio::ip::make_network_v4;
|
||||
|
||||
address_v4 addr = make_address_v4("1.2.3.4");
|
||||
|
||||
// calculate prefix length
|
||||
|
||||
network_v4 net1(addr, make_address_v4("255.255.255.0"));
|
||||
ASIO_CHECK(net1.prefix_length() == 24);
|
||||
|
||||
network_v4 net2(addr, make_address_v4("255.255.255.192"));
|
||||
ASIO_CHECK(net2.prefix_length() == 26);
|
||||
|
||||
network_v4 net3(addr, make_address_v4("128.0.0.0"));
|
||||
ASIO_CHECK(net3.prefix_length() == 1);
|
||||
|
||||
std::string msg;
|
||||
try
|
||||
{
|
||||
make_network_v4(addr, make_address_v4("255.255.255.1"));
|
||||
}
|
||||
catch(std::exception& ex)
|
||||
{
|
||||
msg = ex.what();
|
||||
}
|
||||
ASIO_CHECK(msg == std::string("non-contiguous netmask"));
|
||||
|
||||
msg.clear();
|
||||
try
|
||||
{
|
||||
make_network_v4(addr, make_address_v4("0.255.255.0"));
|
||||
}
|
||||
catch(std::exception& ex)
|
||||
{
|
||||
msg = ex.what();
|
||||
}
|
||||
ASIO_CHECK(msg == std::string("non-contiguous netmask"));
|
||||
|
||||
// calculate netmask
|
||||
|
||||
network_v4 net4(addr, 23);
|
||||
ASIO_CHECK(net4.netmask() == make_address_v4("255.255.254.0"));
|
||||
|
||||
network_v4 net5(addr, 12);
|
||||
ASIO_CHECK(net5.netmask() == make_address_v4("255.240.0.0"));
|
||||
|
||||
network_v4 net6(addr, 24);
|
||||
ASIO_CHECK(net6.netmask() == make_address_v4("255.255.255.0"));
|
||||
|
||||
network_v4 net7(addr, 16);
|
||||
ASIO_CHECK(net7.netmask() == make_address_v4("255.255.0.0"));
|
||||
|
||||
network_v4 net8(addr, 8);
|
||||
ASIO_CHECK(net8.netmask() == make_address_v4("255.0.0.0"));
|
||||
|
||||
network_v4 net9(addr, 32);
|
||||
ASIO_CHECK(net9.netmask() == make_address_v4("255.255.255.255"));
|
||||
|
||||
network_v4 net10(addr, 1);
|
||||
ASIO_CHECK(net10.netmask() == make_address_v4("128.0.0.0"));
|
||||
|
||||
network_v4 net11(addr, 0);
|
||||
ASIO_CHECK(net11.netmask() == make_address_v4("0.0.0.0"));
|
||||
|
||||
msg.clear();
|
||||
try
|
||||
{
|
||||
make_network_v4(addr, 33);
|
||||
}
|
||||
catch(std::out_of_range& ex)
|
||||
{
|
||||
msg = ex.what();
|
||||
}
|
||||
ASIO_CHECK(msg == std::string("prefix length too large"));
|
||||
|
||||
// construct address range from address and prefix length
|
||||
ASIO_CHECK(network_v4(make_address_v4("192.168.77.100"), 32).network() == make_address_v4("192.168.77.100"));
|
||||
ASIO_CHECK(network_v4(make_address_v4("192.168.77.100"), 24).network() == make_address_v4("192.168.77.0"));
|
||||
ASIO_CHECK(network_v4(make_address_v4("192.168.77.128"), 25).network() == make_address_v4("192.168.77.128"));
|
||||
|
||||
// construct address range from string in CIDR notation
|
||||
ASIO_CHECK(make_network_v4("192.168.77.100/32").network() == make_address_v4("192.168.77.100"));
|
||||
ASIO_CHECK(make_network_v4("192.168.77.100/24").network() == make_address_v4("192.168.77.0"));
|
||||
ASIO_CHECK(make_network_v4("192.168.77.128/25").network() == make_address_v4("192.168.77.128"));
|
||||
|
||||
// construct network from invalid string
|
||||
asio::error_code ec;
|
||||
make_network_v4("10.0.0.256/24", ec);
|
||||
ASIO_CHECK(!!ec);
|
||||
make_network_v4("10.0.0.0/33", ec);
|
||||
ASIO_CHECK(!!ec);
|
||||
make_network_v4("10.0.0.0/-1", ec);
|
||||
ASIO_CHECK(!!ec);
|
||||
make_network_v4("10.0.0.0/", ec);
|
||||
ASIO_CHECK(!!ec);
|
||||
make_network_v4("10.0.0.0", ec);
|
||||
ASIO_CHECK(!!ec);
|
||||
|
||||
// prefix length
|
||||
ASIO_CHECK(make_network_v4("193.99.144.80/24").prefix_length() == 24);
|
||||
ASIO_CHECK(network_v4(make_address_v4("193.99.144.80"), 24).prefix_length() == 24);
|
||||
ASIO_CHECK(network_v4(make_address_v4("192.168.77.0"), make_address_v4("255.255.255.0")).prefix_length() == 24);
|
||||
|
||||
// to string
|
||||
std::string a("192.168.77.0/32");
|
||||
ASIO_CHECK(make_network_v4(a.c_str()).to_string() == a);
|
||||
ASIO_CHECK(network_v4(make_address_v4("192.168.77.10"), 24).to_string() == std::string("192.168.77.10/24"));
|
||||
|
||||
// return host part
|
||||
ASIO_CHECK(make_network_v4("192.168.77.11/24").address() == make_address_v4("192.168.77.11"));
|
||||
|
||||
// return host in CIDR notation
|
||||
ASIO_CHECK(make_network_v4("192.168.78.30/20").address().to_string() == "192.168.78.30");
|
||||
|
||||
// return network in CIDR notation
|
||||
ASIO_CHECK(make_network_v4("192.168.78.30/20").canonical().to_string() == "192.168.64.0/20");
|
||||
|
||||
// is host
|
||||
ASIO_CHECK(make_network_v4("192.168.77.0/32").is_host());
|
||||
ASIO_CHECK(!make_network_v4("192.168.77.0/31").is_host());
|
||||
|
||||
// is real subnet of
|
||||
ASIO_CHECK(make_network_v4("192.168.0.192/24").is_subnet_of(make_network_v4("192.168.0.0/16")));
|
||||
ASIO_CHECK(make_network_v4("192.168.0.0/24").is_subnet_of(make_network_v4("192.168.192.168/16")));
|
||||
ASIO_CHECK(make_network_v4("192.168.0.192/24").is_subnet_of(make_network_v4("192.168.192.168/16")));
|
||||
ASIO_CHECK(make_network_v4("192.168.0.0/24").is_subnet_of(make_network_v4("192.168.0.0/16")));
|
||||
ASIO_CHECK(make_network_v4("192.168.0.0/24").is_subnet_of(make_network_v4("192.168.0.0/23")));
|
||||
ASIO_CHECK(make_network_v4("192.168.0.0/24").is_subnet_of(make_network_v4("192.168.0.0/0")));
|
||||
ASIO_CHECK(make_network_v4("192.168.0.0/32").is_subnet_of(make_network_v4("192.168.0.0/24")));
|
||||
|
||||
ASIO_CHECK(!make_network_v4("192.168.0.0/32").is_subnet_of(make_network_v4("192.168.0.0/32")));
|
||||
ASIO_CHECK(!make_network_v4("192.168.0.0/24").is_subnet_of(make_network_v4("192.168.1.0/24")));
|
||||
ASIO_CHECK(!make_network_v4("192.168.0.0/16").is_subnet_of(make_network_v4("192.168.1.0/24")));
|
||||
|
||||
network_v4 r(make_network_v4("192.168.0.0/24"));
|
||||
ASIO_CHECK(!r.is_subnet_of(r));
|
||||
|
||||
network_v4 net12(make_network_v4("192.168.0.2/24"));
|
||||
network_v4 net13(make_network_v4("192.168.1.1/28"));
|
||||
network_v4 net14(make_network_v4("192.168.1.21/28"));
|
||||
// network
|
||||
ASIO_CHECK(net12.network() == make_address_v4("192.168.0.0"));
|
||||
ASIO_CHECK(net13.network() == make_address_v4("192.168.1.0"));
|
||||
ASIO_CHECK(net14.network() == make_address_v4("192.168.1.16"));
|
||||
// netmask
|
||||
ASIO_CHECK(net12.netmask() == make_address_v4("255.255.255.0"));
|
||||
ASIO_CHECK(net13.netmask() == make_address_v4("255.255.255.240"));
|
||||
ASIO_CHECK(net14.netmask() == make_address_v4("255.255.255.240"));
|
||||
// broadcast
|
||||
ASIO_CHECK(net12.broadcast() == make_address_v4("192.168.0.255"));
|
||||
ASIO_CHECK(net13.broadcast() == make_address_v4("192.168.1.15"));
|
||||
ASIO_CHECK(net14.broadcast() == make_address_v4("192.168.1.31"));
|
||||
// iterator
|
||||
ASIO_CHECK(std::distance(net12.hosts().begin(),net12.hosts().end()) == 254);
|
||||
ASIO_CHECK(*net12.hosts().begin() == make_address_v4("192.168.0.1"));
|
||||
ASIO_CHECK(net12.hosts().end() != net12.hosts().find(make_address_v4("192.168.0.10")));
|
||||
ASIO_CHECK(net12.hosts().end() == net12.hosts().find(make_address_v4("192.168.1.10")));
|
||||
ASIO_CHECK(std::distance(net13.hosts().begin(),net13.hosts().end()) == 14);
|
||||
ASIO_CHECK(*net13.hosts().begin() == make_address_v4("192.168.1.1"));
|
||||
ASIO_CHECK(net13.hosts().end() != net13.hosts().find(make_address_v4("192.168.1.14")));
|
||||
ASIO_CHECK(net13.hosts().end() == net13.hosts().find(make_address_v4("192.168.1.15")));
|
||||
ASIO_CHECK(std::distance(net14.hosts().begin(),net14.hosts().end()) == 14);
|
||||
ASIO_CHECK(*net14.hosts().begin() == make_address_v4("192.168.1.17"));
|
||||
ASIO_CHECK(net14.hosts().end() != net14.hosts().find(make_address_v4("192.168.1.30")));
|
||||
ASIO_CHECK(net14.hosts().end() == net14.hosts().find(make_address_v4("192.168.1.31")));
|
||||
}
|
||||
|
||||
} // namespace ip_network_v4_runtime
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
ASIO_TEST_SUITE
|
||||
(
|
||||
"ip/network_v4",
|
||||
ASIO_TEST_CASE(ip_network_v4_compile::test)
|
||||
ASIO_TEST_CASE(ip_network_v4_runtime::test)
|
||||
)
|
||||
@@ -0,0 +1,238 @@
|
||||
//
|
||||
// network_v6.cpp
|
||||
// ~~~~~~~~~~~~~~
|
||||
//
|
||||
// Copyright (c) 2003-2019 Christopher M. Kohlhoff (chris at kohlhoff dot com)
|
||||
// Copyright (c) 2014 Oliver Kowalke (oliver dot kowalke at gmail 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)
|
||||
//
|
||||
|
||||
// Disable autolinking for unit tests.
|
||||
#if !defined(BOOST_ALL_NO_LIB)
|
||||
#define BOOST_ALL_NO_LIB 1
|
||||
#endif // !defined(BOOST_ALL_NO_LIB)
|
||||
|
||||
// Test that header file is self-contained.
|
||||
#include "asio/ip/network_v6.hpp"
|
||||
|
||||
#include "../unit_test.hpp"
|
||||
#include <sstream>
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
// ip_network_v6_compile test
|
||||
// ~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
// The following test checks that all public member functions on the class
|
||||
// ip::network_v6 compile and link correctly. Runtime failures are ignored.
|
||||
|
||||
namespace ip_network_v6_compile {
|
||||
|
||||
void test()
|
||||
{
|
||||
using namespace asio;
|
||||
namespace ip = asio::ip;
|
||||
|
||||
try
|
||||
{
|
||||
asio::error_code ec;
|
||||
|
||||
// network_v6 constructors.
|
||||
|
||||
ip::network_v6 net1(ip::make_address_v6("2001:370::10:7344"), 64);
|
||||
ip::network_v6 net2(ip::make_address_v6("2001:370::10:7345"), 96);
|
||||
|
||||
// network_v6 functions.
|
||||
|
||||
ip::address_v6 addr1 = net1.address();
|
||||
(void)addr1;
|
||||
|
||||
unsigned short prefix_len = net1.prefix_length();
|
||||
(void)prefix_len;
|
||||
|
||||
ip::address_v6 addr3 = net1.network();
|
||||
(void)addr3;
|
||||
|
||||
ip::address_v6_range hosts = net1.hosts();
|
||||
(void)hosts;
|
||||
|
||||
ip::network_v6 net3 = net1.canonical();
|
||||
(void)net3;
|
||||
|
||||
bool b1 = net1.is_host();
|
||||
(void)b1;
|
||||
|
||||
bool b2 = net1.is_subnet_of(net2);
|
||||
(void)b2;
|
||||
|
||||
std::string s1 = net1.to_string();
|
||||
(void)s1;
|
||||
|
||||
std::string s2 = net1.to_string(ec);
|
||||
(void)s2;
|
||||
|
||||
// network_v6 comparisons.
|
||||
|
||||
bool b3 = (net1 == net2);
|
||||
(void)b3;
|
||||
|
||||
bool b4 = (net1 != net2);
|
||||
(void)b4;
|
||||
|
||||
// network_v6 creation functions.
|
||||
|
||||
net1 = ip::make_network_v6(ip::address_v6(), 24);
|
||||
net1 = ip::make_network_v6("10.0.0.0/8");
|
||||
net1 = ip::make_network_v6("10.0.0.0/8", ec);
|
||||
net1 = ip::make_network_v6(s1);
|
||||
net1 = ip::make_network_v6(s1, ec);
|
||||
#if defined(ASIO_HAS_STRING_VIEW)
|
||||
# if defined(ASIO_HAS_STD_STRING_VIEW)
|
||||
std::string_view string_view_value("0::0/8");
|
||||
# elif defined(ASIO_HAS_STD_EXPERIMENTAL_STRING_VIEW)
|
||||
std::experimental::string_view string_view_value("0::0/8");
|
||||
# endif // defined(ASIO_HAS_STD_EXPERIMENTAL_STRING_VIEW)
|
||||
net1 = ip::make_network_v6(string_view_value);
|
||||
net1 = ip::make_network_v6(string_view_value, ec);
|
||||
#endif // defined(ASIO_STD_STRING_VIEW)
|
||||
|
||||
// network_v6 I/O.
|
||||
|
||||
std::ostringstream os;
|
||||
os << net1;
|
||||
|
||||
#if !defined(BOOST_NO_STD_WSTREAMBUF)
|
||||
std::wostringstream wos;
|
||||
wos << net1;
|
||||
#endif // !defined(BOOST_NO_STD_WSTREAMBUF)
|
||||
}
|
||||
catch (std::exception&)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace ip_network_v6_compile
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
// ip_network_v6_runtime test
|
||||
// ~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
// The following test checks that the various public member functions meet the
|
||||
// necessary postconditions.
|
||||
|
||||
namespace ip_network_v6_runtime {
|
||||
|
||||
void test()
|
||||
{
|
||||
using asio::ip::address_v6;
|
||||
using asio::ip::make_address_v6;
|
||||
using asio::ip::network_v6;
|
||||
using asio::ip::make_network_v6;
|
||||
|
||||
address_v6 addr = make_address_v6("2001:370::10:7344");
|
||||
|
||||
std::string msg;
|
||||
try
|
||||
{
|
||||
make_network_v6(addr, 129);
|
||||
}
|
||||
catch(std::out_of_range& ex)
|
||||
{
|
||||
msg = ex.what();
|
||||
}
|
||||
ASIO_CHECK(msg == std::string("prefix length too large"));
|
||||
|
||||
// construct address range from address and prefix length
|
||||
ASIO_CHECK(network_v6(make_address_v6("2001:370::10:7344"), 128).network() == make_address_v6("2001:370::10:7344"));
|
||||
ASIO_CHECK(network_v6(make_address_v6("2001:370::10:7344"), 64).network() == make_address_v6("2001:370::"));
|
||||
ASIO_CHECK(network_v6(make_address_v6("2001:370::10:7344"), 27).network() == make_address_v6("2001:360::"));
|
||||
|
||||
// construct address range from string in CIDR notation
|
||||
ASIO_CHECK(make_network_v6("2001:370::10:7344/128").network() == make_address_v6("2001:370::10:7344"));
|
||||
ASIO_CHECK(make_network_v6("2001:370::10:7344/64").network() == make_address_v6("2001:370::"));
|
||||
ASIO_CHECK(make_network_v6("2001:370::10:7344/27").network() == make_address_v6("2001:360::"));
|
||||
|
||||
// construct network from invalid string
|
||||
asio::error_code ec;
|
||||
make_network_v6("a:b/24", ec);
|
||||
ASIO_CHECK(!!ec);
|
||||
make_network_v6("2001:370::10:7344/129", ec);
|
||||
ASIO_CHECK(!!ec);
|
||||
make_network_v6("2001:370::10:7344/-1", ec);
|
||||
ASIO_CHECK(!!ec);
|
||||
make_network_v6("2001:370::10:7344/", ec);
|
||||
ASIO_CHECK(!!ec);
|
||||
make_network_v6("2001:370::10:7344", ec);
|
||||
ASIO_CHECK(!!ec);
|
||||
|
||||
// prefix length
|
||||
ASIO_CHECK(make_network_v6("2001:370::10:7344/128").prefix_length() == 128);
|
||||
ASIO_CHECK(network_v6(make_address_v6("2001:370::10:7344"), 27).prefix_length() == 27);
|
||||
|
||||
// to string
|
||||
std::string a("2001:370::10:7344/64");
|
||||
ASIO_CHECK(make_network_v6(a.c_str()).to_string() == a);
|
||||
ASIO_CHECK(network_v6(make_address_v6("2001:370::10:7344"), 27).to_string() == std::string("2001:370::10:7344/27"));
|
||||
|
||||
// return host part
|
||||
ASIO_CHECK(make_network_v6("2001:370::10:7344/64").address() == make_address_v6("2001:370::10:7344"));
|
||||
ASIO_CHECK(make_network_v6("2001:370::10:7344/27").address().to_string() == "2001:370::10:7344");
|
||||
|
||||
// return network in CIDR notation
|
||||
ASIO_CHECK(make_network_v6("2001:370::10:7344/27").canonical().to_string() == "2001:360::/27");
|
||||
|
||||
// is host
|
||||
ASIO_CHECK(make_network_v6("2001:370::10:7344/128").is_host());
|
||||
ASIO_CHECK(!make_network_v6("2001:370::10:7344/127").is_host());
|
||||
|
||||
// is real subnet of
|
||||
ASIO_CHECK(make_network_v6("2001:370::10:3744/64").is_subnet_of(make_network_v6("2001:370::/16")));
|
||||
ASIO_CHECK(make_network_v6("2001:370::/64").is_subnet_of(make_network_v6("2001:370::/16")));
|
||||
ASIO_CHECK(make_network_v6("2001:0db8:85a3::/64").is_subnet_of(make_network_v6("2001:0d00::/24")));
|
||||
|
||||
ASIO_CHECK(!make_network_v6("2001:370::10:3744/128").is_subnet_of(make_network_v6("2001:370::10:3744/128")));
|
||||
ASIO_CHECK(make_network_v6("2001:0db8:85a3::/64").is_subnet_of(make_network_v6("2001:0dc0::/24")));
|
||||
|
||||
network_v6 r(make_network_v6("2001:370::/64"));
|
||||
ASIO_CHECK(!r.is_subnet_of(r));
|
||||
|
||||
network_v6 net12(make_network_v6("2001:370::10:7344/64"));
|
||||
network_v6 net13(make_network_v6("2001:0db8::/127"));
|
||||
network_v6 net14(make_network_v6("2001:0db8::/125"));
|
||||
network_v6 net15(make_network_v6("2001:0db8::/119"));
|
||||
|
||||
// network
|
||||
ASIO_CHECK(net12.network() == make_address_v6("2001:370::"));
|
||||
ASIO_CHECK(net13.network() == make_address_v6("2001:0db8::"));
|
||||
ASIO_CHECK(net14.network() == make_address_v6("2001:0db8::"));
|
||||
ASIO_CHECK(net15.network() == make_address_v6("2001:0db8::"));
|
||||
|
||||
// iterator
|
||||
//ASIO_CHECK(std::distance(net12.hosts().begin(),net12.hosts().end()) == 18446744073709552000);
|
||||
ASIO_CHECK(std::distance(net13.hosts().begin(),net13.hosts().end()) == 2);
|
||||
ASIO_CHECK(std::distance(net14.hosts().begin(),net14.hosts().end()) == 8);
|
||||
ASIO_CHECK(std::distance(net15.hosts().begin(),net15.hosts().end()) == 512);
|
||||
ASIO_CHECK(*net12.hosts().begin() == make_address_v6("2001:0370::"));
|
||||
ASIO_CHECK(net12.hosts().end() != net12.hosts().find(make_address_v6("2001:0370::ffff:ffff:ffff:ffff")));
|
||||
ASIO_CHECK(*net13.hosts().begin() == make_address_v6("2001:0db8::"));
|
||||
ASIO_CHECK(net13.hosts().end() != net13.hosts().find(make_address_v6("2001:0db8::1")));
|
||||
ASIO_CHECK(net13.hosts().end() == net13.hosts().find(make_address_v6("2001:0db8::2")));
|
||||
ASIO_CHECK(*net14.hosts().begin() == make_address_v6("2001:0db8::"));
|
||||
ASIO_CHECK(net14.hosts().end() != net14.hosts().find(make_address_v6("2001:0db8::7")));
|
||||
ASIO_CHECK(net14.hosts().end() == net14.hosts().find(make_address_v6("2001:0db8::8")));
|
||||
ASIO_CHECK(*net15.hosts().begin() == make_address_v6("2001:0db8::"));
|
||||
ASIO_CHECK(net15.hosts().end() != net15.hosts().find(make_address_v6("2001:0db8::01ff")));
|
||||
ASIO_CHECK(net15.hosts().end() == net15.hosts().find(make_address_v6("2001:0db8::0200")));
|
||||
}
|
||||
|
||||
} // namespace ip_network_v6_runtime
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
ASIO_TEST_SUITE
|
||||
(
|
||||
"ip/network_v6",
|
||||
ASIO_TEST_CASE(ip_network_v6_compile::test)
|
||||
ASIO_TEST_CASE(ip_network_v6_runtime::test)
|
||||
)
|
||||
@@ -0,0 +1,25 @@
|
||||
//
|
||||
// resolver_query_base.cpp
|
||||
// ~~~~~~~~~~~~~~~~~~~~~~~
|
||||
//
|
||||
// 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)
|
||||
//
|
||||
|
||||
// Disable autolinking for unit tests.
|
||||
#if !defined(BOOST_ALL_NO_LIB)
|
||||
#define BOOST_ALL_NO_LIB 1
|
||||
#endif // !defined(BOOST_ALL_NO_LIB)
|
||||
|
||||
// Test that header file is self-contained.
|
||||
#include "asio/ip/resolver_query_base.hpp"
|
||||
|
||||
#include "../unit_test.hpp"
|
||||
|
||||
ASIO_TEST_SUITE
|
||||
(
|
||||
"ip/resolver_query_base",
|
||||
ASIO_TEST_CASE(null_test)
|
||||
)
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,673 @@
|
||||
//
|
||||
// udp.cpp
|
||||
// ~~~~~~~
|
||||
//
|
||||
// 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)
|
||||
//
|
||||
|
||||
// Disable autolinking for unit tests.
|
||||
#if !defined(BOOST_ALL_NO_LIB)
|
||||
#define BOOST_ALL_NO_LIB 1
|
||||
#endif // !defined(BOOST_ALL_NO_LIB)
|
||||
|
||||
// Test that header file is self-contained.
|
||||
#include "asio/ip/udp.hpp"
|
||||
|
||||
#include <cstring>
|
||||
#include "asio/io_context.hpp"
|
||||
#include "../unit_test.hpp"
|
||||
#include "../archetypes/async_result.hpp"
|
||||
#include "../archetypes/gettable_socket_option.hpp"
|
||||
#include "../archetypes/io_control_command.hpp"
|
||||
#include "../archetypes/settable_socket_option.hpp"
|
||||
|
||||
#if defined(ASIO_HAS_BOOST_BIND)
|
||||
# include <boost/bind.hpp>
|
||||
#else // defined(ASIO_HAS_BOOST_BIND)
|
||||
# include <functional>
|
||||
#endif // defined(ASIO_HAS_BOOST_BIND)
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
// ip_udp_socket_compile test
|
||||
// ~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
// The following test checks that all public member functions on the class
|
||||
// ip::udp::socket compile and link correctly. Runtime failures are ignored.
|
||||
|
||||
namespace ip_udp_socket_compile {
|
||||
|
||||
struct connect_handler
|
||||
{
|
||||
connect_handler() {}
|
||||
void operator()(const asio::error_code&) {}
|
||||
#if defined(ASIO_HAS_MOVE)
|
||||
connect_handler(connect_handler&&) {}
|
||||
private:
|
||||
connect_handler(const connect_handler&);
|
||||
#endif // defined(ASIO_HAS_MOVE)
|
||||
};
|
||||
|
||||
struct wait_handler
|
||||
{
|
||||
wait_handler() {}
|
||||
void operator()(const asio::error_code&) {}
|
||||
#if defined(ASIO_HAS_MOVE)
|
||||
wait_handler(wait_handler&&) {}
|
||||
private:
|
||||
wait_handler(const wait_handler&);
|
||||
#endif // defined(ASIO_HAS_MOVE)
|
||||
};
|
||||
|
||||
struct send_handler
|
||||
{
|
||||
send_handler() {}
|
||||
void operator()(const asio::error_code&, std::size_t) {}
|
||||
#if defined(ASIO_HAS_MOVE)
|
||||
send_handler(send_handler&&) {}
|
||||
private:
|
||||
send_handler(const send_handler&);
|
||||
#endif // defined(ASIO_HAS_MOVE)
|
||||
};
|
||||
|
||||
struct receive_handler
|
||||
{
|
||||
receive_handler() {}
|
||||
void operator()(const asio::error_code&, std::size_t) {}
|
||||
#if defined(ASIO_HAS_MOVE)
|
||||
receive_handler(receive_handler&&) {}
|
||||
private:
|
||||
receive_handler(const receive_handler&);
|
||||
#endif // defined(ASIO_HAS_MOVE)
|
||||
};
|
||||
|
||||
void test()
|
||||
{
|
||||
using namespace asio;
|
||||
namespace ip = asio::ip;
|
||||
|
||||
try
|
||||
{
|
||||
io_context ioc;
|
||||
const io_context::executor_type ioc_ex = ioc.get_executor();
|
||||
char mutable_char_buffer[128] = "";
|
||||
const char const_char_buffer[128] = "";
|
||||
socket_base::message_flags in_flags = 0;
|
||||
archetypes::settable_socket_option<void> settable_socket_option1;
|
||||
archetypes::settable_socket_option<int> settable_socket_option2;
|
||||
archetypes::settable_socket_option<double> settable_socket_option3;
|
||||
archetypes::gettable_socket_option<void> gettable_socket_option1;
|
||||
archetypes::gettable_socket_option<int> gettable_socket_option2;
|
||||
archetypes::gettable_socket_option<double> gettable_socket_option3;
|
||||
archetypes::io_control_command io_control_command;
|
||||
archetypes::lazy_handler lazy;
|
||||
asio::error_code ec;
|
||||
|
||||
// basic_datagram_socket constructors.
|
||||
|
||||
ip::udp::socket socket1(ioc);
|
||||
ip::udp::socket socket2(ioc, ip::udp::v4());
|
||||
ip::udp::socket socket3(ioc, ip::udp::v6());
|
||||
ip::udp::socket socket4(ioc, ip::udp::endpoint(ip::udp::v4(), 0));
|
||||
ip::udp::socket socket5(ioc, ip::udp::endpoint(ip::udp::v6(), 0));
|
||||
#if !defined(ASIO_WINDOWS_RUNTIME)
|
||||
ip::udp::socket::native_handle_type native_socket1
|
||||
= ::socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
|
||||
ip::udp::socket socket6(ioc, ip::udp::v4(), native_socket1);
|
||||
#endif // !defined(ASIO_WINDOWS_RUNTIME)
|
||||
|
||||
ip::udp::socket socket7(ioc_ex);
|
||||
ip::udp::socket socket8(ioc_ex, ip::udp::v4());
|
||||
ip::udp::socket socket9(ioc_ex, ip::udp::v6());
|
||||
ip::udp::socket socket10(ioc_ex, ip::udp::endpoint(ip::udp::v4(), 0));
|
||||
ip::udp::socket socket11(ioc_ex, ip::udp::endpoint(ip::udp::v6(), 0));
|
||||
#if !defined(ASIO_WINDOWS_RUNTIME)
|
||||
ip::udp::socket::native_handle_type native_socket2
|
||||
= ::socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
|
||||
ip::udp::socket socket12(ioc_ex, ip::udp::v4(), native_socket2);
|
||||
#endif // !defined(ASIO_WINDOWS_RUNTIME)
|
||||
|
||||
#if defined(ASIO_HAS_MOVE)
|
||||
ip::udp::socket socket13(std::move(socket6));
|
||||
#endif // defined(ASIO_HAS_MOVE)
|
||||
|
||||
// basic_datagram_socket operators.
|
||||
|
||||
#if defined(ASIO_HAS_MOVE)
|
||||
socket1 = ip::udp::socket(ioc);
|
||||
socket1 = std::move(socket2);
|
||||
#endif // defined(ASIO_HAS_MOVE)
|
||||
|
||||
// basic_io_object functions.
|
||||
|
||||
ip::udp::socket::executor_type ex = socket1.get_executor();
|
||||
(void)ex;
|
||||
|
||||
// basic_socket functions.
|
||||
|
||||
ip::udp::socket::lowest_layer_type& lowest_layer = socket1.lowest_layer();
|
||||
(void)lowest_layer;
|
||||
|
||||
const ip::udp::socket& socket14 = socket1;
|
||||
const ip::udp::socket::lowest_layer_type& lowest_layer2
|
||||
= socket14.lowest_layer();
|
||||
(void)lowest_layer2;
|
||||
|
||||
socket1.open(ip::udp::v4());
|
||||
socket1.open(ip::udp::v6());
|
||||
socket1.open(ip::udp::v4(), ec);
|
||||
socket1.open(ip::udp::v6(), ec);
|
||||
|
||||
#if !defined(ASIO_WINDOWS_RUNTIME)
|
||||
ip::udp::socket::native_handle_type native_socket3
|
||||
= ::socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
|
||||
socket1.assign(ip::udp::v4(), native_socket3);
|
||||
ip::udp::socket::native_handle_type native_socket4
|
||||
= ::socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
|
||||
socket1.assign(ip::udp::v4(), native_socket4, ec);
|
||||
#endif // !defined(ASIO_WINDOWS_RUNTIME)
|
||||
|
||||
bool is_open = socket1.is_open();
|
||||
(void)is_open;
|
||||
|
||||
socket1.close();
|
||||
socket1.close(ec);
|
||||
|
||||
socket1.release();
|
||||
socket1.release(ec);
|
||||
|
||||
ip::udp::socket::native_handle_type native_socket5
|
||||
= socket1.native_handle();
|
||||
(void)native_socket5;
|
||||
|
||||
socket1.cancel();
|
||||
socket1.cancel(ec);
|
||||
|
||||
bool at_mark1 = socket1.at_mark();
|
||||
(void)at_mark1;
|
||||
bool at_mark2 = socket1.at_mark(ec);
|
||||
(void)at_mark2;
|
||||
|
||||
std::size_t available1 = socket1.available();
|
||||
(void)available1;
|
||||
std::size_t available2 = socket1.available(ec);
|
||||
(void)available2;
|
||||
|
||||
socket1.bind(ip::udp::endpoint(ip::udp::v4(), 0));
|
||||
socket1.bind(ip::udp::endpoint(ip::udp::v6(), 0));
|
||||
socket1.bind(ip::udp::endpoint(ip::udp::v4(), 0), ec);
|
||||
socket1.bind(ip::udp::endpoint(ip::udp::v6(), 0), ec);
|
||||
|
||||
socket1.connect(ip::udp::endpoint(ip::udp::v4(), 0));
|
||||
socket1.connect(ip::udp::endpoint(ip::udp::v6(), 0));
|
||||
socket1.connect(ip::udp::endpoint(ip::udp::v4(), 0), ec);
|
||||
socket1.connect(ip::udp::endpoint(ip::udp::v6(), 0), ec);
|
||||
|
||||
socket1.async_connect(ip::udp::endpoint(ip::udp::v4(), 0),
|
||||
connect_handler());
|
||||
socket1.async_connect(ip::udp::endpoint(ip::udp::v6(), 0),
|
||||
connect_handler());
|
||||
int i1 = socket1.async_connect(ip::udp::endpoint(ip::udp::v4(), 0), lazy);
|
||||
(void)i1;
|
||||
int i2 = socket1.async_connect(ip::udp::endpoint(ip::udp::v6(), 0), lazy);
|
||||
(void)i2;
|
||||
|
||||
socket1.set_option(settable_socket_option1);
|
||||
socket1.set_option(settable_socket_option1, ec);
|
||||
socket1.set_option(settable_socket_option2);
|
||||
socket1.set_option(settable_socket_option2, ec);
|
||||
socket1.set_option(settable_socket_option3);
|
||||
socket1.set_option(settable_socket_option3, ec);
|
||||
|
||||
socket1.get_option(gettable_socket_option1);
|
||||
socket1.get_option(gettable_socket_option1, ec);
|
||||
socket1.get_option(gettable_socket_option2);
|
||||
socket1.get_option(gettable_socket_option2, ec);
|
||||
socket1.get_option(gettable_socket_option3);
|
||||
socket1.get_option(gettable_socket_option3, ec);
|
||||
|
||||
socket1.io_control(io_control_command);
|
||||
socket1.io_control(io_control_command, ec);
|
||||
|
||||
bool non_blocking1 = socket1.non_blocking();
|
||||
(void)non_blocking1;
|
||||
socket1.non_blocking(true);
|
||||
socket1.non_blocking(false, ec);
|
||||
|
||||
bool non_blocking2 = socket1.native_non_blocking();
|
||||
(void)non_blocking2;
|
||||
socket1.native_non_blocking(true);
|
||||
socket1.native_non_blocking(false, ec);
|
||||
|
||||
ip::udp::endpoint endpoint1 = socket1.local_endpoint();
|
||||
(void)endpoint1;
|
||||
ip::udp::endpoint endpoint2 = socket1.local_endpoint(ec);
|
||||
(void)endpoint2;
|
||||
|
||||
ip::udp::endpoint endpoint3 = socket1.remote_endpoint();
|
||||
(void)endpoint3;
|
||||
ip::udp::endpoint endpoint4 = socket1.remote_endpoint(ec);
|
||||
(void)endpoint4;
|
||||
|
||||
socket1.shutdown(socket_base::shutdown_both);
|
||||
socket1.shutdown(socket_base::shutdown_both, ec);
|
||||
|
||||
socket1.wait(socket_base::wait_read);
|
||||
socket1.wait(socket_base::wait_write, ec);
|
||||
|
||||
socket1.async_wait(socket_base::wait_read, wait_handler());
|
||||
int i3 = socket1.async_wait(socket_base::wait_write, lazy);
|
||||
(void)i3;
|
||||
|
||||
// basic_datagram_socket functions.
|
||||
|
||||
socket1.send(buffer(mutable_char_buffer));
|
||||
socket1.send(buffer(const_char_buffer));
|
||||
socket1.send(null_buffers());
|
||||
socket1.send(buffer(mutable_char_buffer), in_flags);
|
||||
socket1.send(buffer(const_char_buffer), in_flags);
|
||||
socket1.send(null_buffers(), in_flags);
|
||||
socket1.send(buffer(mutable_char_buffer), in_flags, ec);
|
||||
socket1.send(buffer(const_char_buffer), in_flags, ec);
|
||||
socket1.send(null_buffers(), in_flags, ec);
|
||||
|
||||
socket1.async_send(buffer(mutable_char_buffer), send_handler());
|
||||
socket1.async_send(buffer(const_char_buffer), send_handler());
|
||||
socket1.async_send(null_buffers(), send_handler());
|
||||
socket1.async_send(buffer(mutable_char_buffer), in_flags, send_handler());
|
||||
socket1.async_send(buffer(const_char_buffer), in_flags, send_handler());
|
||||
socket1.async_send(null_buffers(), in_flags, send_handler());
|
||||
int i4 = socket1.async_send(buffer(mutable_char_buffer), lazy);
|
||||
(void)i4;
|
||||
int i5 = socket1.async_send(buffer(const_char_buffer), lazy);
|
||||
(void)i5;
|
||||
int i6 = socket1.async_send(null_buffers(), lazy);
|
||||
(void)i6;
|
||||
int i7 = socket1.async_send(buffer(mutable_char_buffer), in_flags, lazy);
|
||||
(void)i7;
|
||||
int i8 = socket1.async_send(buffer(const_char_buffer), in_flags, lazy);
|
||||
(void)i8;
|
||||
int i9 = socket1.async_send(null_buffers(), in_flags, lazy);
|
||||
(void)i9;
|
||||
|
||||
socket1.send_to(buffer(mutable_char_buffer),
|
||||
ip::udp::endpoint(ip::udp::v4(), 0));
|
||||
socket1.send_to(buffer(mutable_char_buffer),
|
||||
ip::udp::endpoint(ip::udp::v6(), 0));
|
||||
socket1.send_to(buffer(const_char_buffer),
|
||||
ip::udp::endpoint(ip::udp::v4(), 0));
|
||||
socket1.send_to(buffer(const_char_buffer),
|
||||
ip::udp::endpoint(ip::udp::v6(), 0));
|
||||
socket1.send_to(null_buffers(),
|
||||
ip::udp::endpoint(ip::udp::v4(), 0));
|
||||
socket1.send_to(null_buffers(),
|
||||
ip::udp::endpoint(ip::udp::v6(), 0));
|
||||
socket1.send_to(buffer(mutable_char_buffer),
|
||||
ip::udp::endpoint(ip::udp::v4(), 0), in_flags);
|
||||
socket1.send_to(buffer(mutable_char_buffer),
|
||||
ip::udp::endpoint(ip::udp::v6(), 0), in_flags);
|
||||
socket1.send_to(buffer(const_char_buffer),
|
||||
ip::udp::endpoint(ip::udp::v4(), 0), in_flags);
|
||||
socket1.send_to(buffer(const_char_buffer),
|
||||
ip::udp::endpoint(ip::udp::v6(), 0), in_flags);
|
||||
socket1.send_to(null_buffers(),
|
||||
ip::udp::endpoint(ip::udp::v4(), 0), in_flags);
|
||||
socket1.send_to(null_buffers(),
|
||||
ip::udp::endpoint(ip::udp::v6(), 0), in_flags);
|
||||
socket1.send_to(buffer(mutable_char_buffer),
|
||||
ip::udp::endpoint(ip::udp::v4(), 0), in_flags, ec);
|
||||
socket1.send_to(buffer(mutable_char_buffer),
|
||||
ip::udp::endpoint(ip::udp::v6(), 0), in_flags, ec);
|
||||
socket1.send_to(buffer(const_char_buffer),
|
||||
ip::udp::endpoint(ip::udp::v4(), 0), in_flags, ec);
|
||||
socket1.send_to(buffer(const_char_buffer),
|
||||
ip::udp::endpoint(ip::udp::v6(), 0), in_flags, ec);
|
||||
socket1.send_to(null_buffers(),
|
||||
ip::udp::endpoint(ip::udp::v4(), 0), in_flags, ec);
|
||||
socket1.send_to(null_buffers(),
|
||||
ip::udp::endpoint(ip::udp::v6(), 0), in_flags, ec);
|
||||
|
||||
socket1.async_send_to(buffer(mutable_char_buffer),
|
||||
ip::udp::endpoint(ip::udp::v4(), 0), send_handler());
|
||||
socket1.async_send_to(buffer(mutable_char_buffer),
|
||||
ip::udp::endpoint(ip::udp::v6(), 0), send_handler());
|
||||
socket1.async_send_to(buffer(const_char_buffer),
|
||||
ip::udp::endpoint(ip::udp::v4(), 0), send_handler());
|
||||
socket1.async_send_to(buffer(const_char_buffer),
|
||||
ip::udp::endpoint(ip::udp::v6(), 0), send_handler());
|
||||
socket1.async_send_to(null_buffers(),
|
||||
ip::udp::endpoint(ip::udp::v4(), 0), send_handler());
|
||||
socket1.async_send_to(null_buffers(),
|
||||
ip::udp::endpoint(ip::udp::v6(), 0), send_handler());
|
||||
socket1.async_send_to(buffer(mutable_char_buffer),
|
||||
ip::udp::endpoint(ip::udp::v4(), 0), in_flags, send_handler());
|
||||
socket1.async_send_to(buffer(mutable_char_buffer),
|
||||
ip::udp::endpoint(ip::udp::v6(), 0), in_flags, send_handler());
|
||||
socket1.async_send_to(buffer(const_char_buffer),
|
||||
ip::udp::endpoint(ip::udp::v4(), 0), in_flags, send_handler());
|
||||
socket1.async_send_to(buffer(const_char_buffer),
|
||||
ip::udp::endpoint(ip::udp::v6(), 0), in_flags, send_handler());
|
||||
socket1.async_send_to(null_buffers(),
|
||||
ip::udp::endpoint(ip::udp::v4(), 0), in_flags, send_handler());
|
||||
socket1.async_send_to(null_buffers(),
|
||||
ip::udp::endpoint(ip::udp::v6(), 0), in_flags, send_handler());
|
||||
int i10 = socket1.async_send_to(buffer(mutable_char_buffer),
|
||||
ip::udp::endpoint(ip::udp::v4(), 0), lazy);
|
||||
(void)i10;
|
||||
int i11 = socket1.async_send_to(buffer(mutable_char_buffer),
|
||||
ip::udp::endpoint(ip::udp::v6(), 0), lazy);
|
||||
(void)i11;
|
||||
int i12 = socket1.async_send_to(buffer(const_char_buffer),
|
||||
ip::udp::endpoint(ip::udp::v4(), 0), lazy);
|
||||
(void)i12;
|
||||
int i13 = socket1.async_send_to(buffer(const_char_buffer),
|
||||
ip::udp::endpoint(ip::udp::v6(), 0), lazy);
|
||||
(void)i13;
|
||||
int i14 = socket1.async_send_to(null_buffers(),
|
||||
ip::udp::endpoint(ip::udp::v4(), 0), lazy);
|
||||
(void)i14;
|
||||
int i15 = socket1.async_send_to(null_buffers(),
|
||||
ip::udp::endpoint(ip::udp::v6(), 0), lazy);
|
||||
(void)i15;
|
||||
int i16 = socket1.async_send_to(buffer(mutable_char_buffer),
|
||||
ip::udp::endpoint(ip::udp::v4(), 0), in_flags, lazy);
|
||||
(void)i16;
|
||||
int i17 = socket1.async_send_to(buffer(mutable_char_buffer),
|
||||
ip::udp::endpoint(ip::udp::v6(), 0), in_flags, lazy);
|
||||
(void)i17;
|
||||
int i18 = socket1.async_send_to(buffer(const_char_buffer),
|
||||
ip::udp::endpoint(ip::udp::v4(), 0), in_flags, lazy);
|
||||
(void)i18;
|
||||
int i19 = socket1.async_send_to(buffer(const_char_buffer),
|
||||
ip::udp::endpoint(ip::udp::v6(), 0), in_flags, lazy);
|
||||
(void)i19;
|
||||
int i20 = socket1.async_send_to(null_buffers(),
|
||||
ip::udp::endpoint(ip::udp::v4(), 0), in_flags, lazy);
|
||||
(void)i20;
|
||||
int i21 = socket1.async_send_to(null_buffers(),
|
||||
ip::udp::endpoint(ip::udp::v6(), 0), in_flags, lazy);
|
||||
(void)i21;
|
||||
|
||||
socket1.receive(buffer(mutable_char_buffer));
|
||||
socket1.receive(null_buffers());
|
||||
socket1.receive(buffer(mutable_char_buffer), in_flags);
|
||||
socket1.receive(null_buffers(), in_flags);
|
||||
socket1.receive(buffer(mutable_char_buffer), in_flags, ec);
|
||||
socket1.receive(null_buffers(), in_flags, ec);
|
||||
|
||||
socket1.async_receive(buffer(mutable_char_buffer), receive_handler());
|
||||
socket1.async_receive(null_buffers(), receive_handler());
|
||||
socket1.async_receive(buffer(mutable_char_buffer), in_flags,
|
||||
receive_handler());
|
||||
socket1.async_receive(null_buffers(), in_flags, receive_handler());
|
||||
int i22 = socket1.async_receive(buffer(mutable_char_buffer), lazy);
|
||||
(void)i22;
|
||||
int i23 = socket1.async_receive(null_buffers(), lazy);
|
||||
(void)i23;
|
||||
int i24 = socket1.async_receive(buffer(mutable_char_buffer),
|
||||
in_flags, lazy);
|
||||
(void)i24;
|
||||
int i25 = socket1.async_receive(null_buffers(), in_flags, lazy);
|
||||
(void)i25;
|
||||
|
||||
ip::udp::endpoint endpoint;
|
||||
socket1.receive_from(buffer(mutable_char_buffer), endpoint);
|
||||
socket1.receive_from(null_buffers(), endpoint);
|
||||
socket1.receive_from(buffer(mutable_char_buffer), endpoint, in_flags);
|
||||
socket1.receive_from(null_buffers(), endpoint, in_flags);
|
||||
socket1.receive_from(buffer(mutable_char_buffer), endpoint, in_flags, ec);
|
||||
socket1.receive_from(null_buffers(), endpoint, in_flags, ec);
|
||||
|
||||
socket1.async_receive_from(buffer(mutable_char_buffer),
|
||||
endpoint, receive_handler());
|
||||
socket1.async_receive_from(null_buffers(),
|
||||
endpoint, receive_handler());
|
||||
socket1.async_receive_from(buffer(mutable_char_buffer),
|
||||
endpoint, in_flags, receive_handler());
|
||||
socket1.async_receive_from(null_buffers(),
|
||||
endpoint, in_flags, receive_handler());
|
||||
int i26 = socket1.async_receive_from(buffer(mutable_char_buffer),
|
||||
endpoint, lazy);
|
||||
(void)i26;
|
||||
int i27 = socket1.async_receive_from(null_buffers(),
|
||||
endpoint, lazy);
|
||||
(void)i27;
|
||||
int i28 = socket1.async_receive_from(buffer(mutable_char_buffer),
|
||||
endpoint, in_flags, lazy);
|
||||
(void)i28;
|
||||
int i29 = socket1.async_receive_from(null_buffers(),
|
||||
endpoint, in_flags, lazy);
|
||||
(void)i29;
|
||||
}
|
||||
catch (std::exception&)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace ip_udp_socket_compile
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
// ip_udp_socket_runtime test
|
||||
// ~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
// The following test checks the runtime operation of the ip::udp::socket class.
|
||||
|
||||
namespace ip_udp_socket_runtime {
|
||||
|
||||
void handle_send(size_t expected_bytes_sent,
|
||||
const asio::error_code& err, size_t bytes_sent)
|
||||
{
|
||||
ASIO_CHECK(!err);
|
||||
ASIO_CHECK(expected_bytes_sent == bytes_sent);
|
||||
}
|
||||
|
||||
void handle_recv(size_t expected_bytes_recvd,
|
||||
const asio::error_code& err, size_t bytes_recvd)
|
||||
{
|
||||
ASIO_CHECK(!err);
|
||||
ASIO_CHECK(expected_bytes_recvd == bytes_recvd);
|
||||
}
|
||||
|
||||
void test()
|
||||
{
|
||||
using namespace std; // For memcmp and memset.
|
||||
using namespace asio;
|
||||
namespace ip = asio::ip;
|
||||
|
||||
#if defined(ASIO_HAS_BOOST_BIND)
|
||||
namespace bindns = boost;
|
||||
#else // defined(ASIO_HAS_BOOST_BIND)
|
||||
namespace bindns = std;
|
||||
using std::placeholders::_1;
|
||||
using std::placeholders::_2;
|
||||
#endif // defined(ASIO_HAS_BOOST_BIND)
|
||||
|
||||
io_context ioc;
|
||||
|
||||
ip::udp::socket s1(ioc, ip::udp::endpoint(ip::udp::v4(), 0));
|
||||
ip::udp::endpoint target_endpoint = s1.local_endpoint();
|
||||
target_endpoint.address(ip::address_v4::loopback());
|
||||
|
||||
ip::udp::socket s2(ioc);
|
||||
s2.open(ip::udp::v4());
|
||||
s2.bind(ip::udp::endpoint(ip::udp::v4(), 0));
|
||||
char send_msg[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
|
||||
s2.send_to(buffer(send_msg, sizeof(send_msg)), target_endpoint);
|
||||
|
||||
char recv_msg[sizeof(send_msg)];
|
||||
ip::udp::endpoint sender_endpoint;
|
||||
size_t bytes_recvd = s1.receive_from(buffer(recv_msg, sizeof(recv_msg)),
|
||||
sender_endpoint);
|
||||
|
||||
ASIO_CHECK(bytes_recvd == sizeof(send_msg));
|
||||
ASIO_CHECK(memcmp(send_msg, recv_msg, sizeof(send_msg)) == 0);
|
||||
|
||||
memset(recv_msg, 0, sizeof(recv_msg));
|
||||
|
||||
target_endpoint = sender_endpoint;
|
||||
s1.async_send_to(buffer(send_msg, sizeof(send_msg)), target_endpoint,
|
||||
bindns::bind(handle_send, sizeof(send_msg), _1, _2));
|
||||
s2.async_receive_from(buffer(recv_msg, sizeof(recv_msg)), sender_endpoint,
|
||||
bindns::bind(handle_recv, sizeof(recv_msg), _1, _2));
|
||||
|
||||
ioc.run();
|
||||
|
||||
ASIO_CHECK(memcmp(send_msg, recv_msg, sizeof(send_msg)) == 0);
|
||||
}
|
||||
|
||||
} // namespace ip_udp_socket_runtime
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
// ip_udp_resolver_compile test
|
||||
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
// The following test checks that all public member functions on the class
|
||||
// ip::udp::resolver compile and link correctly. Runtime failures are ignored.
|
||||
|
||||
namespace ip_udp_resolver_compile {
|
||||
|
||||
struct resolve_handler
|
||||
{
|
||||
resolve_handler() {}
|
||||
void operator()(const asio::error_code&,
|
||||
asio::ip::udp::resolver::results_type) {}
|
||||
#if defined(ASIO_HAS_MOVE)
|
||||
resolve_handler(resolve_handler&&) {}
|
||||
private:
|
||||
resolve_handler(const resolve_handler&);
|
||||
#endif // defined(ASIO_HAS_MOVE)
|
||||
};
|
||||
|
||||
void test()
|
||||
{
|
||||
using namespace asio;
|
||||
namespace ip = asio::ip;
|
||||
|
||||
try
|
||||
{
|
||||
io_context ioc;
|
||||
const io_context::executor_type ioc_ex = ioc.get_executor();
|
||||
archetypes::lazy_handler lazy;
|
||||
asio::error_code ec;
|
||||
#if !defined(ASIO_NO_DEPRECATED)
|
||||
ip::udp::resolver::query q(ip::udp::v4(), "localhost", "0");
|
||||
#endif // !defined(ASIO_NO_DEPRECATED)
|
||||
ip::udp::endpoint e(ip::address_v4::loopback(), 0);
|
||||
|
||||
// basic_resolver constructors.
|
||||
|
||||
ip::udp::resolver resolver(ioc);
|
||||
ip::udp::resolver resolver2(ioc_ex);
|
||||
|
||||
#if defined(ASIO_HAS_MOVE)
|
||||
ip::udp::resolver resolver3(std::move(resolver));
|
||||
#endif // defined(ASIO_HAS_MOVE)
|
||||
|
||||
// basic_resolver operators.
|
||||
|
||||
#if defined(ASIO_HAS_MOVE)
|
||||
resolver = ip::udp::resolver(ioc);
|
||||
resolver = std::move(resolver3);
|
||||
#endif // defined(ASIO_HAS_MOVE)
|
||||
|
||||
// basic_io_object functions.
|
||||
|
||||
ip::udp::resolver::executor_type ex = resolver.get_executor();
|
||||
(void)ex;
|
||||
|
||||
// basic_resolver functions.
|
||||
|
||||
resolver.cancel();
|
||||
|
||||
#if !defined(ASIO_NO_DEPRECATED)
|
||||
ip::udp::resolver::results_type results1 = resolver.resolve(q);
|
||||
(void)results1;
|
||||
|
||||
ip::udp::resolver::results_type results2 = resolver.resolve(q, ec);
|
||||
(void)results2;
|
||||
#endif // !defined(ASIO_NO_DEPRECATED)
|
||||
|
||||
ip::udp::resolver::results_type results3 = resolver.resolve("", "");
|
||||
(void)results3;
|
||||
|
||||
ip::udp::resolver::results_type results4 = resolver.resolve("", "", ec);
|
||||
(void)results4;
|
||||
|
||||
ip::udp::resolver::results_type results5 =
|
||||
resolver.resolve("", "", ip::udp::resolver::flags());
|
||||
(void)results5;
|
||||
|
||||
ip::udp::resolver::results_type results6 =
|
||||
resolver.resolve("", "", ip::udp::resolver::flags(), ec);
|
||||
(void)results6;
|
||||
|
||||
ip::udp::resolver::results_type results7 =
|
||||
resolver.resolve(ip::udp::v4(), "", "");
|
||||
(void)results7;
|
||||
|
||||
ip::udp::resolver::results_type results8 =
|
||||
resolver.resolve(ip::udp::v4(), "", "", ec);
|
||||
(void)results8;
|
||||
|
||||
ip::udp::resolver::results_type results9 =
|
||||
resolver.resolve(ip::udp::v4(), "", "", ip::udp::resolver::flags());
|
||||
(void)results9;
|
||||
|
||||
ip::udp::resolver::results_type results10 =
|
||||
resolver.resolve(ip::udp::v4(), "", "", ip::udp::resolver::flags(), ec);
|
||||
(void)results10;
|
||||
|
||||
ip::udp::resolver::results_type results11 = resolver.resolve(e);
|
||||
(void)results11;
|
||||
|
||||
ip::udp::resolver::results_type results12 = resolver.resolve(e, ec);
|
||||
(void)results12;
|
||||
|
||||
#if !defined(ASIO_NO_DEPRECATED)
|
||||
resolver.async_resolve(q, resolve_handler());
|
||||
int i1 = resolver.async_resolve(q, lazy);
|
||||
(void)i1;
|
||||
#endif // !defined(ASIO_NO_DEPRECATED)
|
||||
|
||||
resolver.async_resolve("", "", resolve_handler());
|
||||
int i2 = resolver.async_resolve("", "", lazy);
|
||||
(void)i2;
|
||||
|
||||
resolver.async_resolve("", "",
|
||||
ip::udp::resolver::flags(), resolve_handler());
|
||||
int i3 = resolver.async_resolve("", "",
|
||||
ip::udp::resolver::flags(), lazy);
|
||||
(void)i3;
|
||||
|
||||
resolver.async_resolve(ip::udp::v4(), "", "", resolve_handler());
|
||||
int i4 = resolver.async_resolve(ip::udp::v4(), "", "", lazy);
|
||||
(void)i4;
|
||||
|
||||
resolver.async_resolve(ip::udp::v4(),
|
||||
"", "", ip::udp::resolver::flags(), resolve_handler());
|
||||
int i5 = resolver.async_resolve(ip::udp::v4(),
|
||||
"", "", ip::udp::resolver::flags(), lazy);
|
||||
(void)i5;
|
||||
|
||||
resolver.async_resolve(e, resolve_handler());
|
||||
int i6 = resolver.async_resolve(e, lazy);
|
||||
(void)i6;
|
||||
}
|
||||
catch (std::exception&)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace ip_udp_resolver_compile
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
ASIO_TEST_SUITE
|
||||
(
|
||||
"ip/udp",
|
||||
ASIO_TEST_CASE(ip_udp_socket_compile::test)
|
||||
ASIO_TEST_CASE(ip_udp_socket_runtime::test)
|
||||
ASIO_TEST_CASE(ip_udp_resolver_compile::test)
|
||||
)
|
||||
@@ -0,0 +1,171 @@
|
||||
//
|
||||
// unicast.cpp
|
||||
// ~~~~~~~~~~~
|
||||
//
|
||||
// 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)
|
||||
//
|
||||
|
||||
// Disable autolinking for unit tests.
|
||||
#if !defined(BOOST_ALL_NO_LIB)
|
||||
#define BOOST_ALL_NO_LIB 1
|
||||
#endif // !defined(BOOST_ALL_NO_LIB)
|
||||
|
||||
// Test that header file is self-contained.
|
||||
#include "asio/ip/unicast.hpp"
|
||||
|
||||
#include "asio/io_context.hpp"
|
||||
#include "asio/ip/udp.hpp"
|
||||
#include "../unit_test.hpp"
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
// ip_unicast_compile test
|
||||
// ~~~~~~~~~~~~~~~~~~~~~~~
|
||||
// The following test checks that all nested classes, enums and constants in
|
||||
// ip::unicast compile and link correctly. Runtime failures are ignored.
|
||||
|
||||
namespace ip_unicast_compile {
|
||||
|
||||
void test()
|
||||
{
|
||||
using namespace asio;
|
||||
namespace ip = asio::ip;
|
||||
|
||||
try
|
||||
{
|
||||
io_context ioc;
|
||||
ip::udp::socket sock(ioc);
|
||||
|
||||
// hops class.
|
||||
|
||||
ip::unicast::hops hops1(1024);
|
||||
sock.set_option(hops1);
|
||||
ip::unicast::hops hops2;
|
||||
sock.get_option(hops2);
|
||||
hops1 = 1;
|
||||
(void)static_cast<int>(hops1.value());
|
||||
}
|
||||
catch (std::exception&)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace ip_unicast_compile
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
// ip_unicast_runtime test
|
||||
// ~~~~~~~~~~~~~~~~~~~~~~~
|
||||
// The following test checks the runtime operation of the socket options defined
|
||||
// in the ip::unicast namespace.
|
||||
|
||||
namespace ip_unicast_runtime {
|
||||
|
||||
void test()
|
||||
{
|
||||
using namespace asio;
|
||||
namespace ip = asio::ip;
|
||||
|
||||
io_context ioc;
|
||||
asio::error_code ec;
|
||||
|
||||
ip::udp::endpoint ep_v4(ip::address_v4::loopback(), 0);
|
||||
ip::udp::socket sock_v4(ioc);
|
||||
sock_v4.open(ep_v4.protocol(), ec);
|
||||
sock_v4.bind(ep_v4, ec);
|
||||
bool have_v4 = !ec;
|
||||
|
||||
ip::udp::endpoint ep_v6(ip::address_v6::loopback(), 0);
|
||||
ip::udp::socket sock_v6(ioc);
|
||||
sock_v6.open(ep_v6.protocol(), ec);
|
||||
sock_v6.bind(ep_v6, ec);
|
||||
bool have_v6 = !ec;
|
||||
|
||||
ASIO_CHECK(have_v4 || have_v6);
|
||||
|
||||
// hops class.
|
||||
|
||||
if (have_v4)
|
||||
{
|
||||
ip::unicast::hops hops1(1);
|
||||
ASIO_CHECK(hops1.value() == 1);
|
||||
sock_v4.set_option(hops1, ec);
|
||||
#if defined(ASIO_WINDOWS) && defined(UNDER_CE)
|
||||
// Option is not supported under Windows CE.
|
||||
ASIO_CHECK_MESSAGE(ec == asio::error::no_protocol_option,
|
||||
ec.value() << ", " << ec.message());
|
||||
#else // defined(ASIO_WINDOWS) && defined(UNDER_CE)
|
||||
ASIO_CHECK(!ec);
|
||||
#endif // defined(ASIO_WINDOWS) && defined(UNDER_CE)
|
||||
|
||||
ip::unicast::hops hops2;
|
||||
sock_v4.get_option(hops2, ec);
|
||||
#if defined(ASIO_WINDOWS) && defined(UNDER_CE)
|
||||
// Option is not supported under Windows CE.
|
||||
ASIO_CHECK_MESSAGE(ec == asio::error::no_protocol_option,
|
||||
ec.value() << ", " << ec.message());
|
||||
#else // defined(ASIO_WINDOWS) && defined(UNDER_CE)
|
||||
ASIO_CHECK(!ec);
|
||||
ASIO_CHECK(hops2.value() == 1);
|
||||
#endif // defined(ASIO_WINDOWS) && defined(UNDER_CE)
|
||||
|
||||
ip::unicast::hops hops3(255);
|
||||
ASIO_CHECK(hops3.value() == 255);
|
||||
sock_v4.set_option(hops3, ec);
|
||||
#if defined(ASIO_WINDOWS) && defined(UNDER_CE)
|
||||
// Option is not supported under Windows CE.
|
||||
ASIO_CHECK_MESSAGE(ec == asio::error::no_protocol_option,
|
||||
ec.value() << ", " << ec.message());
|
||||
#else // defined(ASIO_WINDOWS) && defined(UNDER_CE)
|
||||
ASIO_CHECK(!ec);
|
||||
#endif // defined(ASIO_WINDOWS) && defined(UNDER_CE)
|
||||
|
||||
ip::unicast::hops hops4;
|
||||
sock_v4.get_option(hops4, ec);
|
||||
#if defined(ASIO_WINDOWS) && defined(UNDER_CE)
|
||||
// Option is not supported under Windows CE.
|
||||
ASIO_CHECK_MESSAGE(ec == asio::error::no_protocol_option,
|
||||
ec.value() << ", " << ec.message());
|
||||
#else // defined(ASIO_WINDOWS) && defined(UNDER_CE)
|
||||
ASIO_CHECK(!ec);
|
||||
ASIO_CHECK(hops4.value() == 255);
|
||||
#endif // defined(ASIO_WINDOWS) && defined(UNDER_CE)
|
||||
}
|
||||
|
||||
if (have_v6)
|
||||
{
|
||||
ip::unicast::hops hops1(1);
|
||||
ASIO_CHECK(hops1.value() == 1);
|
||||
sock_v6.set_option(hops1, ec);
|
||||
ASIO_CHECK(!ec);
|
||||
|
||||
ip::unicast::hops hops2;
|
||||
sock_v6.get_option(hops2, ec);
|
||||
ASIO_CHECK(!ec);
|
||||
ASIO_CHECK(hops2.value() == 1);
|
||||
|
||||
ip::unicast::hops hops3(255);
|
||||
ASIO_CHECK(hops3.value() == 255);
|
||||
sock_v6.set_option(hops3, ec);
|
||||
ASIO_CHECK(!ec);
|
||||
|
||||
ip::unicast::hops hops4;
|
||||
sock_v6.get_option(hops4, ec);
|
||||
ASIO_CHECK(!ec);
|
||||
ASIO_CHECK(hops4.value() == 255);
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace ip_unicast_runtime
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
ASIO_TEST_SUITE
|
||||
(
|
||||
"ip/unicast",
|
||||
ASIO_TEST_CASE(ip_unicast_compile::test)
|
||||
ASIO_TEST_CASE(ip_unicast_runtime::test)
|
||||
)
|
||||
@@ -0,0 +1,135 @@
|
||||
//
|
||||
// v6_only.cpp
|
||||
// ~~~~~~~~~~~
|
||||
//
|
||||
// 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)
|
||||
//
|
||||
|
||||
// Disable autolinking for unit tests.
|
||||
#if !defined(BOOST_ALL_NO_LIB)
|
||||
#define BOOST_ALL_NO_LIB 1
|
||||
#endif // !defined(BOOST_ALL_NO_LIB)
|
||||
|
||||
// Test that header file is self-contained.
|
||||
#include "asio/ip/v6_only.hpp"
|
||||
|
||||
#include "asio/io_context.hpp"
|
||||
#include "asio/ip/tcp.hpp"
|
||||
#include "asio/ip/udp.hpp"
|
||||
#include "../unit_test.hpp"
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
// ip_v6_only_compile test
|
||||
// ~~~~~~~~~~~~~~~~~~~~~~~
|
||||
// The following test checks that the ip::v6_only socket option compiles and
|
||||
// link correctly. Runtime failures are ignored.
|
||||
|
||||
namespace ip_v6_only_compile {
|
||||
|
||||
void test()
|
||||
{
|
||||
using namespace asio;
|
||||
namespace ip = asio::ip;
|
||||
|
||||
try
|
||||
{
|
||||
io_context ioc;
|
||||
ip::udp::socket sock(ioc);
|
||||
|
||||
// v6_only class.
|
||||
|
||||
ip::v6_only v6_only1(true);
|
||||
sock.set_option(v6_only1);
|
||||
ip::v6_only v6_only2;
|
||||
sock.get_option(v6_only2);
|
||||
v6_only1 = true;
|
||||
(void)static_cast<bool>(v6_only1);
|
||||
(void)static_cast<bool>(!v6_only1);
|
||||
(void)static_cast<bool>(v6_only1.value());
|
||||
}
|
||||
catch (std::exception&)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace ip_v6_only_compile
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
// ip_v6_only_runtime test
|
||||
// ~~~~~~~~~~~~~~~~~~~~~~~
|
||||
// The following test checks the runtime operation of the ip::v6_only socket
|
||||
// option.
|
||||
|
||||
namespace ip_v6_only_runtime {
|
||||
|
||||
void test()
|
||||
{
|
||||
using namespace asio;
|
||||
namespace ip = asio::ip;
|
||||
|
||||
io_context ioc;
|
||||
asio::error_code ec;
|
||||
|
||||
ip::tcp::endpoint ep_v6(ip::address_v6::loopback(), 0);
|
||||
ip::tcp::acceptor acceptor_v6(ioc);
|
||||
acceptor_v6.open(ep_v6.protocol(), ec);
|
||||
acceptor_v6.bind(ep_v6, ec);
|
||||
bool have_v6 = !ec;
|
||||
acceptor_v6.close(ec);
|
||||
acceptor_v6.open(ep_v6.protocol(), ec);
|
||||
|
||||
if (have_v6)
|
||||
{
|
||||
ip::v6_only v6_only1;
|
||||
acceptor_v6.get_option(v6_only1, ec);
|
||||
ASIO_CHECK(!ec);
|
||||
bool have_dual_stack = !v6_only1.value();
|
||||
|
||||
if (have_dual_stack)
|
||||
{
|
||||
ip::v6_only v6_only2(false);
|
||||
ASIO_CHECK(!v6_only2.value());
|
||||
ASIO_CHECK(!static_cast<bool>(v6_only2));
|
||||
ASIO_CHECK(!v6_only2);
|
||||
acceptor_v6.set_option(v6_only2, ec);
|
||||
ASIO_CHECK(!ec);
|
||||
|
||||
ip::v6_only v6_only3;
|
||||
acceptor_v6.get_option(v6_only3, ec);
|
||||
ASIO_CHECK(!ec);
|
||||
ASIO_CHECK(!v6_only3.value());
|
||||
ASIO_CHECK(!static_cast<bool>(v6_only3));
|
||||
ASIO_CHECK(!v6_only3);
|
||||
|
||||
ip::v6_only v6_only4(true);
|
||||
ASIO_CHECK(v6_only4.value());
|
||||
ASIO_CHECK(static_cast<bool>(v6_only4));
|
||||
ASIO_CHECK(!!v6_only4);
|
||||
acceptor_v6.set_option(v6_only4, ec);
|
||||
ASIO_CHECK(!ec);
|
||||
|
||||
ip::v6_only v6_only5;
|
||||
acceptor_v6.get_option(v6_only5, ec);
|
||||
ASIO_CHECK(!ec);
|
||||
ASIO_CHECK(v6_only5.value());
|
||||
ASIO_CHECK(static_cast<bool>(v6_only5));
|
||||
ASIO_CHECK(!!v6_only5);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace ip_v6_only_runtime
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
ASIO_TEST_SUITE
|
||||
(
|
||||
"ip/v6_only",
|
||||
ASIO_TEST_CASE(ip_v6_only_compile::test)
|
||||
ASIO_TEST_CASE(ip_v6_only_runtime::test)
|
||||
)
|
||||
@@ -0,0 +1,129 @@
|
||||
//
|
||||
// is_read_buffered.cpp
|
||||
// ~~~~~~~~~~~~~~~~~~~~
|
||||
//
|
||||
// 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)
|
||||
//
|
||||
|
||||
// Disable autolinking for unit tests.
|
||||
#if !defined(BOOST_ALL_NO_LIB)
|
||||
#define BOOST_ALL_NO_LIB 1
|
||||
#endif // !defined(BOOST_ALL_NO_LIB)
|
||||
|
||||
// Test that header file is self-contained.
|
||||
#include "asio/is_read_buffered.hpp"
|
||||
|
||||
#include "asio/buffered_read_stream.hpp"
|
||||
#include "asio/buffered_write_stream.hpp"
|
||||
#include "asio/io_context.hpp"
|
||||
#include "asio/ip/tcp.hpp"
|
||||
#include "unit_test.hpp"
|
||||
|
||||
using namespace std; // For memcmp, memcpy and memset.
|
||||
|
||||
class test_stream
|
||||
{
|
||||
public:
|
||||
typedef asio::io_context io_context_type;
|
||||
|
||||
typedef test_stream lowest_layer_type;
|
||||
|
||||
typedef io_context_type::executor_type executor_type;
|
||||
|
||||
test_stream(asio::io_context& io_context)
|
||||
: io_context_(io_context)
|
||||
{
|
||||
}
|
||||
|
||||
io_context_type& io_context()
|
||||
{
|
||||
return io_context_;
|
||||
}
|
||||
|
||||
lowest_layer_type& lowest_layer()
|
||||
{
|
||||
return *this;
|
||||
}
|
||||
|
||||
template <typename Const_Buffers>
|
||||
size_t write(const Const_Buffers&)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
template <typename Const_Buffers>
|
||||
size_t write(const Const_Buffers&, asio::error_code& ec)
|
||||
{
|
||||
ec = asio::error_code();
|
||||
return 0;
|
||||
}
|
||||
|
||||
template <typename Const_Buffers, typename Handler>
|
||||
void async_write(const Const_Buffers&, Handler handler)
|
||||
{
|
||||
asio::error_code error;
|
||||
asio::post(io_context_,
|
||||
asio::detail::bind_handler(handler, error, 0));
|
||||
}
|
||||
|
||||
template <typename Mutable_Buffers>
|
||||
size_t read(const Mutable_Buffers&)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
template <typename Mutable_Buffers>
|
||||
size_t read(const Mutable_Buffers&, asio::error_code& ec)
|
||||
{
|
||||
ec = asio::error_code();
|
||||
return 0;
|
||||
}
|
||||
|
||||
template <typename Mutable_Buffers, typename Handler>
|
||||
void async_read(const Mutable_Buffers&, Handler handler)
|
||||
{
|
||||
asio::error_code error;
|
||||
asio::post(io_context_,
|
||||
asio::detail::bind_handler(handler, error, 0));
|
||||
}
|
||||
|
||||
private:
|
||||
io_context_type& io_context_;
|
||||
};
|
||||
|
||||
void is_read_buffered_test()
|
||||
{
|
||||
ASIO_CHECK(!asio::is_read_buffered<
|
||||
asio::ip::tcp::socket>::value);
|
||||
|
||||
ASIO_CHECK(!!asio::is_read_buffered<
|
||||
asio::buffered_read_stream<
|
||||
asio::ip::tcp::socket> >::value);
|
||||
|
||||
ASIO_CHECK(!asio::is_read_buffered<
|
||||
asio::buffered_write_stream<
|
||||
asio::ip::tcp::socket> >::value);
|
||||
|
||||
ASIO_CHECK(!!asio::is_read_buffered<
|
||||
asio::buffered_stream<asio::ip::tcp::socket> >::value);
|
||||
|
||||
ASIO_CHECK(!asio::is_read_buffered<test_stream>::value);
|
||||
|
||||
ASIO_CHECK(!!asio::is_read_buffered<
|
||||
asio::buffered_read_stream<test_stream> >::value);
|
||||
|
||||
ASIO_CHECK(!asio::is_read_buffered<
|
||||
asio::buffered_write_stream<test_stream> >::value);
|
||||
|
||||
ASIO_CHECK(!!asio::is_read_buffered<
|
||||
asio::buffered_stream<test_stream> >::value);
|
||||
}
|
||||
|
||||
ASIO_TEST_SUITE
|
||||
(
|
||||
"is_read_buffered",
|
||||
ASIO_TEST_CASE(is_read_buffered_test)
|
||||
)
|
||||
@@ -0,0 +1,129 @@
|
||||
//
|
||||
// is_write_buffered.cpp
|
||||
// ~~~~~~~~~~~~~~~~~~~~~
|
||||
//
|
||||
// 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)
|
||||
//
|
||||
|
||||
// Disable autolinking for unit tests.
|
||||
#if !defined(BOOST_ALL_NO_LIB)
|
||||
#define BOOST_ALL_NO_LIB 1
|
||||
#endif // !defined(BOOST_ALL_NO_LIB)
|
||||
|
||||
// Test that header file is self-contained.
|
||||
#include "asio/is_write_buffered.hpp"
|
||||
|
||||
#include "asio/buffered_read_stream.hpp"
|
||||
#include "asio/buffered_write_stream.hpp"
|
||||
#include "asio/io_context.hpp"
|
||||
#include "asio/ip/tcp.hpp"
|
||||
#include "unit_test.hpp"
|
||||
|
||||
using namespace std; // For memcmp, memcpy and memset.
|
||||
|
||||
class test_stream
|
||||
{
|
||||
public:
|
||||
typedef asio::io_context io_context_type;
|
||||
|
||||
typedef test_stream lowest_layer_type;
|
||||
|
||||
typedef io_context_type::executor_type executor_type;
|
||||
|
||||
test_stream(asio::io_context& io_context)
|
||||
: io_context_(io_context)
|
||||
{
|
||||
}
|
||||
|
||||
io_context_type& io_context()
|
||||
{
|
||||
return io_context_;
|
||||
}
|
||||
|
||||
lowest_layer_type& lowest_layer()
|
||||
{
|
||||
return *this;
|
||||
}
|
||||
|
||||
template <typename Const_Buffers>
|
||||
size_t write(const Const_Buffers&)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
template <typename Const_Buffers>
|
||||
size_t write(const Const_Buffers&, asio::error_code& ec)
|
||||
{
|
||||
ec = asio::error_code();
|
||||
return 0;
|
||||
}
|
||||
|
||||
template <typename Const_Buffers, typename Handler>
|
||||
void async_write(const Const_Buffers&, Handler handler)
|
||||
{
|
||||
asio::error_code error;
|
||||
asio::post(io_context_,
|
||||
asio::detail::bind_handler(handler, error, 0));
|
||||
}
|
||||
|
||||
template <typename Mutable_Buffers>
|
||||
size_t read(const Mutable_Buffers&)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
template <typename Mutable_Buffers>
|
||||
size_t read(const Mutable_Buffers&, asio::error_code& ec)
|
||||
{
|
||||
ec = asio::error_code();
|
||||
return 0;
|
||||
}
|
||||
|
||||
template <typename Mutable_Buffers, typename Handler>
|
||||
void async_read(const Mutable_Buffers&, Handler handler)
|
||||
{
|
||||
asio::error_code error;
|
||||
asio::post(io_context_,
|
||||
asio::detail::bind_handler(handler, error, 0));
|
||||
}
|
||||
|
||||
private:
|
||||
io_context_type& io_context_;
|
||||
};
|
||||
|
||||
void is_write_buffered_test()
|
||||
{
|
||||
ASIO_CHECK(!asio::is_write_buffered<
|
||||
asio::ip::tcp::socket>::value);
|
||||
|
||||
ASIO_CHECK(!asio::is_write_buffered<
|
||||
asio::buffered_read_stream<
|
||||
asio::ip::tcp::socket> >::value);
|
||||
|
||||
ASIO_CHECK(!!asio::is_write_buffered<
|
||||
asio::buffered_write_stream<
|
||||
asio::ip::tcp::socket> >::value);
|
||||
|
||||
ASIO_CHECK(!!asio::is_write_buffered<
|
||||
asio::buffered_stream<asio::ip::tcp::socket> >::value);
|
||||
|
||||
ASIO_CHECK(!asio::is_write_buffered<test_stream>::value);
|
||||
|
||||
ASIO_CHECK(!asio::is_write_buffered<
|
||||
asio::buffered_read_stream<test_stream> >::value);
|
||||
|
||||
ASIO_CHECK(!!asio::is_write_buffered<
|
||||
asio::buffered_write_stream<test_stream> >::value);
|
||||
|
||||
ASIO_CHECK(!!asio::is_write_buffered<
|
||||
asio::buffered_stream<test_stream> >::value);
|
||||
}
|
||||
|
||||
ASIO_TEST_SUITE
|
||||
(
|
||||
"is_write_buffered",
|
||||
ASIO_TEST_CASE(is_write_buffered_test)
|
||||
)
|
||||
@@ -0,0 +1,13 @@
|
||||
.deps
|
||||
.dirstamp
|
||||
*.o
|
||||
*.obj
|
||||
*.exe
|
||||
*.ilk
|
||||
*.manifest
|
||||
*.pdb
|
||||
*.tds
|
||||
basic_endpoint
|
||||
connect_pair
|
||||
datagram_protocol
|
||||
stream_protocol
|
||||
@@ -0,0 +1,25 @@
|
||||
//
|
||||
// basic_endpoint.cpp
|
||||
// ~~~~~~~~~~~~~~~~~~
|
||||
//
|
||||
// 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)
|
||||
//
|
||||
|
||||
// Disable autolinking for unit tests.
|
||||
#if !defined(BOOST_ALL_NO_LIB)
|
||||
#define BOOST_ALL_NO_LIB 1
|
||||
#endif // !defined(BOOST_ALL_NO_LIB)
|
||||
|
||||
// Test that header file is self-contained.
|
||||
#include "asio/local/basic_endpoint.hpp"
|
||||
|
||||
#include "../unit_test.hpp"
|
||||
|
||||
ASIO_TEST_SUITE
|
||||
(
|
||||
"local/basic_endpoint",
|
||||
ASIO_TEST_CASE(null_test)
|
||||
)
|
||||
@@ -0,0 +1,76 @@
|
||||
//
|
||||
// connect_pair.cpp
|
||||
// ~~~~~~~~~~~~~~~~
|
||||
//
|
||||
// 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)
|
||||
//
|
||||
|
||||
// Disable autolinking for unit tests.
|
||||
#if !defined(BOOST_ALL_NO_LIB)
|
||||
#define BOOST_ALL_NO_LIB 1
|
||||
#endif // !defined(BOOST_ALL_NO_LIB)
|
||||
|
||||
// Test that header file is self-contained.
|
||||
#include "asio/local/connect_pair.hpp"
|
||||
|
||||
#include "asio/io_context.hpp"
|
||||
#include "asio/local/datagram_protocol.hpp"
|
||||
#include "asio/local/stream_protocol.hpp"
|
||||
#include "../unit_test.hpp"
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
// local_connect_pair_compile test
|
||||
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
// The following test checks that all host_name functions compile and link
|
||||
// correctly. Runtime failures are ignored.
|
||||
|
||||
namespace local_connect_pair_compile {
|
||||
|
||||
void test()
|
||||
{
|
||||
#if defined(ASIO_HAS_LOCAL_SOCKETS)
|
||||
using namespace asio;
|
||||
namespace local = asio::local;
|
||||
typedef local::datagram_protocol dp;
|
||||
typedef local::stream_protocol sp;
|
||||
|
||||
try
|
||||
{
|
||||
asio::io_context io_context;
|
||||
asio::error_code ec1;
|
||||
|
||||
dp::socket s1(io_context);
|
||||
dp::socket s2(io_context);
|
||||
local::connect_pair(s1, s2);
|
||||
|
||||
dp::socket s3(io_context);
|
||||
dp::socket s4(io_context);
|
||||
local::connect_pair(s3, s4, ec1);
|
||||
|
||||
sp::socket s5(io_context);
|
||||
sp::socket s6(io_context);
|
||||
local::connect_pair(s5, s6);
|
||||
|
||||
sp::socket s7(io_context);
|
||||
sp::socket s8(io_context);
|
||||
local::connect_pair(s7, s8, ec1);
|
||||
}
|
||||
catch (std::exception&)
|
||||
{
|
||||
}
|
||||
#endif // defined(ASIO_HAS_LOCAL_SOCKETS)
|
||||
}
|
||||
|
||||
} // namespace local_connect_pair_compile
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
ASIO_TEST_SUITE
|
||||
(
|
||||
"local/connect_pair",
|
||||
ASIO_TEST_CASE(local_connect_pair_compile::test)
|
||||
)
|
||||
@@ -0,0 +1,242 @@
|
||||
//
|
||||
// datagram_protocol.cpp
|
||||
// ~~~~~~~~~~~~~~~~~~~~~
|
||||
//
|
||||
// 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)
|
||||
//
|
||||
|
||||
// Disable autolinking for unit tests.
|
||||
#if !defined(BOOST_ALL_NO_LIB)
|
||||
#define BOOST_ALL_NO_LIB 1
|
||||
#endif // !defined(BOOST_ALL_NO_LIB)
|
||||
|
||||
// Test that header file is self-contained.
|
||||
#include "asio/local/datagram_protocol.hpp"
|
||||
|
||||
#include <cstring>
|
||||
#include "asio/io_context.hpp"
|
||||
#include "../unit_test.hpp"
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
// local_datagram_protocol_socket_compile test
|
||||
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
// The following test checks that all public member functions on the class
|
||||
// local::datagram_socket::socket compile and link correctly. Runtime failures
|
||||
// are ignored.
|
||||
|
||||
namespace local_datagram_protocol_socket_compile {
|
||||
|
||||
void connect_handler(const asio::error_code&)
|
||||
{
|
||||
}
|
||||
|
||||
void send_handler(const asio::error_code&, std::size_t)
|
||||
{
|
||||
}
|
||||
|
||||
void receive_handler(const asio::error_code&, std::size_t)
|
||||
{
|
||||
}
|
||||
|
||||
void test()
|
||||
{
|
||||
#if defined(ASIO_HAS_LOCAL_SOCKETS)
|
||||
using namespace asio;
|
||||
namespace local = asio::local;
|
||||
typedef local::datagram_protocol dp;
|
||||
|
||||
try
|
||||
{
|
||||
io_context ioc;
|
||||
const io_context::executor_type ioc_ex = ioc.get_executor();
|
||||
char mutable_char_buffer[128] = "";
|
||||
const char const_char_buffer[128] = "";
|
||||
socket_base::message_flags in_flags = 0;
|
||||
socket_base::send_buffer_size socket_option;
|
||||
socket_base::bytes_readable io_control_command;
|
||||
asio::error_code ec;
|
||||
|
||||
// basic_datagram_socket constructors.
|
||||
|
||||
dp::socket socket1(ioc);
|
||||
dp::socket socket2(ioc, dp());
|
||||
dp::socket socket3(ioc, dp::endpoint(""));
|
||||
int native_socket1 = ::socket(AF_UNIX, SOCK_DGRAM, 0);
|
||||
dp::socket socket4(ioc, dp(), native_socket1);
|
||||
|
||||
dp::socket socket5(ioc_ex);
|
||||
dp::socket socket6(ioc_ex, dp());
|
||||
dp::socket socket7(ioc_ex, dp::endpoint(""));
|
||||
int native_socket2 = ::socket(AF_UNIX, SOCK_DGRAM, 0);
|
||||
dp::socket socket8(ioc_ex, dp(), native_socket2);
|
||||
|
||||
// basic_io_object functions.
|
||||
|
||||
dp::socket::executor_type ex = socket1.get_executor();
|
||||
(void)ex;
|
||||
|
||||
// basic_socket functions.
|
||||
|
||||
dp::socket::lowest_layer_type& lowest_layer = socket1.lowest_layer();
|
||||
(void)lowest_layer;
|
||||
|
||||
socket1.open(dp());
|
||||
socket1.open(dp(), ec);
|
||||
|
||||
int native_socket3 = ::socket(AF_UNIX, SOCK_DGRAM, 0);
|
||||
socket1.assign(dp(), native_socket3);
|
||||
int native_socket4 = ::socket(AF_UNIX, SOCK_DGRAM, 0);
|
||||
socket1.assign(dp(), native_socket4, ec);
|
||||
|
||||
bool is_open = socket1.is_open();
|
||||
(void)is_open;
|
||||
|
||||
socket1.close();
|
||||
socket1.close(ec);
|
||||
|
||||
dp::socket::native_handle_type native_socket5 = socket1.native_handle();
|
||||
(void)native_socket5;
|
||||
|
||||
socket1.cancel();
|
||||
socket1.cancel(ec);
|
||||
|
||||
bool at_mark1 = socket1.at_mark();
|
||||
(void)at_mark1;
|
||||
bool at_mark2 = socket1.at_mark(ec);
|
||||
(void)at_mark2;
|
||||
|
||||
std::size_t available1 = socket1.available();
|
||||
(void)available1;
|
||||
std::size_t available2 = socket1.available(ec);
|
||||
(void)available2;
|
||||
|
||||
socket1.bind(dp::endpoint(""));
|
||||
socket1.bind(dp::endpoint(""), ec);
|
||||
|
||||
socket1.connect(dp::endpoint(""));
|
||||
socket1.connect(dp::endpoint(""), ec);
|
||||
|
||||
socket1.async_connect(dp::endpoint(""), connect_handler);
|
||||
|
||||
socket1.set_option(socket_option);
|
||||
socket1.set_option(socket_option, ec);
|
||||
|
||||
socket1.get_option(socket_option);
|
||||
socket1.get_option(socket_option, ec);
|
||||
|
||||
socket1.io_control(io_control_command);
|
||||
socket1.io_control(io_control_command, ec);
|
||||
|
||||
dp::endpoint endpoint1 = socket1.local_endpoint();
|
||||
(void)endpoint1;
|
||||
dp::endpoint endpoint2 = socket1.local_endpoint(ec);
|
||||
(void)endpoint2;
|
||||
|
||||
dp::endpoint endpoint3 = socket1.remote_endpoint();
|
||||
(void)endpoint3;
|
||||
dp::endpoint endpoint4 = socket1.remote_endpoint(ec);
|
||||
(void)endpoint4;
|
||||
|
||||
socket1.shutdown(socket_base::shutdown_both);
|
||||
socket1.shutdown(socket_base::shutdown_both, ec);
|
||||
|
||||
// basic_datagram_socket functions.
|
||||
|
||||
socket1.send(buffer(mutable_char_buffer));
|
||||
socket1.send(buffer(const_char_buffer));
|
||||
socket1.send(null_buffers());
|
||||
socket1.send(buffer(mutable_char_buffer), in_flags);
|
||||
socket1.send(buffer(const_char_buffer), in_flags);
|
||||
socket1.send(null_buffers(), in_flags);
|
||||
socket1.send(buffer(mutable_char_buffer), in_flags, ec);
|
||||
socket1.send(buffer(const_char_buffer), in_flags, ec);
|
||||
socket1.send(null_buffers(), in_flags, ec);
|
||||
|
||||
socket1.async_send(buffer(mutable_char_buffer), send_handler);
|
||||
socket1.async_send(buffer(const_char_buffer), send_handler);
|
||||
socket1.async_send(null_buffers(), send_handler);
|
||||
socket1.async_send(buffer(mutable_char_buffer), in_flags, send_handler);
|
||||
socket1.async_send(buffer(const_char_buffer), in_flags, send_handler);
|
||||
socket1.async_send(null_buffers(), in_flags, send_handler);
|
||||
|
||||
socket1.send_to(buffer(mutable_char_buffer),
|
||||
dp::endpoint(""));
|
||||
socket1.send_to(buffer(const_char_buffer),
|
||||
dp::endpoint(""));
|
||||
socket1.send_to(null_buffers(),
|
||||
dp::endpoint(""));
|
||||
socket1.send_to(buffer(mutable_char_buffer),
|
||||
dp::endpoint(""), in_flags);
|
||||
socket1.send_to(buffer(const_char_buffer),
|
||||
dp::endpoint(""), in_flags);
|
||||
socket1.send_to(null_buffers(),
|
||||
dp::endpoint(""), in_flags);
|
||||
socket1.send_to(buffer(mutable_char_buffer),
|
||||
dp::endpoint(""), in_flags, ec);
|
||||
socket1.send_to(buffer(const_char_buffer),
|
||||
dp::endpoint(""), in_flags, ec);
|
||||
socket1.send_to(null_buffers(),
|
||||
dp::endpoint(""), in_flags, ec);
|
||||
|
||||
socket1.async_send_to(buffer(mutable_char_buffer),
|
||||
dp::endpoint(""), send_handler);
|
||||
socket1.async_send_to(buffer(const_char_buffer),
|
||||
dp::endpoint(""), send_handler);
|
||||
socket1.async_send_to(null_buffers(),
|
||||
dp::endpoint(""), send_handler);
|
||||
socket1.async_send_to(buffer(mutable_char_buffer),
|
||||
dp::endpoint(""), in_flags, send_handler);
|
||||
socket1.async_send_to(buffer(const_char_buffer),
|
||||
dp::endpoint(""), in_flags, send_handler);
|
||||
socket1.async_send_to(null_buffers(),
|
||||
dp::endpoint(""), in_flags, send_handler);
|
||||
|
||||
socket1.receive(buffer(mutable_char_buffer));
|
||||
socket1.receive(null_buffers());
|
||||
socket1.receive(buffer(mutable_char_buffer), in_flags);
|
||||
socket1.receive(null_buffers(), in_flags);
|
||||
socket1.receive(buffer(mutable_char_buffer), in_flags, ec);
|
||||
socket1.receive(null_buffers(), in_flags, ec);
|
||||
|
||||
socket1.async_receive(buffer(mutable_char_buffer), receive_handler);
|
||||
socket1.async_receive(null_buffers(), receive_handler);
|
||||
socket1.async_receive(buffer(mutable_char_buffer), in_flags,
|
||||
receive_handler);
|
||||
socket1.async_receive(null_buffers(), in_flags, receive_handler);
|
||||
|
||||
dp::endpoint endpoint;
|
||||
socket1.receive_from(buffer(mutable_char_buffer), endpoint);
|
||||
socket1.receive_from(null_buffers(), endpoint);
|
||||
socket1.receive_from(buffer(mutable_char_buffer), endpoint, in_flags);
|
||||
socket1.receive_from(null_buffers(), endpoint, in_flags);
|
||||
socket1.receive_from(buffer(mutable_char_buffer), endpoint, in_flags, ec);
|
||||
socket1.receive_from(null_buffers(), endpoint, in_flags, ec);
|
||||
|
||||
socket1.async_receive_from(buffer(mutable_char_buffer),
|
||||
endpoint, receive_handler);
|
||||
socket1.async_receive_from(null_buffers(),
|
||||
endpoint, receive_handler);
|
||||
socket1.async_receive_from(buffer(mutable_char_buffer),
|
||||
endpoint, in_flags, receive_handler);
|
||||
socket1.async_receive_from(null_buffers(),
|
||||
endpoint, in_flags, receive_handler);
|
||||
}
|
||||
catch (std::exception&)
|
||||
{
|
||||
}
|
||||
#endif // defined(ASIO_HAS_LOCAL_SOCKETS)
|
||||
}
|
||||
|
||||
} // namespace local_datagram_protocol_socket_compile
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
ASIO_TEST_SUITE
|
||||
(
|
||||
"local/datagram_protocol",
|
||||
ASIO_TEST_CASE(local_datagram_protocol_socket_compile::test)
|
||||
)
|
||||
@@ -0,0 +1,219 @@
|
||||
//
|
||||
// stream_protocol.cpp
|
||||
// ~~~~~~~~~~~~~~~~~~~
|
||||
//
|
||||
// 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)
|
||||
//
|
||||
|
||||
// Disable autolinking for unit tests.
|
||||
#if !defined(BOOST_ALL_NO_LIB)
|
||||
#define BOOST_ALL_NO_LIB 1
|
||||
#endif // !defined(BOOST_ALL_NO_LIB)
|
||||
|
||||
// Test that header file is self-contained.
|
||||
#include "asio/local/stream_protocol.hpp"
|
||||
|
||||
#include <cstring>
|
||||
#include "asio/io_context.hpp"
|
||||
#include "../unit_test.hpp"
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
// local_stream_protocol_socket_compile test
|
||||
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
// The following test checks that all public member functions on the class
|
||||
// local::stream_protocol::socket compile and link correctly. Runtime failures
|
||||
// are ignored.
|
||||
|
||||
namespace local_stream_protocol_socket_compile {
|
||||
|
||||
void connect_handler(const asio::error_code&)
|
||||
{
|
||||
}
|
||||
|
||||
void send_handler(const asio::error_code&, std::size_t)
|
||||
{
|
||||
}
|
||||
|
||||
void receive_handler(const asio::error_code&, std::size_t)
|
||||
{
|
||||
}
|
||||
|
||||
void write_some_handler(const asio::error_code&, std::size_t)
|
||||
{
|
||||
}
|
||||
|
||||
void read_some_handler(const asio::error_code&, std::size_t)
|
||||
{
|
||||
}
|
||||
|
||||
void test()
|
||||
{
|
||||
#if defined(ASIO_HAS_LOCAL_SOCKETS)
|
||||
using namespace asio;
|
||||
namespace local = asio::local;
|
||||
typedef local::stream_protocol sp;
|
||||
|
||||
try
|
||||
{
|
||||
io_context ioc;
|
||||
const io_context::executor_type ioc_ex = ioc.get_executor();
|
||||
char mutable_char_buffer[128] = "";
|
||||
const char const_char_buffer[128] = "";
|
||||
socket_base::message_flags in_flags = 0;
|
||||
socket_base::keep_alive socket_option;
|
||||
socket_base::bytes_readable io_control_command;
|
||||
asio::error_code ec;
|
||||
|
||||
// basic_stream_socket constructors.
|
||||
|
||||
sp::socket socket1(ioc);
|
||||
sp::socket socket2(ioc, sp());
|
||||
sp::socket socket3(ioc, sp::endpoint(""));
|
||||
int native_socket1 = ::socket(AF_UNIX, SOCK_STREAM, 0);
|
||||
sp::socket socket4(ioc, sp(), native_socket1);
|
||||
|
||||
sp::socket socket5(ioc_ex);
|
||||
sp::socket socket6(ioc_ex, sp());
|
||||
sp::socket socket7(ioc_ex, sp::endpoint(""));
|
||||
int native_socket2 = ::socket(AF_UNIX, SOCK_STREAM, 0);
|
||||
sp::socket socket8(ioc_ex, sp(), native_socket2);
|
||||
|
||||
// basic_io_object functions.
|
||||
|
||||
sp::socket::executor_type ex = socket1.get_executor();
|
||||
(void)ex;
|
||||
|
||||
// basic_socket functions.
|
||||
|
||||
sp::socket::lowest_layer_type& lowest_layer = socket1.lowest_layer();
|
||||
(void)lowest_layer;
|
||||
|
||||
socket1.open(sp());
|
||||
socket1.open(sp(), ec);
|
||||
|
||||
int native_socket3 = ::socket(AF_UNIX, SOCK_STREAM, 0);
|
||||
socket1.assign(sp(), native_socket3);
|
||||
int native_socket4 = ::socket(AF_UNIX, SOCK_STREAM, 0);
|
||||
socket1.assign(sp(), native_socket4, ec);
|
||||
|
||||
bool is_open = socket1.is_open();
|
||||
(void)is_open;
|
||||
|
||||
socket1.close();
|
||||
socket1.close(ec);
|
||||
|
||||
sp::socket::native_handle_type native_socket5 = socket1.native_handle();
|
||||
(void)native_socket5;
|
||||
|
||||
socket1.cancel();
|
||||
socket1.cancel(ec);
|
||||
|
||||
bool at_mark1 = socket1.at_mark();
|
||||
(void)at_mark1;
|
||||
bool at_mark2 = socket1.at_mark(ec);
|
||||
(void)at_mark2;
|
||||
|
||||
std::size_t available1 = socket1.available();
|
||||
(void)available1;
|
||||
std::size_t available2 = socket1.available(ec);
|
||||
(void)available2;
|
||||
|
||||
socket1.bind(sp::endpoint(""));
|
||||
socket1.bind(sp::endpoint(""), ec);
|
||||
|
||||
socket1.connect(sp::endpoint(""));
|
||||
socket1.connect(sp::endpoint(""), ec);
|
||||
|
||||
socket1.async_connect(sp::endpoint(""), connect_handler);
|
||||
|
||||
socket1.set_option(socket_option);
|
||||
socket1.set_option(socket_option, ec);
|
||||
|
||||
socket1.get_option(socket_option);
|
||||
socket1.get_option(socket_option, ec);
|
||||
|
||||
socket1.io_control(io_control_command);
|
||||
socket1.io_control(io_control_command, ec);
|
||||
|
||||
sp::endpoint endpoint1 = socket1.local_endpoint();
|
||||
(void)endpoint1;
|
||||
sp::endpoint endpoint2 = socket1.local_endpoint(ec);
|
||||
(void)endpoint2;
|
||||
|
||||
sp::endpoint endpoint3 = socket1.remote_endpoint();
|
||||
(void)endpoint3;
|
||||
sp::endpoint endpoint4 = socket1.remote_endpoint(ec);
|
||||
(void)endpoint4;
|
||||
|
||||
socket1.shutdown(socket_base::shutdown_both);
|
||||
socket1.shutdown(socket_base::shutdown_both, ec);
|
||||
|
||||
// basic_stream_socket functions.
|
||||
|
||||
socket1.send(buffer(mutable_char_buffer));
|
||||
socket1.send(buffer(const_char_buffer));
|
||||
socket1.send(null_buffers());
|
||||
socket1.send(buffer(mutable_char_buffer), in_flags);
|
||||
socket1.send(buffer(const_char_buffer), in_flags);
|
||||
socket1.send(null_buffers(), in_flags);
|
||||
socket1.send(buffer(mutable_char_buffer), in_flags, ec);
|
||||
socket1.send(buffer(const_char_buffer), in_flags, ec);
|
||||
socket1.send(null_buffers(), in_flags, ec);
|
||||
|
||||
socket1.async_send(buffer(mutable_char_buffer), send_handler);
|
||||
socket1.async_send(buffer(const_char_buffer), send_handler);
|
||||
socket1.async_send(null_buffers(), send_handler);
|
||||
socket1.async_send(buffer(mutable_char_buffer), in_flags, send_handler);
|
||||
socket1.async_send(buffer(const_char_buffer), in_flags, send_handler);
|
||||
socket1.async_send(null_buffers(), in_flags, send_handler);
|
||||
|
||||
socket1.receive(buffer(mutable_char_buffer));
|
||||
socket1.receive(null_buffers());
|
||||
socket1.receive(buffer(mutable_char_buffer), in_flags);
|
||||
socket1.receive(null_buffers(), in_flags);
|
||||
socket1.receive(buffer(mutable_char_buffer), in_flags, ec);
|
||||
socket1.receive(null_buffers(), in_flags, ec);
|
||||
|
||||
socket1.async_receive(buffer(mutable_char_buffer), receive_handler);
|
||||
socket1.async_receive(null_buffers(), receive_handler);
|
||||
socket1.async_receive(buffer(mutable_char_buffer), in_flags,
|
||||
receive_handler);
|
||||
socket1.async_receive(null_buffers(), in_flags, receive_handler);
|
||||
|
||||
socket1.write_some(buffer(mutable_char_buffer));
|
||||
socket1.write_some(buffer(const_char_buffer));
|
||||
socket1.write_some(null_buffers());
|
||||
socket1.write_some(buffer(mutable_char_buffer), ec);
|
||||
socket1.write_some(buffer(const_char_buffer), ec);
|
||||
socket1.write_some(null_buffers(), ec);
|
||||
|
||||
socket1.async_write_some(buffer(mutable_char_buffer), write_some_handler);
|
||||
socket1.async_write_some(buffer(const_char_buffer), write_some_handler);
|
||||
socket1.async_write_some(null_buffers(), write_some_handler);
|
||||
|
||||
socket1.read_some(buffer(mutable_char_buffer));
|
||||
socket1.read_some(buffer(mutable_char_buffer), ec);
|
||||
socket1.read_some(null_buffers(), ec);
|
||||
|
||||
socket1.async_read_some(buffer(mutable_char_buffer), read_some_handler);
|
||||
socket1.async_read_some(null_buffers(), read_some_handler);
|
||||
}
|
||||
catch (std::exception&)
|
||||
{
|
||||
}
|
||||
#endif // defined(ASIO_HAS_LOCAL_SOCKETS)
|
||||
}
|
||||
|
||||
} // namespace local_stream_protocol_socket_compile
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
ASIO_TEST_SUITE
|
||||
(
|
||||
"local/stream_protocol",
|
||||
ASIO_TEST_CASE(local_stream_protocol_socket_compile::test)
|
||||
)
|
||||
@@ -0,0 +1,25 @@
|
||||
//
|
||||
// packaged_task.cpp
|
||||
// ~~~~~~~~~~~~~~~~~
|
||||
//
|
||||
// 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)
|
||||
//
|
||||
|
||||
// Disable autolinking for unit tests.
|
||||
#if !defined(BOOST_ALL_NO_LIB)
|
||||
#define BOOST_ALL_NO_LIB 1
|
||||
#endif // !defined(BOOST_ALL_NO_LIB)
|
||||
|
||||
// Test that header file is self-contained.
|
||||
#include "asio/packaged_task.hpp"
|
||||
|
||||
#include "unit_test.hpp"
|
||||
|
||||
ASIO_TEST_SUITE
|
||||
(
|
||||
"packaged_task",
|
||||
ASIO_TEST_CASE(null_test)
|
||||
)
|
||||
@@ -0,0 +1,25 @@
|
||||
//
|
||||
// placeholders.cpp
|
||||
// ~~~~~~~~~~~~~~~~
|
||||
//
|
||||
// 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)
|
||||
//
|
||||
|
||||
// Disable autolinking for unit tests.
|
||||
#if !defined(BOOST_ALL_NO_LIB)
|
||||
#define BOOST_ALL_NO_LIB 1
|
||||
#endif // !defined(BOOST_ALL_NO_LIB)
|
||||
|
||||
// Test that header file is self-contained.
|
||||
#include "asio/placeholders.hpp"
|
||||
|
||||
#include "unit_test.hpp"
|
||||
|
||||
ASIO_TEST_SUITE
|
||||
(
|
||||
"placeholders",
|
||||
ASIO_TEST_CASE(null_test)
|
||||
)
|
||||
@@ -0,0 +1,14 @@
|
||||
.deps
|
||||
.dirstamp
|
||||
*.o
|
||||
*.obj
|
||||
*.exe
|
||||
*.ilk
|
||||
*.manifest
|
||||
*.pdb
|
||||
*.tds
|
||||
basic_descriptor
|
||||
basic_stream_descriptor
|
||||
descriptor
|
||||
descriptor_base
|
||||
stream_descriptor
|
||||
@@ -0,0 +1,25 @@
|
||||
//
|
||||
// basic_descriptor.cpp
|
||||
// ~~~~~~~~~~~~~~~~~~~~
|
||||
//
|
||||
// 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)
|
||||
//
|
||||
|
||||
// Disable autolinking for unit tests.
|
||||
#if !defined(BOOST_ALL_NO_LIB)
|
||||
#define BOOST_ALL_NO_LIB 1
|
||||
#endif // !defined(BOOST_ALL_NO_LIB)
|
||||
|
||||
// Test that header file is self-contained.
|
||||
#include "asio/posix/basic_descriptor.hpp"
|
||||
|
||||
#include "../unit_test.hpp"
|
||||
|
||||
ASIO_TEST_SUITE
|
||||
(
|
||||
"posix/basic_descriptor",
|
||||
ASIO_TEST_CASE(null_test)
|
||||
)
|
||||
@@ -0,0 +1,25 @@
|
||||
//
|
||||
// basic_stream_descriptor.cpp
|
||||
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
//
|
||||
// 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)
|
||||
//
|
||||
|
||||
// Disable autolinking for unit tests.
|
||||
#if !defined(BOOST_ALL_NO_LIB)
|
||||
#define BOOST_ALL_NO_LIB 1
|
||||
#endif // !defined(BOOST_ALL_NO_LIB)
|
||||
|
||||
// Test that header file is self-contained.
|
||||
#include "asio/posix/basic_stream_descriptor.hpp"
|
||||
|
||||
#include "../unit_test.hpp"
|
||||
|
||||
ASIO_TEST_SUITE
|
||||
(
|
||||
"posix/basic_stream_descriptor",
|
||||
ASIO_TEST_CASE(null_test)
|
||||
)
|
||||
@@ -0,0 +1,25 @@
|
||||
//
|
||||
// descriptor.cpp
|
||||
// ~~~~~~~~~~~~~~
|
||||
//
|
||||
// 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)
|
||||
//
|
||||
|
||||
// Disable autolinking for unit tests.
|
||||
#if !defined(BOOST_ALL_NO_LIB)
|
||||
#define BOOST_ALL_NO_LIB 1
|
||||
#endif // !defined(BOOST_ALL_NO_LIB)
|
||||
|
||||
// Test that header file is self-contained.
|
||||
#include "asio/posix/descriptor.hpp"
|
||||
|
||||
#include "../unit_test.hpp"
|
||||
|
||||
ASIO_TEST_SUITE
|
||||
(
|
||||
"posix/descriptor",
|
||||
ASIO_TEST_CASE(null_test)
|
||||
)
|
||||
@@ -0,0 +1,25 @@
|
||||
//
|
||||
// descriptor_base.cpp
|
||||
// ~~~~~~~~~~~~~~~~~~~
|
||||
//
|
||||
// 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)
|
||||
//
|
||||
|
||||
// Disable autolinking for unit tests.
|
||||
#if !defined(BOOST_ALL_NO_LIB)
|
||||
#define BOOST_ALL_NO_LIB 1
|
||||
#endif // !defined(BOOST_ALL_NO_LIB)
|
||||
|
||||
// Test that header file is self-contained.
|
||||
#include "asio/posix/descriptor_base.hpp"
|
||||
|
||||
#include "../unit_test.hpp"
|
||||
|
||||
ASIO_TEST_SUITE
|
||||
(
|
||||
"posix/descriptor_base",
|
||||
ASIO_TEST_CASE(null_test)
|
||||
)
|
||||
@@ -0,0 +1,183 @@
|
||||
//
|
||||
// stream_descriptor.cpp
|
||||
// ~~~~~~~~~~~~~~~~~~~~~
|
||||
//
|
||||
// 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)
|
||||
//
|
||||
|
||||
// Disable autolinking for unit tests.
|
||||
#if !defined(BOOST_ALL_NO_LIB)
|
||||
#define BOOST_ALL_NO_LIB 1
|
||||
#endif // !defined(BOOST_ALL_NO_LIB)
|
||||
|
||||
// Test that header file is self-contained.
|
||||
#include "asio/posix/stream_descriptor.hpp"
|
||||
|
||||
#include "asio/io_context.hpp"
|
||||
#include "../archetypes/async_result.hpp"
|
||||
#include "../unit_test.hpp"
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
// posix_stream_descriptor_compile test
|
||||
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
// The following test checks that all public member functions on the class
|
||||
// posix::stream_descriptor compile and link correctly. Runtime failures are
|
||||
// ignored.
|
||||
|
||||
namespace posix_stream_descriptor_compile {
|
||||
|
||||
void wait_handler(const asio::error_code&)
|
||||
{
|
||||
}
|
||||
|
||||
void write_some_handler(const asio::error_code&, std::size_t)
|
||||
{
|
||||
}
|
||||
|
||||
void read_some_handler(const asio::error_code&, std::size_t)
|
||||
{
|
||||
}
|
||||
|
||||
void test()
|
||||
{
|
||||
#if defined(ASIO_HAS_POSIX_STREAM_DESCRIPTOR)
|
||||
using namespace asio;
|
||||
namespace posix = asio::posix;
|
||||
|
||||
try
|
||||
{
|
||||
io_context ioc;
|
||||
const io_context::executor_type ioc_ex = ioc.get_executor();
|
||||
char mutable_char_buffer[128] = "";
|
||||
const char const_char_buffer[128] = "";
|
||||
posix::descriptor_base::bytes_readable io_control_command;
|
||||
archetypes::lazy_handler lazy;
|
||||
asio::error_code ec;
|
||||
|
||||
// basic_stream_descriptor constructors.
|
||||
|
||||
posix::stream_descriptor descriptor1(ioc);
|
||||
posix::stream_descriptor descriptor2(ioc_ex);
|
||||
int native_descriptor1 = -1;
|
||||
posix::stream_descriptor descriptor3(ioc, native_descriptor1);
|
||||
posix::stream_descriptor descriptor4(ioc_ex, native_descriptor1);
|
||||
|
||||
#if defined(ASIO_HAS_MOVE)
|
||||
posix::stream_descriptor descriptor5(std::move(descriptor2));
|
||||
#endif // defined(ASIO_HAS_MOVE)
|
||||
|
||||
// basic_stream_descriptor operators.
|
||||
|
||||
#if defined(ASIO_HAS_MOVE)
|
||||
descriptor1 = posix::stream_descriptor(ioc);
|
||||
descriptor1 = std::move(descriptor2);
|
||||
#endif // defined(ASIO_HAS_MOVE)
|
||||
|
||||
// basic_io_object functions.
|
||||
|
||||
posix::stream_descriptor::executor_type ex = descriptor1.get_executor();
|
||||
(void)ex;
|
||||
|
||||
// basic_descriptor functions.
|
||||
|
||||
posix::stream_descriptor::lowest_layer_type& lowest_layer
|
||||
= descriptor1.lowest_layer();
|
||||
(void)lowest_layer;
|
||||
|
||||
const posix::stream_descriptor& descriptor6 = descriptor1;
|
||||
const posix::stream_descriptor::lowest_layer_type& lowest_layer2
|
||||
= descriptor6.lowest_layer();
|
||||
(void)lowest_layer2;
|
||||
|
||||
int native_descriptor2 = -1;
|
||||
descriptor1.assign(native_descriptor2);
|
||||
|
||||
bool is_open = descriptor1.is_open();
|
||||
(void)is_open;
|
||||
|
||||
descriptor1.close();
|
||||
descriptor1.close(ec);
|
||||
|
||||
posix::stream_descriptor::native_handle_type native_descriptor3
|
||||
= descriptor1.native_handle();
|
||||
(void)native_descriptor3;
|
||||
|
||||
posix::stream_descriptor::native_handle_type native_descriptor4
|
||||
= descriptor1.release();
|
||||
(void)native_descriptor4;
|
||||
|
||||
descriptor1.cancel();
|
||||
descriptor1.cancel(ec);
|
||||
|
||||
descriptor1.io_control(io_control_command);
|
||||
descriptor1.io_control(io_control_command, ec);
|
||||
|
||||
bool non_blocking1 = descriptor1.non_blocking();
|
||||
(void)non_blocking1;
|
||||
descriptor1.non_blocking(true);
|
||||
descriptor1.non_blocking(false, ec);
|
||||
|
||||
bool non_blocking2 = descriptor1.native_non_blocking();
|
||||
(void)non_blocking2;
|
||||
descriptor1.native_non_blocking(true);
|
||||
descriptor1.native_non_blocking(false, ec);
|
||||
|
||||
descriptor1.wait(posix::descriptor_base::wait_read);
|
||||
descriptor1.wait(posix::descriptor_base::wait_write, ec);
|
||||
|
||||
descriptor1.async_wait(posix::descriptor_base::wait_read, &wait_handler);
|
||||
int i1 = descriptor1.async_wait(posix::descriptor_base::wait_write, lazy);
|
||||
(void)i1;
|
||||
|
||||
// basic_stream_descriptor functions.
|
||||
|
||||
descriptor1.write_some(buffer(mutable_char_buffer));
|
||||
descriptor1.write_some(buffer(const_char_buffer));
|
||||
descriptor1.write_some(null_buffers());
|
||||
descriptor1.write_some(buffer(mutable_char_buffer), ec);
|
||||
descriptor1.write_some(buffer(const_char_buffer), ec);
|
||||
descriptor1.write_some(null_buffers(), ec);
|
||||
|
||||
descriptor1.async_write_some(buffer(mutable_char_buffer),
|
||||
write_some_handler);
|
||||
descriptor1.async_write_some(buffer(const_char_buffer),
|
||||
write_some_handler);
|
||||
descriptor1.async_write_some(null_buffers(),
|
||||
write_some_handler);
|
||||
int i2 = descriptor1.async_write_some(buffer(mutable_char_buffer), lazy);
|
||||
(void)i2;
|
||||
int i3 = descriptor1.async_write_some(buffer(const_char_buffer), lazy);
|
||||
(void)i3;
|
||||
int i4 = descriptor1.async_write_some(null_buffers(), lazy);
|
||||
(void)i4;
|
||||
|
||||
descriptor1.read_some(buffer(mutable_char_buffer));
|
||||
descriptor1.read_some(buffer(mutable_char_buffer), ec);
|
||||
descriptor1.read_some(null_buffers(), ec);
|
||||
|
||||
descriptor1.async_read_some(buffer(mutable_char_buffer), read_some_handler);
|
||||
descriptor1.async_read_some(null_buffers(), read_some_handler);
|
||||
int i5 = descriptor1.async_read_some(buffer(mutable_char_buffer), lazy);
|
||||
(void)i5;
|
||||
int i6 = descriptor1.async_read_some(null_buffers(), lazy);
|
||||
(void)i6;
|
||||
}
|
||||
catch (std::exception&)
|
||||
{
|
||||
}
|
||||
#endif // defined(ASIO_HAS_POSIX_STREAM_DESCRIPTOR)
|
||||
}
|
||||
|
||||
} // namespace posix_stream_descriptor_compile
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
ASIO_TEST_SUITE
|
||||
(
|
||||
"posix/stream_descriptor",
|
||||
ASIO_TEST_CASE(posix_stream_descriptor_compile::test)
|
||||
)
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user