RESTinio
asio_include.hpp
Go to the documentation of this file.
1/*
2 restinio
3*/
4
9#pragma once
10
11#if !defined(RESTINIO_USE_BOOST_ASIO)
12
13// RESTinio uses stand-alone version of asio.
14#include <asio.hpp>
15
16// Define added to not have to distinguish between boost and non-boost asio in
17// other code.
18#define RESTINIO_ASIO_VERSION ASIO_VERSION
19
20namespace restinio
21{
22 namespace asio_ns = ::asio;
23
26 inline bool
27 error_is_operation_aborted( const asio_ns::error_code & ec ) noexcept
28 {
29 return ec == asio_ns::error::operation_aborted;
30 }
31
32 inline bool
33 error_is_eof( const asio_ns::error_code & ec ) noexcept
34 {
35 return ec == asio_ns::error::eof;
36 }
38
39 namespace asio_ec
40 {
41 constexpr auto eof = asio_ns::error::eof;
42 inline const auto & system_category() { return asio_ns::system_category(); }
43 } /* namespace err */
45
47 using error_category_base_t = asio_ns::error_category;
48
49// Define a proxy macro for having the same name for asio stand-alone and boost.
50#define RESTINIO_ERROR_CATEGORY_NAME_NOEXCEPT ASIO_ERROR_CATEGORY_NOEXCEPT
51
52} /* namespace restinio */
53
54 #if defined(ASIO_HAS_WINDOWS_OVERLAPPED_PTR)
55 // Define feature macro with the same name for stand-alone and boost asio.
56 #define RESTINIO_ASIO_HAS_WINDOWS_OVERLAPPED_PTR
57 #endif
58
59#else
60
61// RESTinio uses boost::asio.
62#include <boost/asio.hpp>
63
64// Define added to not have to distinguish between boost and non-boost asio in
65// other code.
66#define RESTINIO_ASIO_VERSION BOOST_ASIO_VERSION
67
68namespace restinio
69{
70
71 namespace asio_ns
72 {
73 using namespace ::boost::asio;
74 using error_code = ::boost::system::error_code;
75 } /* namespace asio_ns */
76
79 inline bool error_is_operation_aborted( const asio_ns::error_code & ec )
80 {
81 return ec == asio_ns::error::basic_errors::operation_aborted;
82 }
83
84 inline bool error_is_eof( const asio_ns::error_code & ec )
85 {
87 }
89
90 namespace asio_ec
91 {
93
95
96 } /* namespace err */
97
99 using error_category_base_t = ::boost::system::error_category;
100
101 // Define a proxy macro for having the same name for asio stand-alone and boost.
102 #define RESTINIO_ERROR_CATEGORY_NAME_NOEXCEPT BOOST_SYSTEM_NOEXCEPT
103
104} /* namespace restinio */
105
106 #if defined(BOOST_ASIO_HAS_WINDOWS_OVERLAPPED_PTR)
107 // Define feature macro with the same name for stand-alone and boost asio.
108 #define RESTINIO_ASIO_HAS_WINDOWS_OVERLAPPED_PTR
109 #endif
110
111#endif
112
113namespace restinio
114{
115
116
118/*
119 @since v.0.4.8
120*/
122{
123 // Notificators error.
124
128
133
136
140
143
147};
148
149namespace impl
150{
151
153/*
154 @since v.0.4.8
155*/
157{
158 public:
159 virtual const char*
161 {
162 return "restinio";
163 }
164
165 virtual std::string
166 message( int value ) const override
167 {
168 std::string result{};
169 switch( static_cast< asio_convertible_error_t >( value ) )
170 {
172 result.assign( "write operation was not" );
173 break;
175 result.assign(
176 "write group destroyed without external notificato invokation" );
177 break;
179 result.assign(
180 "a call to async_write() failed" );
181 break;
183 result.assign(
184 "a call to async_read_some_at_call_failed() failed" );
185 break;
186 }
187
188 return result;
189 }
190};
191
192} /* namespace impl */
193
195/*
196 @since v.0.4.8
197*/
198inline const error_category_base_t &
200{
201 static impl::restinio_err_category_t instance;
202 return instance;
203}
204
206/*
207 @since v.0.4.8
208*/
209inline asio_ns::error_code
211{
212 return asio_ns::error_code{ static_cast< int >( err ), restinio_err_category() };
213}
214
215// Since Asio 1.17 the usage of asio::executor requires
216// a special define ASIO_USE_TS_EXECUTOR_AS_DEFAULT (otherwise the
217// code won't compile).
218// A new name any_io_executor is introduced in Asio 1.17.
219// We'll use that name for Asio 1.17 or newer.
220// Old name asio::executor will be used for older versions of Asio.
221#if RESTINIO_ASIO_VERSION >= 101700
222 using default_asio_executor = asio_ns::any_io_executor;
223#else
224 using default_asio_executor = asio_ns::executor;
225#endif
226
227} /* namespace restinio */
228
#define RESTINIO_ERROR_CATEGORY_NAME_NOEXCEPT
Error category for asio compatible error codes.
virtual std::string message(int value) const override
virtual const char * name() const RESTINIO_ERROR_CATEGORY_NAME_NOEXCEPT override
constexpr auto eof
const auto & system_category()
asio_ns::executor default_asio_executor
bool error_is_operation_aborted(const asio_ns::error_code &ec) noexcept
asio_convertible_error_t
Enum for restinio errors that must presented as asio_ns::error_code value.
@ write_was_not_executed
After write notificator error: data was not sent, connection closed (or aborted) before a given piece...
@ async_read_some_at_call_failed
A call to async_read_some_at failed. The corresponding sendfile operation wasn't done.
@ write_group_destroyed_passively
After write notificator error: a notificator was set for a write_group_t but no external invokation h...
@ async_write_call_failed
A call to async_write failed. The corresponding write operation wasn't done.
bool error_is_eof(const asio_ns::error_code &ec) noexcept
asio_ns::error_category error_category_base_t
An alias for base class of error category entity.
asio_ns::error_code make_asio_compaible_error(asio_convertible_error_t err) noexcept
Make restinio error_code compatible with asio_ns::error_code.
const error_category_base_t & restinio_err_category()
Get restinio error category.
#define const
Definition: zconf.h:230