is_write_buffered.cpp
2.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
//
// is_write_buffered.cpp
// ~~~~~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2020 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)
)