2 // is_write_buffered.cpp
3 // ~~~~~~~~~~~~~~~~~~~~~
5 // Copyright (c) 2003-2022 Christopher M. Kohlhoff (chris at kohlhoff dot com)
7 // Distributed under the Boost Software License, Version 1.0. (See accompanying
8 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
11 // Disable autolinking for unit tests.
12 #if !defined(BOOST_ALL_NO_LIB)
13 #define BOOST_ALL_NO_LIB 1
14 #endif // !defined(BOOST_ALL_NO_LIB)
16 // Test that header file is self-contained.
17 #include <boost/asio/is_write_buffered.hpp>
19 #include <boost/asio/buffered_read_stream.hpp>
20 #include <boost/asio/buffered_write_stream.hpp>
21 #include <boost/asio/io_context.hpp>
22 #include <boost/asio/ip/tcp.hpp>
23 #include "unit_test.hpp"
25 using namespace std
; // For memcmp, memcpy and memset.
30 typedef boost::asio::io_context io_context_type
;
32 typedef test_stream lowest_layer_type
;
34 typedef io_context_type::executor_type executor_type
;
36 test_stream(boost::asio::io_context
& io_context
)
37 : io_context_(io_context
)
41 io_context_type
& io_context()
46 lowest_layer_type
& lowest_layer()
51 template <typename Const_Buffers
>
52 size_t write(const Const_Buffers
&)
57 template <typename Const_Buffers
>
58 size_t write(const Const_Buffers
&, boost::system::error_code
& ec
)
60 ec
= boost::system::error_code();
64 template <typename Const_Buffers
, typename Handler
>
65 void async_write(const Const_Buffers
&, Handler handler
)
67 boost::system::error_code error
;
68 boost::asio::post(io_context_
,
69 boost::asio::detail::bind_handler(handler
, error
, 0));
72 template <typename Mutable_Buffers
>
73 size_t read(const Mutable_Buffers
&)
78 template <typename Mutable_Buffers
>
79 size_t read(const Mutable_Buffers
&, boost::system::error_code
& ec
)
81 ec
= boost::system::error_code();
85 template <typename Mutable_Buffers
, typename Handler
>
86 void async_read(const Mutable_Buffers
&, Handler handler
)
88 boost::system::error_code error
;
89 boost::asio::post(io_context_
,
90 boost::asio::detail::bind_handler(handler
, error
, 0));
94 io_context_type
& io_context_
;
97 void is_write_buffered_test()
99 BOOST_ASIO_CHECK(!boost::asio::is_write_buffered
<
100 boost::asio::ip::tcp::socket
>::value
);
102 BOOST_ASIO_CHECK(!boost::asio::is_write_buffered
<
103 boost::asio::buffered_read_stream
<
104 boost::asio::ip::tcp::socket
> >::value
);
106 BOOST_ASIO_CHECK(!!boost::asio::is_write_buffered
<
107 boost::asio::buffered_write_stream
<
108 boost::asio::ip::tcp::socket
> >::value
);
110 BOOST_ASIO_CHECK(!!boost::asio::is_write_buffered
<
111 boost::asio::buffered_stream
<boost::asio::ip::tcp::socket
> >::value
);
113 BOOST_ASIO_CHECK(!boost::asio::is_write_buffered
<test_stream
>::value
);
115 BOOST_ASIO_CHECK(!boost::asio::is_write_buffered
<
116 boost::asio::buffered_read_stream
<test_stream
> >::value
);
118 BOOST_ASIO_CHECK(!!boost::asio::is_write_buffered
<
119 boost::asio::buffered_write_stream
<test_stream
> >::value
);
121 BOOST_ASIO_CHECK(!!boost::asio::is_write_buffered
<
122 boost::asio::buffered_stream
<test_stream
> >::value
);
125 BOOST_ASIO_TEST_SUITE
128 BOOST_ASIO_TEST_CASE(is_write_buffered_test
)