Add non-allocating overload for error category message function

Fixes #2646
This commit is contained in:
Mohammad Nejati
2024-01-03 10:03:46 +00:00
committed by Mohammad Nejati
parent 5998feda44
commit 9e16754dd5
9 changed files with 72 additions and 17 deletions

View File

@ -29,8 +29,8 @@ public:
}
BOOST_BEAST_DECL
std::string
message(int ev) const override
char const*
message(int ev, char*, std::size_t) const noexcept override
{
switch(static_cast<error>(ev))
{
@ -40,6 +40,13 @@ public:
}
}
BOOST_BEAST_DECL
std::string
message(int ev) const override
{
return message(ev, nullptr, 0);
}
BOOST_BEAST_DECL
error_condition
default_error_condition(int ev) const noexcept override

View File

@ -28,10 +28,9 @@ public:
error_codes() : error_category(0x002f6e94401c6e8bu) {}
BOOST_BEAST_DECL
std::string
message(int ev) const override
char const*
message(int ev, char*, std::size_t) const noexcept override
{
switch(static_cast<error>(ev))
{
@ -41,6 +40,13 @@ public:
}
}
BOOST_BEAST_DECL
std::string
message(int ev) const override
{
return message(ev, nullptr, 0);
}
BOOST_BEAST_DECL
error_condition
default_error_condition(int ev) const noexcept override
@ -67,10 +73,9 @@ public:
error_conditions() : error_category(0x3dd0b0ce843c5b10u) {}
BOOST_BEAST_DECL
std::string
message(int cv) const override
char const*
message(int cv, char*, std::size_t) const noexcept override
{
switch(static_cast<condition>(cv))
{
@ -79,6 +84,13 @@ public:
return "The operation timed out";
}
}
BOOST_BEAST_DECL
std::string
message(int cv) const override
{
return message(cv, nullptr, 0);
}
};
} // detail

View File

@ -29,8 +29,9 @@ public:
http_error_category() : error_category(0x964627da815bf210u) {}
std::string
message(int ev) const override
BOOST_BEAST_DECL
char const*
message(int ev, char*, std::size_t) const noexcept override
{
switch(static_cast<error>(ev))
{
@ -66,6 +67,12 @@ public:
}
}
std::string
message(int ev) const override
{
return message(ev, nullptr, 0);
}
error_condition
default_error_condition(
int ev) const noexcept override

View File

@ -29,8 +29,9 @@ public:
return "boost.beast.websocket";
}
std::string
message(int ev) const override
BOOST_BEAST_DECL
char const*
message(int ev, char*, std::size_t) const noexcept override
{
switch(static_cast<error>(ev))
{
@ -71,6 +72,12 @@ public:
}
}
std::string
message(int ev) const override
{
return message(ev, nullptr, 0);
}
error_condition
default_error_condition(int ev) const noexcept override
{
@ -128,9 +135,9 @@ public:
error_conditions() : error_category(0x7a8de5d61799ce9eu) {}
std::string
message(int cv) const override
BOOST_BEAST_DECL
char const*
message(int cv, char*, std::size_t) const noexcept override
{
switch(static_cast<condition>(cv))
{
@ -139,6 +146,12 @@ public:
case condition::protocol_violation: return "A WebSocket protocol violation occurred";
}
}
std::string
message(int cv) const override
{
return message(cv, nullptr, 0);
}
};
} // detail

View File

@ -55,8 +55,9 @@ public:
return "boost.beast.zlib";
}
std::string
message(int ev) const override
BOOST_BEAST_DECL
char const*
message(int ev, char*, std::size_t) const noexcept override
{
switch(static_cast<error>(ev))
{
@ -84,6 +85,12 @@ public:
}
}
std::string
message(int ev) const override
{
return message(ev, nullptr, 0);
}
error_condition
default_error_condition(int ev) const noexcept override
{

View File

@ -34,12 +34,14 @@ public:
BEAST_EXPECT(ec.category().name() != nullptr);
BEAST_EXPECT(! ec.message().empty());
BEAST_EXPECT(ec == c);
BEAST_EXPECT(ec.message(nullptr, 0) != nullptr);
}
{
auto ec = make_error_condition(c);
BEAST_EXPECT(ec.category().name() != nullptr);
BEAST_EXPECT(! ec.message().empty());
BEAST_EXPECT(ec == c);
BEAST_EXPECT(ec.message(nullptr, 0) != nullptr);
}
}

View File

@ -36,6 +36,8 @@ public:
static_cast<std::underlying_type<error>::type>(ev))));
BEAST_EXPECT(cat.equivalent(ec,
static_cast<std::underlying_type<error>::type>(ev)));
BEAST_EXPECT(ec.message(nullptr, 0) != nullptr);
}
void

View File

@ -35,6 +35,9 @@ public:
BEAST_EXPECT(ec.category().name() != nullptr);
BEAST_EXPECT(! ec.message().empty());
BEAST_EXPECT(ec == c);
BEAST_EXPECT(ec.message(nullptr, 0) != nullptr);
BEAST_EXPECT(make_error_condition(c).message(nullptr, 0) != nullptr);
}
void run() override

View File

@ -35,6 +35,8 @@ public:
static_cast<std::underlying_type<error>::type>(ev))));
BEAST_EXPECT(cat.equivalent(ec,
static_cast<std::underlying_type<error>::type>(ev)));
BEAST_EXPECT(ec.message(nullptr, 0) != nullptr);
}
void run() override