• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //
2 // is_read_buffered.cpp
3 // ~~~~~~~~~~~~~~~~~~~~
4 //
5 // Copyright (c) 2003-2021 Christopher M. Kohlhoff (chris at kohlhoff dot com)
6 //
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)
9 //
10 
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)
15 
16 // Test that header file is self-contained.
17 #include <boost/asio/is_read_buffered.hpp>
18 
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"
24 
25 using namespace std; // For memcmp, memcpy and memset.
26 
27 class test_stream
28 {
29 public:
30   typedef boost::asio::io_context io_context_type;
31 
32   typedef test_stream lowest_layer_type;
33 
34   typedef io_context_type::executor_type executor_type;
35 
test_stream(boost::asio::io_context & io_context)36   test_stream(boost::asio::io_context& io_context)
37     : io_context_(io_context)
38   {
39   }
40 
io_context()41   io_context_type& io_context()
42   {
43     return io_context_;
44   }
45 
lowest_layer()46   lowest_layer_type& lowest_layer()
47   {
48     return *this;
49   }
50 
51   template <typename Const_Buffers>
write(const Const_Buffers &)52   size_t write(const Const_Buffers&)
53   {
54     return 0;
55   }
56 
57   template <typename Const_Buffers>
write(const Const_Buffers &,boost::system::error_code & ec)58   size_t write(const Const_Buffers&, boost::system::error_code& ec)
59   {
60     ec = boost::system::error_code();
61     return 0;
62   }
63 
64   template <typename Const_Buffers, typename Handler>
async_write(const Const_Buffers &,Handler handler)65   void async_write(const Const_Buffers&, Handler handler)
66   {
67     boost::system::error_code error;
68     boost::asio::post(io_context_,
69         boost::asio::detail::bind_handler(handler, error, 0));
70   }
71 
72   template <typename Mutable_Buffers>
read(const Mutable_Buffers &)73   size_t read(const Mutable_Buffers&)
74   {
75     return 0;
76   }
77 
78   template <typename Mutable_Buffers>
read(const Mutable_Buffers &,boost::system::error_code & ec)79   size_t read(const Mutable_Buffers&, boost::system::error_code& ec)
80   {
81     ec = boost::system::error_code();
82     return 0;
83   }
84 
85   template <typename Mutable_Buffers, typename Handler>
async_read(const Mutable_Buffers &,Handler handler)86   void async_read(const Mutable_Buffers&, Handler handler)
87   {
88     boost::system::error_code error;
89     boost::asio::post(io_context_,
90         boost::asio::detail::bind_handler(handler, error, 0));
91   }
92 
93 private:
94   io_context_type& io_context_;
95 };
96 
is_read_buffered_test()97 void is_read_buffered_test()
98 {
99   BOOST_ASIO_CHECK(!boost::asio::is_read_buffered<
100       boost::asio::ip::tcp::socket>::value);
101 
102   BOOST_ASIO_CHECK(!!boost::asio::is_read_buffered<
103       boost::asio::buffered_read_stream<
104         boost::asio::ip::tcp::socket> >::value);
105 
106   BOOST_ASIO_CHECK(!boost::asio::is_read_buffered<
107       boost::asio::buffered_write_stream<
108         boost::asio::ip::tcp::socket> >::value);
109 
110   BOOST_ASIO_CHECK(!!boost::asio::is_read_buffered<
111       boost::asio::buffered_stream<boost::asio::ip::tcp::socket> >::value);
112 
113   BOOST_ASIO_CHECK(!boost::asio::is_read_buffered<test_stream>::value);
114 
115   BOOST_ASIO_CHECK(!!boost::asio::is_read_buffered<
116       boost::asio::buffered_read_stream<test_stream> >::value);
117 
118   BOOST_ASIO_CHECK(!boost::asio::is_read_buffered<
119       boost::asio::buffered_write_stream<test_stream> >::value);
120 
121   BOOST_ASIO_CHECK(!!boost::asio::is_read_buffered<
122       boost::asio::buffered_stream<test_stream> >::value);
123 }
124 
125 BOOST_ASIO_TEST_SUITE
126 (
127   "is_read_buffered",
128   BOOST_ASIO_TEST_CASE(is_read_buffered_test)
129 )
130