Skip to content

Commit 6498c29

Browse files
committed
use std::error_code instead of system::error_code
Closes #162
1 parent fb0a9c8 commit 6498c29

11 files changed

Lines changed: 47 additions & 105 deletions

File tree

‎example/server/main.cpp‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,8 @@
1414
#include <boost/beast2/error.hpp>
1515
#include <boost/beast2/http_server.hpp>
1616
#include <boost/beast2/https_server.hpp>
17-
#include <boost/capy/buffers/string_dynamic_buffer.hpp>
1817
#include <boost/capy/ex/thread_pool.hpp>
19-
#include <boost/capy/io/push_to.hpp>
18+
#include <boost/http/io/push_to.hpp>
2019
#include <boost/capy/read.hpp>
2120
#include <boost/corosio/signal_set.hpp>
2221
#include <boost/http/json/json_sink.hpp>
@@ -172,7 +171,7 @@ int server_main( int argc, char* argv[] )
172171
if(rp.req.method() != http::method::post)
173172
co_return http::route_next;
174173
http::json_sink js;
175-
auto [ec, n] = co_await capy::push_to(rp.req_body, js);
174+
auto [ec, n] = co_await http::push_to(rp.req_body, js);
176175
if(ec)
177176
co_return http::route_error(ec);
178177
json::value jv = js.release();

‎example/server/serve_log_admin.cpp‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class serve_log_page
2727
{
2828
}
2929

30-
system::error_code
30+
std::error_code
3131
operator()(
3232
http::route_params&) const
3333
{
@@ -95,7 +95,7 @@ class handle_submit
9595
{
9696
}
9797

98-
system::error_code
98+
std::error_code
9999
operator()(
100100
http::route_params&) const
101101
{

‎include/boost/beast2/detail/config.hpp‎

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -29,31 +29,13 @@ namespace beast2 {
2929
# define BOOST_BEAST2_DECL
3030
# endif
3131
# if !defined(BOOST_BEAST2_SOURCE) && !defined(BOOST_ALL_NO_LIB) && !defined(BOOST_BEAST2_NO_LIB)
32-
# define BOOST_LIB_NAME boost_json
32+
# define BOOST_LIB_NAME boost_beast2
3333
# if defined(BOOST_ALL_DYN_LINK) || defined(BOOST_BEAST2_DYN_LINK)
3434
# define BOOST_DYN_LINK
3535
# endif
3636
# include <boost/config/auto_link.hpp>
3737
# endif
3838

39-
//------------------------------------------------
40-
41-
// Add source location to error codes
42-
#ifdef BOOST_BEAST2_NO_SOURCE_LOCATION
43-
# define BOOST_BEAST2_ERR(ev) (::boost::system::error_code(ev))
44-
# define BOOST_BEAST2_RETURN_EC(ev) return (ev)
45-
#else
46-
# define BOOST_BEAST2_ERR(ev) ( \
47-
::boost::system::error_code( (ev), [] { \
48-
static constexpr auto loc((BOOST_CURRENT_LOCATION)); \
49-
return &loc; }()))
50-
# define BOOST_BEAST2_RETURN_EC(ev) \
51-
do { \
52-
static constexpr auto loc ## __LINE__((BOOST_CURRENT_LOCATION)); \
53-
return ::boost::system::error_code((ev), &loc ## __LINE__); \
54-
} while(0)
55-
#endif
56-
5739
} // beast2
5840

5941
namespace http {}

‎include/boost/beast2/error.hpp‎

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,7 @@
1111
#define BOOST_BEAST2_ERROR_HPP
1212

1313
#include <boost/beast2/detail/config.hpp>
14-
#include <boost/core/detail/string_view.hpp>
15-
#include <boost/system/error_category.hpp>
16-
#include <boost/system/is_error_code_enum.hpp>
14+
#include <system_error>
1715
#include <type_traits>
1816

1917
namespace boost {
@@ -27,45 +25,38 @@ enum class error
2725
};
2826

2927
} // beast2
28+
} // boost
3029

31-
namespace system {
30+
namespace std {
3231
template<>
3332
struct is_error_code_enum<
3433
::boost::beast2::error>
35-
{
36-
static bool const value = true;
37-
};
38-
} // system
34+
: std::true_type {};
35+
} // std
3936

37+
namespace boost {
4038
namespace beast2 {
4139

4240
namespace detail {
4341
struct BOOST_SYMBOL_VISIBLE
4442
error_cat_type
45-
: system::error_category
43+
: std::error_category
4644
{
4745
BOOST_BEAST2_DECL const char* name(
4846
) const noexcept override;
4947
BOOST_BEAST2_DECL std::string message(
5048
int) const override;
51-
BOOST_BEAST2_DECL char const* message(
52-
int, char*, std::size_t
53-
) const noexcept override;
54-
BOOST_SYSTEM_CONSTEXPR error_cat_type()
55-
: error_category(0x515eb9dbd1314d96 )
56-
{
57-
}
49+
constexpr error_cat_type() noexcept = default;
5850
};
5951
BOOST_BEAST2_DECL extern error_cat_type error_cat;
6052
} // detail
6153

6254
inline
63-
BOOST_SYSTEM_CONSTEXPR
64-
system::error_code
55+
std::error_code
6556
make_error_code(
6657
error ev) noexcept
6758
{
68-
return system::error_code{
59+
return std::error_code{
6960
static_cast<std::underlying_type<
7061
error>::type>(ev),
7162
detail::error_cat};

‎include/boost/beast2/http_worker.hpp‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@ namespace beast2 {
5757
, sock(ctx)
5858
{
5959
sock.open();
60-
rp.req_body = capy::any_buffer_source(parser.source_for(sock));
61-
rp.res_body = capy::any_buffer_sink(serializer.sink_for(sock));
60+
rp.req_body = http::any_buffer_source(parser.source_for(sock));
61+
rp.res_body = http::any_buffer_sink(serializer.sink_for(sock));
6262
stream = capy::any_read_stream(&sock);
6363
}
6464

‎include/boost/beast2/test/impl/error.hpp‎

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,15 @@
1010
#ifndef BOOST_BEAST2_TEST_IMPL_ERROR_HPP
1111
#define BOOST_BEAST2_TEST_IMPL_ERROR_HPP
1212

13-
#include <boost/system/error_category.hpp>
14-
#include <boost/system/is_error_code_enum.hpp>
13+
#include <system_error>
14+
#include <type_traits>
1515

16-
namespace boost {
17-
namespace system {
16+
namespace std {
1817
template<>
1918
struct is_error_code_enum<
20-
boost::beast2::test::error>
21-
: std::true_type
22-
{
23-
};
24-
} // system
25-
} // boost
19+
::boost::beast2::test::error>
20+
: std::true_type {};
21+
} // std
2622

2723
namespace boost {
2824
namespace beast2 {
@@ -31,7 +27,7 @@ namespace test {
3127
namespace detail {
3228

3329
class error_cat_type :
34-
public system::error_category
30+
public std::error_category
3531
{
3632
public:
3733
const char*
@@ -40,8 +36,8 @@ class error_cat_type :
4036
return "boost.beast2.test";
4137
}
4238

43-
char const*
44-
message(int ev, char*, std::size_t) const noexcept override
39+
std::string
40+
message(int ev) const override
4541
{
4642
switch(static_cast<error>(ev))
4743
{
@@ -50,18 +46,12 @@ class error_cat_type :
5046
"An automatic unit test failure occurred";
5147
}
5248
}
53-
54-
std::string
55-
message(int ev) const override
56-
{
57-
return message(ev, nullptr, 0);
58-
}
5949
};
6050

6151
} // detail
6252

6353
inline
64-
system::error_code
54+
std::error_code
6555
make_error_code(error e) noexcept
6656
{
6757
static detail::error_cat_type const cat{};

‎src/error.cpp‎

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88
//
99

1010
#include <boost/beast2/error.hpp>
11-
#include <boost/assert.hpp>
12-
#include <cstring>
1311

1412
namespace boost {
1513
namespace beast2 {
@@ -26,22 +24,12 @@ name() const noexcept
2624
std::string
2725
error_cat_type::
2826
message(int code) const
29-
{
30-
return message(code, nullptr, 0);
31-
}
32-
33-
char const*
34-
error_cat_type::
35-
message(
36-
int code,
37-
char*,
38-
std::size_t) const noexcept
3927
{
4028
switch(static_cast<error>(code))
4129
{
42-
case error::success: return "http::error::success";
30+
case error::success: return "beast2::error::success";
4331
default:
44-
return "http::error::?";
32+
return "beast2::error::?";
4533
}
4634
}
4735

‎src/http_server.cpp‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@
1212
#include <boost/capy/task.hpp>
1313
#include <boost/capy/cond.hpp>
1414
#include <boost/capy/ex/strand.hpp>
15-
#include <boost/capy/io/any_read_source.hpp>
1615
#include <boost/capy/io/any_read_stream.hpp>
17-
#include <boost/capy/io/any_buffer_sink.hpp>
16+
#include <boost/http/io/any_buffer_sink.hpp>
17+
#include <boost/http/io/any_buffer_source.hpp>
1818
#include <boost/http/request_parser.hpp>
1919
#include <boost/http/response.hpp>
2020
#include <boost/http/server/router.hpp>
@@ -63,8 +63,8 @@ struct http_server::
6363
{
6464
sock.open();
6565

66-
rp.req_body = capy::any_buffer_source(parser.source_for(sock));
67-
rp.res_body = capy::any_buffer_sink(serializer.sink_for(sock));
66+
rp.req_body = http::any_buffer_source(parser.source_for(sock));
67+
rp.res_body = http::any_buffer_sink(serializer.sink_for(sock));
6868
stream = capy::any_read_stream(&sock);
6969
}
7070

‎src/https_server.cpp‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@
1212
#include <boost/capy/task.hpp>
1313
#include <boost/capy/cond.hpp>
1414
#include <boost/capy/ex/strand.hpp>
15-
#include <boost/capy/io/any_read_source.hpp>
1615
#include <boost/capy/io/any_read_stream.hpp>
17-
#include <boost/capy/io/any_buffer_sink.hpp>
1816
#include <boost/corosio/openssl_stream.hpp>
17+
#include <boost/http/io/any_buffer_sink.hpp>
18+
#include <boost/http/io/any_buffer_source.hpp>
1919
#include <boost/http/request_parser.hpp>
2020
#include <boost/http/response.hpp>
2121
#include <boost/http/server/router.hpp>
@@ -88,7 +88,7 @@ struct https_server::
8888
ssl = std::make_unique<corosio::openssl_stream>(&sock, tls_ctx);
8989

9090
// Perform TLS handshake as server
91-
auto [hs_ec] = co_await ssl->handshake(corosio::tls_stream::server);
91+
auto [hs_ec] = co_await ssl->handshake(corosio::tls_role::server);
9292
if(hs_ec)
9393
{
9494
std::cerr << "TLS handshake error: " << hs_ec.message() << "\n";
@@ -98,8 +98,8 @@ struct https_server::
9898
}
9999

100100
// Wire parser and serializer to the TLS stream
101-
rp.req_body = capy::any_buffer_source(parser.source_for(*ssl));
102-
rp.res_body = capy::any_buffer_sink(serializer.sink_for(*ssl));
101+
rp.req_body = http::any_buffer_source(parser.source_for(*ssl));
102+
rp.res_body = http::any_buffer_sink(serializer.sink_for(*ssl));
103103
stream = capy::any_read_stream(ssl.get());
104104

105105
// Process HTTP requests over TLS

‎src/route_rule.hpp‎

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -199,29 +199,25 @@ constexpr struct
199199
if(it == end || *it != '(')
200200
return "";
201201
if(it == end)
202-
BOOST_BEAST2_RETURN_EC(
203-
grammar::error::syntax);
202+
return grammar::error::syntax;
204203
auto it0 = it;
205204
it = grammar::find_if_not(
206205
it, end, constraint_char{});
207206
if(it - it0 <= 1)
208207
{
209208
// too small
210209
it = it0;
211-
BOOST_BEAST2_RETURN_EC(
212-
grammar::error::syntax);
210+
return grammar::error::syntax;
213211
}
214212
if(it == end)
215213
{
216214
it = it0;
217-
BOOST_BEAST2_RETURN_EC(
218-
grammar::error::syntax);
215+
return grammar::error::syntax;
219216
}
220217
if(*it != ')')
221218
{
222219
it0 = it;
223-
BOOST_BEAST2_RETURN_EC(
224-
grammar::error::syntax);
220+
return grammar::error::syntax;
225221
}
226222
return core::string_view(++it0, it++);
227223
}
@@ -238,11 +234,9 @@ constexpr struct
238234
system::result<value_type>
239235
{
240236
if(it == end)
241-
BOOST_BEAST2_RETURN_EC(
242-
grammar::error::syntax);
237+
return grammar::error::syntax;
243238
if(! grammar::alpha_chars(*it))
244-
BOOST_BEAST2_RETURN_EC(
245-
grammar::error::syntax);
239+
return grammar::error::syntax;
246240
auto it0 = it++;
247241
it = grammar::find_if_not(
248242
it, end, ident_char{});
@@ -276,11 +270,9 @@ struct param_segment_rule_t
276270
system::result<value_type>
277271
{
278272
if(it == end)
279-
BOOST_BEAST2_RETURN_EC(
280-
grammar::error::syntax);
273+
return grammar::error::syntax;
281274
if(*it != ':' && *it != '*')
282-
BOOST_BEAST2_RETURN_EC(
283-
grammar::error::mismatch);
275+
return grammar::error::mismatch;
284276
value_type v;
285277
v.ptype = *it++;
286278
{

0 commit comments

Comments
 (0)