mirror of
https://github.com/boostorg/asio.git
synced 2026-01-27 06:32:08 +00:00
------------------------------------------------------------------------
r84301 | chris_kohlhoff | 2013-05-17 07:34:54 +1000 (Fri, 17 May 2013) | 2 lines
Enable handler type requirements static_assert on clang.
------------------------------------------------------------------------
r84308 | chris_kohlhoff | 2013-05-17 09:26:04 +1000 (Fri, 17 May 2013) | 3 lines
Add new traits classes, handler_type and async_result, that allow
the customisation of the return type of an initiating function.
------------------------------------------------------------------------
r84311 | chris_kohlhoff | 2013-05-17 11:38:47 +1000 (Fri, 17 May 2013) | 81 lines
Add the asio::spawn() function, a high-level wrapper for running
stackful coroutines. It is based on the Boost.Coroutine library.
Here is an example of its use:
asio::spawn(my_strand, do_echo);
// ...
void do_echo(asio::yield_context yield)
{
try
{
char data[128];
for (;;)
{
std::size_t length =
my_socket.async_read_some(
asio::buffer(data), yield);
asio::async_write(my_socket,
asio::buffer(data, length), yield);
}
}
catch (std::exception& e)
{
// ...
}
}
The first argument to asio::spawn() may be a strand, io_service or
completion handler. This argument determines the context in which the
coroutine is permitted to execute. For example, a server's per-client
object may consist of multiple coroutines; they should all run on the
same strand so that no explicit synchronisation is required.
The second argument is a function object with signature (**):
void coroutine(asio::yield_context yield);
that specifies the code to be run as part of the coroutine. The
parameter yield may be passed to an asynchronous operation in place of
the completion handler, as in:
std::size_t length =
my_socket.async_read_some(
asio::buffer(data), yield);
This starts the asynchronous operation and suspends the coroutine. The
coroutine will be resumed automatically when the asynchronous operation
completes.
Where a completion handler signature has the form:
void handler(error_code ec, result_type result);
the initiating function returns the result_type. In the async_read_some
example above, this is std::size_t. If the asynchronous operation fails,
the error_code is converted into a system_error exception and thrown.
Where a completion handler signature has the form:
void handler(error_code ec);
the initiating function returns void. As above, an error is passed back
to the coroutine as a system_error exception.
To collect the error_code from an operation, rather than have it throw
an exception, associate the output variable with the yield_context as
follows:
error_code ec;
std::size_t length =
my_socket.async_read_some(
asio::buffer(data), yield[ec]);
**Note: if asio::spawn() is used with a custom completion handler of
type Handler, the function object signature is actually:
void coroutine(asio::basic_yield_context<Handler> yield);
------------------------------------------------------------------------
r84312 | chris_kohlhoff | 2013-05-17 12:25:10 +1000 (Fri, 17 May 2013) | 4 lines
Move existing examples into a C++03-specific directory, and add a new
directory for C++11-specific examples. A limited subset of the C++03
examples have been converted to their C++11 equivalents.
------------------------------------------------------------------------
r84313 | chris_kohlhoff | 2013-05-17 12:35:08 +1000 (Fri, 17 May 2013) | 26 lines
Add the asio::use_future special value, which adds first-class support
for returning a C++11 std::future from an asynchronous operation's
initiating function.
To use asio::use_future, pass it to an asynchronous operation instead of
a normal completion handler. For example:
std::future<std::size_t> length =
my_socket.async_read_some(my_buffer, asio::use_future);
Where a completion handler signature has the form:
void handler(error_code ec, result_type result);
the initiating function returns a std::future templated on result_type.
In the above example, this is std::size_t. If the asynchronous operation
fails, the error_code is converted into a system_error exception and
passed back to the caller through the future.
Where a completion handler signature has the form:
void handler(error_code ec);
the initiating function returns std::future<void>. As above, an error
is passed back in the future as a system_error exception.
------------------------------------------------------------------------
r84314 | chris_kohlhoff | 2013-05-17 13:07:51 +1000 (Fri, 17 May 2013) | 27 lines
Add a new handler hook called asio_handler_is_continuation.
Asynchronous operations may represent a continuation of the asynchronous
control flow associated with the current handler. Asio's implementation
can use this knowledge to optimise scheduling of the handler.
The asio_handler_is_continuation hook returns true to indicate whether a
completion handler represents a continuation of the current call
context. The default implementation of the hook returns false, and
applications may customise the hook when necessary. The hook has already
been customised within Asio to return true for the following cases:
- Handlers returned by strand.wrap(), when the corresponding
asynchronous operation is being initiated from within the strand.
- The internal handlers used to implement the asio::spawn() function's
stackful coroutines.
- When an intermediate handler of a composed operation (e.g.
asio::async_read(), asio::async_write(), asio::async_connect(),
ssl::stream<>, etc.) starts a new asynchronous operation due to the
composed operation not being complete.
To support this optimisation, a new running_in_this_thread() member
function has been added to the io_service::strand class. This function
returns true when called from within a strand.
------------------------------------------------------------------------
r84315 | chris_kohlhoff | 2013-05-17 20:06:50 +1000 (Fri, 17 May 2013) | 3 lines
Partially decouple Asio from other boost components via an extra level
of indirection.
------------------------------------------------------------------------
r84316 | chris_kohlhoff | 2013-05-17 20:15:21 +1000 (Fri, 17 May 2013) | 2 lines
Minor cleanup.
------------------------------------------------------------------------
r84319 | chris_kohlhoff | 2013-05-17 20:52:08 +1000 (Fri, 17 May 2013) | 9 lines
Support handshake with re-use of data already read from the wire.
Add new overloads of the SSL stream's handshake() and async_handshake()
functions, that accepts a ConstBufferSequence to be used as initial
input to the ssl engine for the handshake procedure.
Thanks go to Nick Jones <nick dot fa dot jones at gmail dot com>, on
whose work this commit is partially based.
------------------------------------------------------------------------
r84320 | chris_kohlhoff | 2013-05-17 20:57:02 +1000 (Fri, 17 May 2013) | 6 lines
Support for creation of TLSv1.1 and TLSv1.2 contexts.
Thanks go to Alvin Cheung <alvin dot cheung at alumni dot ust dot hk>
and Nick Jones <nick dot fa dot jones at gmail dot com>, on whose work
this is based.
------------------------------------------------------------------------
r84322 | chris_kohlhoff | 2013-05-17 21:00:49 +1000 (Fri, 17 May 2013) | 5 lines
Add set_verify_depth function to SSL context and stream.
Thanks go to Nick Jones <nick dot fa dot jones at gmail dot com>, on
whose work this commit is based.
------------------------------------------------------------------------
r84325 | chris_kohlhoff | 2013-05-17 21:04:11 +1000 (Fri, 17 May 2013) | 9 lines
Allow loading of SSL certificate and key data from memory buffers.
Added new buffer-based interfaces:
add_certificate_authority, use_certificate, use_certificate_chain,
use_private_key, use_rsa_private_key, use_tmp_dh.
Thanks go to Nick Jones <nick dot fa dot jones at gmail dot com>, on
whose work this commit is based.
------------------------------------------------------------------------
r84345 | chris_kohlhoff | 2013-05-18 21:24:59 +1000 (Sat, 18 May 2013) | 2 lines
Update copyright notices.
------------------------------------------------------------------------
r84346 | chris_kohlhoff | 2013-05-18 21:54:59 +1000 (Sat, 18 May 2013) | 3 lines
Remove the stackless coroutine class and macros from the HTTP server 4
example, and instead make them a part of Asio's documented interface.
------------------------------------------------------------------------
r84347 | chris_kohlhoff | 2013-05-18 22:01:59 +1000 (Sat, 18 May 2013) | 4 lines
Fix basic_waitable_timer's underlying implementation so that it can
handle any time_point value without overflowing the intermediate
duration objects.
------------------------------------------------------------------------
r84348 | chris_kohlhoff | 2013-05-18 22:07:00 +1000 (Sat, 18 May 2013) | 3 lines
Fix a problem with lost thread wakeups that can occur when making
concurrent calls to run() and poll() on the same io_service object.
------------------------------------------------------------------------
r84349 | chris_kohlhoff | 2013-05-18 22:13:17 +1000 (Sat, 18 May 2013) | 3 lines
Fix implementation of asynchronous connect operation so that it can cope
with spurious readiness notifications from the reactor.
------------------------------------------------------------------------
r84361 | chris_kohlhoff | 2013-05-19 07:56:31 +1000 (Sun, 19 May 2013) | 1 line
Remove some trailing spaces and fix another copyright notice.
------------------------------------------------------------------------
r84363 | chris_kohlhoff | 2013-05-19 14:55:11 +1000 (Sun, 19 May 2013) | 53 lines
Add generic socket protocols and converting move constructors.
Four new protocol classes have been added:
- asio::generic::datagram_protocol
- asio::generic::raw_protocol
- asio::generic::seq_packet_protocol
- asio::generic::stream_protocol
These classes implement the Protocol type requirements, but allow the
user to specify the address family (e.g. AF_INET) and protocol type
(e.g. IPPROTO_TCP) at runtime.
A new endpoint class template, asio::generic::basic_endpoint, has been
added to support these new protocol classes. This endpoint can hold any
other endpoint type, provided its native representation fits into a
sockaddr_storage object.
When using C++11, it is now possible to perform move construction from a
socket (or acceptor) object to convert to the more generic protocol's
socket (or acceptor) type. If the protocol conversion is valid:
Protocol1 p1 = ...;
Protocol2 p2(p1);
then the corresponding socket conversion is allowed:
Protocol1::socket socket1(io_service);
...
Protocol2::socket socket2(std::move(socket1));
For example, one possible conversion is from a TCP socket to a generic
stream-oriented socket:
asio::ip::tcp::socket socket1(io_service);
...
asio::generic::stream_protocol::socket socket2(std::move(socket1));
The conversion is also available for move-assignment. Note that these
conversions are not limited to the newly added generic protocol classes.
User-defined protocols may take advantage of this feature by similarly
ensuring the conversion from Protocol1 to Protocol2 is valid, as above.
As a convenience, the socket acceptor's accept() and async_accept()
functions have been changed so that they can directly accept into a
different protocol's socket type, provided the protocol conversion is
valid. For example, the following is now possible:
asio::ip::tcp::acceptor acceptor(io_service);
...
asio::generic::stream_protocol::socket socket1(io_service);
acceptor.accept(socket1);
[SVN r84388]
655 lines
24 KiB
C++
655 lines
24 KiB
C++
//
|
|
// socket_base.cpp
|
|
// ~~~~~~~~~~~~~~~
|
|
//
|
|
// Copyright (c) 2003-2013 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 <boost/asio/socket_base.hpp>
|
|
|
|
#include <boost/asio/io_service.hpp>
|
|
#include <boost/asio/ip/tcp.hpp>
|
|
#include <boost/asio/ip/udp.hpp>
|
|
#include "unit_test.hpp"
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
// socket_base_compile test
|
|
// ~~~~~~~~~~~~~~~~~~~~~~~~
|
|
// The following test checks that all nested classes, enums and constants in
|
|
// socket_base compile and link correctly. Runtime failures are ignored.
|
|
|
|
namespace socket_base_compile {
|
|
|
|
void test()
|
|
{
|
|
using namespace boost::asio;
|
|
namespace ip = boost::asio::ip;
|
|
|
|
try
|
|
{
|
|
io_service ios;
|
|
ip::tcp::socket sock(ios);
|
|
char buf[1024];
|
|
|
|
// shutdown_type enumeration.
|
|
|
|
sock.shutdown(socket_base::shutdown_receive);
|
|
sock.shutdown(socket_base::shutdown_send);
|
|
sock.shutdown(socket_base::shutdown_both);
|
|
|
|
// message_flags constants.
|
|
|
|
sock.receive(buffer(buf), socket_base::message_peek);
|
|
sock.receive(buffer(buf), socket_base::message_out_of_band);
|
|
sock.send(buffer(buf), socket_base::message_do_not_route);
|
|
|
|
// broadcast class.
|
|
|
|
socket_base::broadcast broadcast1(true);
|
|
sock.set_option(broadcast1);
|
|
socket_base::broadcast broadcast2;
|
|
sock.get_option(broadcast2);
|
|
broadcast1 = true;
|
|
(void)static_cast<bool>(broadcast1);
|
|
(void)static_cast<bool>(!broadcast1);
|
|
(void)static_cast<bool>(broadcast1.value());
|
|
|
|
// debug class.
|
|
|
|
socket_base::debug debug1(true);
|
|
sock.set_option(debug1);
|
|
socket_base::debug debug2;
|
|
sock.get_option(debug2);
|
|
debug1 = true;
|
|
(void)static_cast<bool>(debug1);
|
|
(void)static_cast<bool>(!debug1);
|
|
(void)static_cast<bool>(debug1.value());
|
|
|
|
// do_not_route class.
|
|
|
|
socket_base::do_not_route do_not_route1(true);
|
|
sock.set_option(do_not_route1);
|
|
socket_base::do_not_route do_not_route2;
|
|
sock.get_option(do_not_route2);
|
|
do_not_route1 = true;
|
|
(void)static_cast<bool>(do_not_route1);
|
|
(void)static_cast<bool>(!do_not_route1);
|
|
(void)static_cast<bool>(do_not_route1.value());
|
|
|
|
// keep_alive class.
|
|
|
|
socket_base::keep_alive keep_alive1(true);
|
|
sock.set_option(keep_alive1);
|
|
socket_base::keep_alive keep_alive2;
|
|
sock.get_option(keep_alive2);
|
|
keep_alive1 = true;
|
|
(void)static_cast<bool>(keep_alive1);
|
|
(void)static_cast<bool>(!keep_alive1);
|
|
(void)static_cast<bool>(keep_alive1.value());
|
|
|
|
// send_buffer_size class.
|
|
|
|
socket_base::send_buffer_size send_buffer_size1(1024);
|
|
sock.set_option(send_buffer_size1);
|
|
socket_base::send_buffer_size send_buffer_size2;
|
|
sock.get_option(send_buffer_size2);
|
|
send_buffer_size1 = 1;
|
|
(void)static_cast<int>(send_buffer_size1.value());
|
|
|
|
// send_low_watermark class.
|
|
|
|
socket_base::send_low_watermark send_low_watermark1(128);
|
|
sock.set_option(send_low_watermark1);
|
|
socket_base::send_low_watermark send_low_watermark2;
|
|
sock.get_option(send_low_watermark2);
|
|
send_low_watermark1 = 1;
|
|
(void)static_cast<int>(send_low_watermark1.value());
|
|
|
|
// receive_buffer_size class.
|
|
|
|
socket_base::receive_buffer_size receive_buffer_size1(1024);
|
|
sock.set_option(receive_buffer_size1);
|
|
socket_base::receive_buffer_size receive_buffer_size2;
|
|
sock.get_option(receive_buffer_size2);
|
|
receive_buffer_size1 = 1;
|
|
(void)static_cast<int>(receive_buffer_size1.value());
|
|
|
|
// receive_low_watermark class.
|
|
|
|
socket_base::receive_low_watermark receive_low_watermark1(128);
|
|
sock.set_option(receive_low_watermark1);
|
|
socket_base::receive_low_watermark receive_low_watermark2;
|
|
sock.get_option(receive_low_watermark2);
|
|
receive_low_watermark1 = 1;
|
|
(void)static_cast<int>(receive_low_watermark1.value());
|
|
|
|
// reuse_address class.
|
|
|
|
socket_base::reuse_address reuse_address1(true);
|
|
sock.set_option(reuse_address1);
|
|
socket_base::reuse_address reuse_address2;
|
|
sock.get_option(reuse_address2);
|
|
reuse_address1 = true;
|
|
(void)static_cast<bool>(reuse_address1);
|
|
(void)static_cast<bool>(!reuse_address1);
|
|
(void)static_cast<bool>(reuse_address1.value());
|
|
|
|
// linger class.
|
|
|
|
socket_base::linger linger1(true, 30);
|
|
sock.set_option(linger1);
|
|
socket_base::linger linger2;
|
|
sock.get_option(linger2);
|
|
linger1.enabled(true);
|
|
(void)static_cast<bool>(linger1.enabled());
|
|
linger1.timeout(1);
|
|
(void)static_cast<int>(linger1.timeout());
|
|
|
|
// enable_connection_aborted class.
|
|
|
|
socket_base::enable_connection_aborted enable_connection_aborted1(true);
|
|
sock.set_option(enable_connection_aborted1);
|
|
socket_base::enable_connection_aborted enable_connection_aborted2;
|
|
sock.get_option(enable_connection_aborted2);
|
|
enable_connection_aborted1 = true;
|
|
(void)static_cast<bool>(enable_connection_aborted1);
|
|
(void)static_cast<bool>(!enable_connection_aborted1);
|
|
(void)static_cast<bool>(enable_connection_aborted1.value());
|
|
|
|
// non_blocking_io class.
|
|
|
|
socket_base::non_blocking_io non_blocking_io(true);
|
|
sock.io_control(non_blocking_io);
|
|
|
|
// bytes_readable class.
|
|
|
|
socket_base::bytes_readable bytes_readable;
|
|
sock.io_control(bytes_readable);
|
|
std::size_t bytes = bytes_readable.get();
|
|
(void)bytes;
|
|
}
|
|
catch (std::exception&)
|
|
{
|
|
}
|
|
}
|
|
|
|
} // namespace socket_base_compile
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
// socket_base_runtime test
|
|
// ~~~~~~~~~~~~~~~~~~~~~~~~
|
|
// The following test checks the runtime operation of the socket options and I/O
|
|
// control commands defined in socket_base.
|
|
|
|
namespace socket_base_runtime {
|
|
|
|
void test()
|
|
{
|
|
using namespace boost::asio;
|
|
namespace ip = boost::asio::ip;
|
|
|
|
io_service ios;
|
|
ip::udp::socket udp_sock(ios, ip::udp::v4());
|
|
ip::tcp::socket tcp_sock(ios, ip::tcp::v4());
|
|
ip::tcp::acceptor tcp_acceptor(ios, ip::tcp::v4());
|
|
boost::system::error_code ec;
|
|
|
|
// broadcast class.
|
|
|
|
socket_base::broadcast broadcast1(true);
|
|
BOOST_ASIO_CHECK(broadcast1.value());
|
|
BOOST_ASIO_CHECK(static_cast<bool>(broadcast1));
|
|
BOOST_ASIO_CHECK(!!broadcast1);
|
|
udp_sock.set_option(broadcast1, ec);
|
|
BOOST_ASIO_CHECK_MESSAGE(!ec, ec.value() << ", " << ec.message());
|
|
|
|
socket_base::broadcast broadcast2;
|
|
udp_sock.get_option(broadcast2, ec);
|
|
BOOST_ASIO_CHECK_MESSAGE(!ec, ec.value() << ", " << ec.message());
|
|
BOOST_ASIO_CHECK(broadcast2.value());
|
|
BOOST_ASIO_CHECK(static_cast<bool>(broadcast2));
|
|
BOOST_ASIO_CHECK(!!broadcast2);
|
|
|
|
socket_base::broadcast broadcast3(false);
|
|
BOOST_ASIO_CHECK(!broadcast3.value());
|
|
BOOST_ASIO_CHECK(!static_cast<bool>(broadcast3));
|
|
BOOST_ASIO_CHECK(!broadcast3);
|
|
udp_sock.set_option(broadcast3, ec);
|
|
BOOST_ASIO_CHECK_MESSAGE(!ec, ec.value() << ", " << ec.message());
|
|
|
|
socket_base::broadcast broadcast4;
|
|
udp_sock.get_option(broadcast4, ec);
|
|
BOOST_ASIO_CHECK_MESSAGE(!ec, ec.value() << ", " << ec.message());
|
|
BOOST_ASIO_CHECK(!broadcast4.value());
|
|
BOOST_ASIO_CHECK(!static_cast<bool>(broadcast4));
|
|
BOOST_ASIO_CHECK(!broadcast4);
|
|
|
|
// debug class.
|
|
|
|
socket_base::debug debug1(true);
|
|
BOOST_ASIO_CHECK(debug1.value());
|
|
BOOST_ASIO_CHECK(static_cast<bool>(debug1));
|
|
BOOST_ASIO_CHECK(!!debug1);
|
|
udp_sock.set_option(debug1, ec);
|
|
#if defined(__linux__)
|
|
// On Linux, only root can set SO_DEBUG.
|
|
bool not_root = (ec == boost::asio::error::access_denied);
|
|
BOOST_ASIO_CHECK(!ec || not_root);
|
|
BOOST_ASIO_WARN_MESSAGE(!ec, "Must be root to set debug socket option");
|
|
#else // defined(__linux__)
|
|
# if defined(BOOST_ASIO_WINDOWS) && defined(UNDER_CE)
|
|
// Option is not supported under Windows CE.
|
|
BOOST_ASIO_CHECK_MESSAGE(ec == boost::asio::error::no_protocol_option,
|
|
ec.value() << ", " << ec.message());
|
|
# else // defined(BOOST_ASIO_WINDOWS) && defined(UNDER_CE)
|
|
BOOST_ASIO_CHECK_MESSAGE(!ec, ec.value() << ", " << ec.message());
|
|
# endif // defined(BOOST_ASIO_WINDOWS) && defined(UNDER_CE)
|
|
#endif // defined(__linux__)
|
|
|
|
socket_base::debug debug2;
|
|
udp_sock.get_option(debug2, ec);
|
|
#if defined(BOOST_ASIO_WINDOWS) && defined(UNDER_CE)
|
|
// Option is not supported under Windows CE.
|
|
BOOST_ASIO_CHECK_MESSAGE(ec == boost::asio::error::no_protocol_option,
|
|
ec.value() << ", " << ec.message());
|
|
#else // defined(BOOST_ASIO_WINDOWS) && defined(UNDER_CE)
|
|
BOOST_ASIO_CHECK_MESSAGE(!ec, ec.value() << ", " << ec.message());
|
|
# if defined(__linux__)
|
|
BOOST_ASIO_CHECK(debug2.value() || not_root);
|
|
BOOST_ASIO_CHECK(static_cast<bool>(debug2) || not_root);
|
|
BOOST_ASIO_CHECK(!!debug2 || not_root);
|
|
# else // defined(__linux__)
|
|
BOOST_ASIO_CHECK(debug2.value());
|
|
BOOST_ASIO_CHECK(static_cast<bool>(debug2));
|
|
BOOST_ASIO_CHECK(!!debug2);
|
|
# endif // defined(__linux__)
|
|
#endif // defined(BOOST_ASIO_WINDOWS) && defined(UNDER_CE)
|
|
|
|
socket_base::debug debug3(false);
|
|
BOOST_ASIO_CHECK(!debug3.value());
|
|
BOOST_ASIO_CHECK(!static_cast<bool>(debug3));
|
|
BOOST_ASIO_CHECK(!debug3);
|
|
udp_sock.set_option(debug3, ec);
|
|
#if defined(__linux__)
|
|
BOOST_ASIO_CHECK(!ec || not_root);
|
|
#else // defined(__linux__)
|
|
# if defined(BOOST_ASIO_WINDOWS) && defined(UNDER_CE)
|
|
// Option is not supported under Windows CE.
|
|
BOOST_ASIO_CHECK_MESSAGE(ec == boost::asio::error::no_protocol_option,
|
|
ec.value() << ", " << ec.message());
|
|
# else // defined(BOOST_ASIO_WINDOWS) && defined(UNDER_CE)
|
|
BOOST_ASIO_CHECK_MESSAGE(!ec, ec.value() << ", " << ec.message());
|
|
# endif // defined(BOOST_ASIO_WINDOWS) && defined(UNDER_CE)
|
|
#endif // defined(__linux__)
|
|
|
|
socket_base::debug debug4;
|
|
udp_sock.get_option(debug4, ec);
|
|
#if defined(BOOST_ASIO_WINDOWS) && defined(UNDER_CE)
|
|
// Option is not supported under Windows CE.
|
|
BOOST_ASIO_CHECK_MESSAGE(ec == boost::asio::error::no_protocol_option,
|
|
ec.value() << ", " << ec.message());
|
|
#else // defined(BOOST_ASIO_WINDOWS) && defined(UNDER_CE)
|
|
BOOST_ASIO_CHECK_MESSAGE(!ec, ec.value() << ", " << ec.message());
|
|
# if defined(__linux__)
|
|
BOOST_ASIO_CHECK(!debug4.value() || not_root);
|
|
BOOST_ASIO_CHECK(!static_cast<bool>(debug4) || not_root);
|
|
BOOST_ASIO_CHECK(!debug4 || not_root);
|
|
# else // defined(__linux__)
|
|
BOOST_ASIO_CHECK(!debug4.value());
|
|
BOOST_ASIO_CHECK(!static_cast<bool>(debug4));
|
|
BOOST_ASIO_CHECK(!debug4);
|
|
# endif // defined(__linux__)
|
|
#endif // defined(BOOST_ASIO_WINDOWS) && defined(UNDER_CE)
|
|
|
|
// do_not_route class.
|
|
|
|
socket_base::do_not_route do_not_route1(true);
|
|
BOOST_ASIO_CHECK(do_not_route1.value());
|
|
BOOST_ASIO_CHECK(static_cast<bool>(do_not_route1));
|
|
BOOST_ASIO_CHECK(!!do_not_route1);
|
|
udp_sock.set_option(do_not_route1, ec);
|
|
#if defined(BOOST_ASIO_WINDOWS) && defined(UNDER_CE)
|
|
// Option is not supported under Windows CE.
|
|
BOOST_ASIO_CHECK_MESSAGE(ec == boost::asio::error::no_protocol_option,
|
|
ec.value() << ", " << ec.message());
|
|
#else // defined(BOOST_ASIO_WINDOWS) && defined(UNDER_CE)
|
|
BOOST_ASIO_CHECK_MESSAGE(!ec, ec.value() << ", " << ec.message());
|
|
#endif // defined(BOOST_ASIO_WINDOWS) && defined(UNDER_CE)
|
|
|
|
socket_base::do_not_route do_not_route2;
|
|
udp_sock.get_option(do_not_route2, ec);
|
|
#if defined(BOOST_ASIO_WINDOWS) && defined(UNDER_CE)
|
|
// Option is not supported under Windows CE.
|
|
BOOST_ASIO_CHECK_MESSAGE(ec == boost::asio::error::no_protocol_option,
|
|
ec.value() << ", " << ec.message());
|
|
#else // defined(BOOST_ASIO_WINDOWS) && defined(UNDER_CE)
|
|
BOOST_ASIO_CHECK_MESSAGE(!ec, ec.value() << ", " << ec.message());
|
|
BOOST_ASIO_CHECK(do_not_route2.value());
|
|
BOOST_ASIO_CHECK(static_cast<bool>(do_not_route2));
|
|
BOOST_ASIO_CHECK(!!do_not_route2);
|
|
#endif // defined(BOOST_ASIO_WINDOWS) && defined(UNDER_CE)
|
|
|
|
socket_base::do_not_route do_not_route3(false);
|
|
BOOST_ASIO_CHECK(!do_not_route3.value());
|
|
BOOST_ASIO_CHECK(!static_cast<bool>(do_not_route3));
|
|
BOOST_ASIO_CHECK(!do_not_route3);
|
|
udp_sock.set_option(do_not_route3, ec);
|
|
#if defined(BOOST_ASIO_WINDOWS) && defined(UNDER_CE)
|
|
// Option is not supported under Windows CE.
|
|
BOOST_ASIO_CHECK_MESSAGE(ec == boost::asio::error::no_protocol_option,
|
|
ec.value() << ", " << ec.message());
|
|
#else // defined(BOOST_ASIO_WINDOWS) && defined(UNDER_CE)
|
|
BOOST_ASIO_CHECK_MESSAGE(!ec, ec.value() << ", " << ec.message());
|
|
#endif // defined(BOOST_ASIO_WINDOWS) && defined(UNDER_CE)
|
|
|
|
socket_base::do_not_route do_not_route4;
|
|
udp_sock.get_option(do_not_route4, ec);
|
|
#if defined(BOOST_ASIO_WINDOWS) && defined(UNDER_CE)
|
|
// Option is not supported under Windows CE.
|
|
BOOST_ASIO_CHECK_MESSAGE(ec == boost::asio::error::no_protocol_option,
|
|
ec.value() << ", " << ec.message());
|
|
#else // defined(BOOST_ASIO_WINDOWS) && defined(UNDER_CE)
|
|
BOOST_ASIO_CHECK_MESSAGE(!ec, ec.value() << ", " << ec.message());
|
|
BOOST_ASIO_CHECK(!do_not_route4.value());
|
|
BOOST_ASIO_CHECK(!static_cast<bool>(do_not_route4));
|
|
BOOST_ASIO_CHECK(!do_not_route4);
|
|
#endif // defined(BOOST_ASIO_WINDOWS) && defined(UNDER_CE)
|
|
|
|
// keep_alive class.
|
|
|
|
socket_base::keep_alive keep_alive1(true);
|
|
BOOST_ASIO_CHECK(keep_alive1.value());
|
|
BOOST_ASIO_CHECK(static_cast<bool>(keep_alive1));
|
|
BOOST_ASIO_CHECK(!!keep_alive1);
|
|
tcp_sock.set_option(keep_alive1, ec);
|
|
BOOST_ASIO_CHECK_MESSAGE(!ec, ec.value() << ", " << ec.message());
|
|
|
|
socket_base::keep_alive keep_alive2;
|
|
tcp_sock.get_option(keep_alive2, ec);
|
|
BOOST_ASIO_CHECK_MESSAGE(!ec, ec.value() << ", " << ec.message());
|
|
BOOST_ASIO_CHECK(keep_alive2.value());
|
|
BOOST_ASIO_CHECK(static_cast<bool>(keep_alive2));
|
|
BOOST_ASIO_CHECK(!!keep_alive2);
|
|
|
|
socket_base::keep_alive keep_alive3(false);
|
|
BOOST_ASIO_CHECK(!keep_alive3.value());
|
|
BOOST_ASIO_CHECK(!static_cast<bool>(keep_alive3));
|
|
BOOST_ASIO_CHECK(!keep_alive3);
|
|
tcp_sock.set_option(keep_alive3, ec);
|
|
BOOST_ASIO_CHECK_MESSAGE(!ec, ec.value() << ", " << ec.message());
|
|
|
|
socket_base::keep_alive keep_alive4;
|
|
tcp_sock.get_option(keep_alive4, ec);
|
|
BOOST_ASIO_CHECK_MESSAGE(!ec, ec.value() << ", " << ec.message());
|
|
BOOST_ASIO_CHECK(!keep_alive4.value());
|
|
BOOST_ASIO_CHECK(!static_cast<bool>(keep_alive4));
|
|
BOOST_ASIO_CHECK(!keep_alive4);
|
|
|
|
// send_buffer_size class.
|
|
|
|
socket_base::send_buffer_size send_buffer_size1(4096);
|
|
BOOST_ASIO_CHECK(send_buffer_size1.value() == 4096);
|
|
tcp_sock.set_option(send_buffer_size1, ec);
|
|
BOOST_ASIO_CHECK_MESSAGE(!ec, ec.value() << ", " << ec.message());
|
|
|
|
socket_base::send_buffer_size send_buffer_size2;
|
|
tcp_sock.get_option(send_buffer_size2, ec);
|
|
BOOST_ASIO_CHECK_MESSAGE(!ec, ec.value() << ", " << ec.message());
|
|
BOOST_ASIO_CHECK(send_buffer_size2.value() == 4096);
|
|
|
|
socket_base::send_buffer_size send_buffer_size3(16384);
|
|
BOOST_ASIO_CHECK(send_buffer_size3.value() == 16384);
|
|
tcp_sock.set_option(send_buffer_size3, ec);
|
|
BOOST_ASIO_CHECK_MESSAGE(!ec, ec.value() << ", " << ec.message());
|
|
|
|
socket_base::send_buffer_size send_buffer_size4;
|
|
tcp_sock.get_option(send_buffer_size4, ec);
|
|
BOOST_ASIO_CHECK_MESSAGE(!ec, ec.value() << ", " << ec.message());
|
|
BOOST_ASIO_CHECK(send_buffer_size4.value() == 16384);
|
|
|
|
// send_low_watermark class.
|
|
|
|
socket_base::send_low_watermark send_low_watermark1(4096);
|
|
BOOST_ASIO_CHECK(send_low_watermark1.value() == 4096);
|
|
tcp_sock.set_option(send_low_watermark1, ec);
|
|
#if defined(WIN32) || defined(__linux__) || defined(__sun)
|
|
BOOST_ASIO_CHECK(!!ec); // Not supported on Windows, Linux or Solaris.
|
|
#else
|
|
BOOST_ASIO_CHECK_MESSAGE(!ec, ec.value() << ", " << ec.message());
|
|
#endif
|
|
|
|
socket_base::send_low_watermark send_low_watermark2;
|
|
tcp_sock.get_option(send_low_watermark2, ec);
|
|
#if defined(WIN32) || defined(__sun)
|
|
BOOST_ASIO_CHECK(!!ec); // Not supported on Windows or Solaris.
|
|
#elif defined(__linux__)
|
|
BOOST_ASIO_CHECK(!ec); // Not supported on Linux but can get value.
|
|
#else
|
|
BOOST_ASIO_CHECK_MESSAGE(!ec, ec.value() << ", " << ec.message());
|
|
BOOST_ASIO_CHECK(send_low_watermark2.value() == 4096);
|
|
#endif
|
|
|
|
socket_base::send_low_watermark send_low_watermark3(8192);
|
|
BOOST_ASIO_CHECK(send_low_watermark3.value() == 8192);
|
|
tcp_sock.set_option(send_low_watermark3, ec);
|
|
#if defined(WIN32) || defined(__linux__) || defined(__sun)
|
|
BOOST_ASIO_CHECK(!!ec); // Not supported on Windows, Linux or Solaris.
|
|
#else
|
|
BOOST_ASIO_CHECK_MESSAGE(!ec, ec.value() << ", " << ec.message());
|
|
#endif
|
|
|
|
socket_base::send_low_watermark send_low_watermark4;
|
|
tcp_sock.get_option(send_low_watermark4, ec);
|
|
#if defined(WIN32) || defined(__sun)
|
|
BOOST_ASIO_CHECK(!!ec); // Not supported on Windows or Solaris.
|
|
#elif defined(__linux__)
|
|
BOOST_ASIO_CHECK(!ec); // Not supported on Linux but can get value.
|
|
#else
|
|
BOOST_ASIO_CHECK_MESSAGE(!ec, ec.value() << ", " << ec.message());
|
|
BOOST_ASIO_CHECK(send_low_watermark4.value() == 8192);
|
|
#endif
|
|
|
|
// receive_buffer_size class.
|
|
|
|
socket_base::receive_buffer_size receive_buffer_size1(4096);
|
|
BOOST_ASIO_CHECK(receive_buffer_size1.value() == 4096);
|
|
tcp_sock.set_option(receive_buffer_size1, ec);
|
|
#if defined(BOOST_ASIO_WINDOWS) && defined(UNDER_CE)
|
|
// Option is not supported under Windows CE.
|
|
BOOST_ASIO_CHECK_MESSAGE(ec == boost::asio::error::no_protocol_option,
|
|
ec.value() << ", " << ec.message());
|
|
#else // defined(BOOST_ASIO_WINDOWS) && defined(UNDER_CE)
|
|
BOOST_ASIO_CHECK_MESSAGE(!ec, ec.value() << ", " << ec.message());
|
|
#endif // defined(BOOST_ASIO_WINDOWS) && defined(UNDER_CE)
|
|
|
|
socket_base::receive_buffer_size receive_buffer_size2;
|
|
tcp_sock.get_option(receive_buffer_size2, ec);
|
|
#if defined(BOOST_ASIO_WINDOWS) && defined(UNDER_CE)
|
|
BOOST_ASIO_CHECK(!ec); // Not supported under Windows CE but can get value.
|
|
#else // defined(BOOST_ASIO_WINDOWS) && defined(UNDER_CE)
|
|
BOOST_ASIO_CHECK_MESSAGE(!ec, ec.value() << ", " << ec.message());
|
|
BOOST_ASIO_CHECK(receive_buffer_size2.value() == 4096);
|
|
#endif // defined(BOOST_ASIO_WINDOWS) && defined(UNDER_CE)
|
|
|
|
socket_base::receive_buffer_size receive_buffer_size3(16384);
|
|
BOOST_ASIO_CHECK(receive_buffer_size3.value() == 16384);
|
|
tcp_sock.set_option(receive_buffer_size3, ec);
|
|
#if defined(BOOST_ASIO_WINDOWS) && defined(UNDER_CE)
|
|
// Option is not supported under Windows CE.
|
|
BOOST_ASIO_CHECK_MESSAGE(ec == boost::asio::error::no_protocol_option,
|
|
ec.value() << ", " << ec.message());
|
|
#else // defined(BOOST_ASIO_WINDOWS) && defined(UNDER_CE)
|
|
BOOST_ASIO_CHECK_MESSAGE(!ec, ec.value() << ", " << ec.message());
|
|
#endif // defined(BOOST_ASIO_WINDOWS) && defined(UNDER_CE)
|
|
|
|
socket_base::receive_buffer_size receive_buffer_size4;
|
|
tcp_sock.get_option(receive_buffer_size4, ec);
|
|
#if defined(BOOST_ASIO_WINDOWS) && defined(UNDER_CE)
|
|
BOOST_ASIO_CHECK(!ec); // Not supported under Windows CE but can get value.
|
|
#else // defined(BOOST_ASIO_WINDOWS) && defined(UNDER_CE)
|
|
BOOST_ASIO_CHECK_MESSAGE(!ec, ec.value() << ", " << ec.message());
|
|
BOOST_ASIO_CHECK(receive_buffer_size4.value() == 16384);
|
|
#endif // defined(BOOST_ASIO_WINDOWS) && defined(UNDER_CE)
|
|
|
|
// receive_low_watermark class.
|
|
|
|
socket_base::receive_low_watermark receive_low_watermark1(4096);
|
|
BOOST_ASIO_CHECK(receive_low_watermark1.value() == 4096);
|
|
tcp_sock.set_option(receive_low_watermark1, ec);
|
|
#if defined(WIN32) || defined(__sun)
|
|
BOOST_ASIO_CHECK(!!ec); // Not supported on Windows or Solaris.
|
|
#else
|
|
BOOST_ASIO_CHECK_MESSAGE(!ec, ec.value() << ", " << ec.message());
|
|
#endif
|
|
|
|
socket_base::receive_low_watermark receive_low_watermark2;
|
|
tcp_sock.get_option(receive_low_watermark2, ec);
|
|
#if defined(WIN32) || defined(__sun)
|
|
BOOST_ASIO_CHECK(!!ec); // Not supported on Windows or Solaris.
|
|
#else
|
|
BOOST_ASIO_CHECK_MESSAGE(!ec, ec.value() << ", " << ec.message());
|
|
BOOST_ASIO_CHECK(receive_low_watermark2.value() == 4096);
|
|
#endif
|
|
|
|
socket_base::receive_low_watermark receive_low_watermark3(8192);
|
|
BOOST_ASIO_CHECK(receive_low_watermark3.value() == 8192);
|
|
tcp_sock.set_option(receive_low_watermark3, ec);
|
|
#if defined(WIN32) || defined(__sun)
|
|
BOOST_ASIO_CHECK(!!ec); // Not supported on Windows or Solaris.
|
|
#else
|
|
BOOST_ASIO_CHECK_MESSAGE(!ec, ec.value() << ", " << ec.message());
|
|
#endif
|
|
|
|
socket_base::receive_low_watermark receive_low_watermark4;
|
|
tcp_sock.get_option(receive_low_watermark4, ec);
|
|
#if defined(WIN32) || defined(__sun)
|
|
BOOST_ASIO_CHECK(!!ec); // Not supported on Windows or Solaris.
|
|
#else
|
|
BOOST_ASIO_CHECK_MESSAGE(!ec, ec.value() << ", " << ec.message());
|
|
BOOST_ASIO_CHECK(receive_low_watermark4.value() == 8192);
|
|
#endif
|
|
|
|
// reuse_address class.
|
|
|
|
socket_base::reuse_address reuse_address1(true);
|
|
BOOST_ASIO_CHECK(reuse_address1.value());
|
|
BOOST_ASIO_CHECK(static_cast<bool>(reuse_address1));
|
|
BOOST_ASIO_CHECK(!!reuse_address1);
|
|
udp_sock.set_option(reuse_address1, ec);
|
|
BOOST_ASIO_CHECK_MESSAGE(!ec, ec.value() << ", " << ec.message());
|
|
|
|
socket_base::reuse_address reuse_address2;
|
|
udp_sock.get_option(reuse_address2, ec);
|
|
BOOST_ASIO_CHECK_MESSAGE(!ec, ec.value() << ", " << ec.message());
|
|
BOOST_ASIO_CHECK(reuse_address2.value());
|
|
BOOST_ASIO_CHECK(static_cast<bool>(reuse_address2));
|
|
BOOST_ASIO_CHECK(!!reuse_address2);
|
|
|
|
socket_base::reuse_address reuse_address3(false);
|
|
BOOST_ASIO_CHECK(!reuse_address3.value());
|
|
BOOST_ASIO_CHECK(!static_cast<bool>(reuse_address3));
|
|
BOOST_ASIO_CHECK(!reuse_address3);
|
|
udp_sock.set_option(reuse_address3, ec);
|
|
BOOST_ASIO_CHECK_MESSAGE(!ec, ec.value() << ", " << ec.message());
|
|
|
|
socket_base::reuse_address reuse_address4;
|
|
udp_sock.get_option(reuse_address4, ec);
|
|
BOOST_ASIO_CHECK_MESSAGE(!ec, ec.value() << ", " << ec.message());
|
|
BOOST_ASIO_CHECK(!reuse_address4.value());
|
|
BOOST_ASIO_CHECK(!static_cast<bool>(reuse_address4));
|
|
BOOST_ASIO_CHECK(!reuse_address4);
|
|
|
|
// linger class.
|
|
|
|
socket_base::linger linger1(true, 60);
|
|
BOOST_ASIO_CHECK(linger1.enabled());
|
|
BOOST_ASIO_CHECK(linger1.timeout() == 60);
|
|
tcp_sock.set_option(linger1, ec);
|
|
BOOST_ASIO_CHECK_MESSAGE(!ec, ec.value() << ", " << ec.message());
|
|
|
|
socket_base::linger linger2;
|
|
tcp_sock.get_option(linger2, ec);
|
|
BOOST_ASIO_CHECK_MESSAGE(!ec, ec.value() << ", " << ec.message());
|
|
BOOST_ASIO_CHECK(linger2.enabled());
|
|
BOOST_ASIO_CHECK(linger2.timeout() == 60);
|
|
|
|
socket_base::linger linger3(false, 0);
|
|
BOOST_ASIO_CHECK(!linger3.enabled());
|
|
BOOST_ASIO_CHECK(linger3.timeout() == 0);
|
|
tcp_sock.set_option(linger3, ec);
|
|
BOOST_ASIO_CHECK_MESSAGE(!ec, ec.value() << ", " << ec.message());
|
|
|
|
socket_base::linger linger4;
|
|
tcp_sock.get_option(linger4, ec);
|
|
BOOST_ASIO_CHECK_MESSAGE(!ec, ec.value() << ", " << ec.message());
|
|
BOOST_ASIO_CHECK(!linger4.enabled());
|
|
|
|
// enable_connection_aborted class.
|
|
|
|
socket_base::enable_connection_aborted enable_connection_aborted1(true);
|
|
BOOST_ASIO_CHECK(enable_connection_aborted1.value());
|
|
BOOST_ASIO_CHECK(static_cast<bool>(enable_connection_aborted1));
|
|
BOOST_ASIO_CHECK(!!enable_connection_aborted1);
|
|
tcp_acceptor.set_option(enable_connection_aborted1, ec);
|
|
BOOST_ASIO_CHECK_MESSAGE(!ec, ec.value() << ", " << ec.message());
|
|
|
|
socket_base::enable_connection_aborted enable_connection_aborted2;
|
|
tcp_acceptor.get_option(enable_connection_aborted2, ec);
|
|
BOOST_ASIO_CHECK_MESSAGE(!ec, ec.value() << ", " << ec.message());
|
|
BOOST_ASIO_CHECK(enable_connection_aborted2.value());
|
|
BOOST_ASIO_CHECK(static_cast<bool>(enable_connection_aborted2));
|
|
BOOST_ASIO_CHECK(!!enable_connection_aborted2);
|
|
|
|
socket_base::enable_connection_aborted enable_connection_aborted3(false);
|
|
BOOST_ASIO_CHECK(!enable_connection_aborted3.value());
|
|
BOOST_ASIO_CHECK(!static_cast<bool>(enable_connection_aborted3));
|
|
BOOST_ASIO_CHECK(!enable_connection_aborted3);
|
|
tcp_acceptor.set_option(enable_connection_aborted3, ec);
|
|
BOOST_ASIO_CHECK_MESSAGE(!ec, ec.value() << ", " << ec.message());
|
|
|
|
socket_base::enable_connection_aborted enable_connection_aborted4;
|
|
tcp_acceptor.get_option(enable_connection_aborted4, ec);
|
|
BOOST_ASIO_CHECK_MESSAGE(!ec, ec.value() << ", " << ec.message());
|
|
BOOST_ASIO_CHECK(!enable_connection_aborted4.value());
|
|
BOOST_ASIO_CHECK(!static_cast<bool>(enable_connection_aborted4));
|
|
BOOST_ASIO_CHECK(!enable_connection_aborted4);
|
|
|
|
// non_blocking_io class.
|
|
|
|
socket_base::non_blocking_io non_blocking_io1(true);
|
|
tcp_sock.io_control(non_blocking_io1, ec);
|
|
BOOST_ASIO_CHECK_MESSAGE(!ec, ec.value() << ", " << ec.message());
|
|
|
|
socket_base::non_blocking_io non_blocking_io2(false);
|
|
tcp_sock.io_control(non_blocking_io2, ec);
|
|
BOOST_ASIO_CHECK_MESSAGE(!ec, ec.value() << ", " << ec.message());
|
|
|
|
// bytes_readable class.
|
|
|
|
socket_base::bytes_readable bytes_readable;
|
|
udp_sock.io_control(bytes_readable, ec);
|
|
BOOST_ASIO_CHECK_MESSAGE(!ec, ec.value() << ", " << ec.message());
|
|
}
|
|
|
|
} // namespace socket_base_runtime
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
BOOST_ASIO_TEST_SUITE
|
|
(
|
|
"socket_base",
|
|
BOOST_ASIO_TEST_CASE(socket_base_compile::test)
|
|
BOOST_ASIO_TEST_CASE(socket_base_runtime::test)
|
|
)
|