forked from boostorg/beast
Tidy up error types:
* Restructure header material * Clean up namespace type injections * Remove extraneous 'success' constants
This commit is contained in:
1 parent
f2a283ed10
commit
6b0b016b21
23 files changed
+260
-292
No files matched your search
@@ -1,92 +0,0 @@
|
||||
//
|
||||
// Copyright (c) 2013-2016 Vinnie Falco (vinnie dot falco at gmail 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)
|
||||
//
|
||||
|
||||
#ifndef BEAST_WEBSOCKET_DETAIL_ERROR_HPP
|
||||
#define BEAST_WEBSOCKET_DETAIL_ERROR_HPP
|
||||
|
||||
#include <beast/websocket/error.hpp>
|
||||
|
||||
namespace boost {
|
||||
namespace system {
|
||||
template<>
|
||||
struct is_error_code_enum<beast::websocket::error>
|
||||
{
|
||||
static bool const value = true;
|
||||
};
|
||||
} // system
|
||||
} // boost
|
||||
|
||||
namespace beast {
|
||||
namespace websocket {
|
||||
namespace detail {
|
||||
|
||||
class error_category : public boost::system::error_category
|
||||
{
|
||||
public:
|
||||
const char*
|
||||
name() const noexcept override
|
||||
{
|
||||
return "websocket";
|
||||
}
|
||||
|
||||
std::string
|
||||
message(int ev) const override
|
||||
{
|
||||
switch(static_cast<error>(ev))
|
||||
{
|
||||
case error::closed: return "WebSocket connection closed normally";
|
||||
case error::failed: return "WebSocket connection failed due to a protocol violation";
|
||||
case error::handshake_failed: return "WebSocket Upgrade handshake failed";
|
||||
case error::keep_alive: return "WebSocket Upgrade handshake failed but connection is still open";
|
||||
|
||||
case error::response_malformed: return "malformed HTTP response";
|
||||
case error::response_failed: return "upgrade request failed";
|
||||
case error::response_denied: return "upgrade request denied";
|
||||
case error::request_malformed: return "malformed HTTP request";
|
||||
case error::request_invalid: return "upgrade request invalid";
|
||||
case error::request_denied: return "upgrade request denied";
|
||||
default:
|
||||
return "websocket error";
|
||||
}
|
||||
}
|
||||
|
||||
boost::system::error_condition
|
||||
default_error_condition(int ev) const noexcept override
|
||||
{
|
||||
return boost::system::error_condition(ev, *this);
|
||||
}
|
||||
|
||||
bool
|
||||
equivalent(int ev,
|
||||
boost::system::error_condition const& condition
|
||||
) const noexcept override
|
||||
{
|
||||
return condition.value() == ev &&
|
||||
&condition.category() == this;
|
||||
}
|
||||
|
||||
bool
|
||||
equivalent(error_code const& error, int ev) const noexcept override
|
||||
{
|
||||
return error.value() == ev &&
|
||||
&error.category() == this;
|
||||
}
|
||||
};
|
||||
|
||||
inline
|
||||
boost::system::error_category const&
|
||||
get_error_category()
|
||||
{
|
||||
static detail::error_category const cat{};
|
||||
return cat;
|
||||
}
|
||||
|
||||
} // detail
|
||||
} // websocket
|
||||
} // beast
|
||||
|
||||
#endif
|
||||
@@ -16,10 +16,8 @@ namespace websocket {
|
||||
/// Error codes returned from @ref stream operations.
|
||||
enum class error
|
||||
{
|
||||
success = 0,
|
||||
|
||||
/// Both sides performed a WebSocket close
|
||||
closed,
|
||||
closed = 1,
|
||||
|
||||
/// WebSocket connection failed, protocol violation
|
||||
failed,
|
||||
@@ -52,11 +50,6 @@ enum class error
|
||||
general
|
||||
};
|
||||
|
||||
#if ! GENERATING_DOCS
|
||||
error_code
|
||||
make_error_code(error e);
|
||||
#endif
|
||||
|
||||
} // websocket
|
||||
} // beast
|
||||
|
||||
|
||||
@@ -5,20 +5,93 @@
|
||||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
|
||||
#ifndef BEAST_WEBSOCKET_IMPL_ERROR_IPP_HPP
|
||||
#define BEAST_WEBSOCKET_IMPL_ERROR_IPP_HPP
|
||||
#ifndef BEAST_WEBSOCKET_IMPL_ERROR_IPP
|
||||
#define BEAST_WEBSOCKET_IMPL_ERROR_IPP
|
||||
|
||||
#include <beast/websocket/detail/error.hpp>
|
||||
namespace boost {
|
||||
namespace system {
|
||||
template<>
|
||||
struct is_error_code_enum<beast::websocket::error>
|
||||
{
|
||||
static bool const value = true;
|
||||
};
|
||||
} // system
|
||||
} // boost
|
||||
|
||||
namespace beast {
|
||||
namespace websocket {
|
||||
namespace detail {
|
||||
|
||||
class websocket_error_category : public error_category
|
||||
{
|
||||
public:
|
||||
const char*
|
||||
name() const noexcept override
|
||||
{
|
||||
return "websocket";
|
||||
}
|
||||
|
||||
std::string
|
||||
message(int ev) const override
|
||||
{
|
||||
switch(static_cast<error>(ev))
|
||||
{
|
||||
case error::closed: return "WebSocket connection closed normally";
|
||||
case error::failed: return "WebSocket connection failed due to a protocol violation";
|
||||
case error::handshake_failed: return "WebSocket Upgrade handshake failed";
|
||||
case error::keep_alive: return "WebSocket Upgrade handshake failed but connection is still open";
|
||||
|
||||
case error::response_malformed: return "malformed HTTP response";
|
||||
case error::response_failed: return "upgrade request failed";
|
||||
case error::response_denied: return "upgrade request denied";
|
||||
case error::request_malformed: return "malformed HTTP request";
|
||||
case error::request_invalid: return "upgrade request invalid";
|
||||
case error::request_denied: return "upgrade request denied";
|
||||
default:
|
||||
return "websocket error";
|
||||
}
|
||||
}
|
||||
|
||||
error_condition
|
||||
default_error_condition(int ev) const noexcept override
|
||||
{
|
||||
return error_condition(ev, *this);
|
||||
}
|
||||
|
||||
bool
|
||||
equivalent(int ev,
|
||||
error_condition const& condition
|
||||
) const noexcept override
|
||||
{
|
||||
return condition.value() == ev &&
|
||||
&condition.category() == this;
|
||||
}
|
||||
|
||||
bool
|
||||
equivalent(error_code const& error, int ev) const noexcept override
|
||||
{
|
||||
return error.value() == ev &&
|
||||
&error.category() == this;
|
||||
}
|
||||
};
|
||||
|
||||
inline
|
||||
error_category const&
|
||||
get_error_category()
|
||||
{
|
||||
static detail::websocket_error_category const cat{};
|
||||
return cat;
|
||||
}
|
||||
|
||||
} // detail
|
||||
|
||||
inline
|
||||
error_code
|
||||
make_error_code(error e)
|
||||
{
|
||||
return error_code(
|
||||
static_cast<int>(e), detail::get_error_category());
|
||||
static_cast<std::underlying_type<error>::type>(e),
|
||||
detail::get_error_category());
|
||||
}
|
||||
|
||||
} // websocket
|
||||
|
||||
@@ -352,7 +352,7 @@ public:
|
||||
HTTP response is sent indicating the reason and status code
|
||||
(typically 400, "Bad Request"). This counts as a failure.
|
||||
|
||||
@throws boost::system::system_error Thrown on failure.
|
||||
@throws system_error Thrown on failure.
|
||||
*/
|
||||
void
|
||||
accept();
|
||||
@@ -462,7 +462,7 @@ public:
|
||||
then to received WebSocket frames. The implementation will
|
||||
copy the caller provided data before the function returns.
|
||||
|
||||
@throws boost::system::system_error Thrown on failure.
|
||||
@throws system_error Thrown on failure.
|
||||
*/
|
||||
template<class ConstBufferSequence>
|
||||
void
|
||||
@@ -585,7 +585,7 @@ public:
|
||||
Ownership is not transferred, the implementation will not access
|
||||
this object from other threads.
|
||||
|
||||
@throws boost::system::system_error Thrown on failure.
|
||||
@throws system_error Thrown on failure.
|
||||
*/
|
||||
// VFALCO TODO This should also take a DynamicBuffer with any leftover bytes.
|
||||
template<class Body, class Headers>
|
||||
@@ -700,7 +700,7 @@ public:
|
||||
@param resource The requesting URI, which may not be empty,
|
||||
required by the HTTP protocol.
|
||||
|
||||
@throws boost::system::system_error Thrown on failure.
|
||||
@throws system_error Thrown on failure.
|
||||
|
||||
@par Example
|
||||
@code
|
||||
@@ -837,7 +837,7 @@ public:
|
||||
|
||||
@param cr The reason for the close.
|
||||
|
||||
@throws boost::system::system_error Thrown on failure.
|
||||
@throws system_error Thrown on failure.
|
||||
*/
|
||||
void
|
||||
close(close_reason const& cr);
|
||||
@@ -937,7 +937,7 @@ public:
|
||||
|
||||
@param payload The payload of the ping message, which may be empty.
|
||||
|
||||
@throws boost::system::system_error Thrown on failure.
|
||||
@throws system_error Thrown on failure.
|
||||
*/
|
||||
void
|
||||
ping(ping_data const& payload);
|
||||
@@ -1031,7 +1031,7 @@ public:
|
||||
@param dynabuf A dynamic buffer to hold the message data after
|
||||
any masking or decompression has been applied.
|
||||
|
||||
@throws boost::system::system_error Thrown on failure.
|
||||
@throws system_error Thrown on failure.
|
||||
*/
|
||||
template<class DynamicBuffer>
|
||||
void
|
||||
@@ -1166,7 +1166,7 @@ public:
|
||||
@param dynabuf A dynamic buffer to hold the message data after
|
||||
any masking or decompression has been applied.
|
||||
|
||||
@throws boost::system::system_error Thrown on failure.
|
||||
@throws system_error Thrown on failure.
|
||||
*/
|
||||
template<class DynamicBuffer>
|
||||
void
|
||||
@@ -1304,7 +1304,7 @@ public:
|
||||
the memory locations pointed to by buffers remains valid
|
||||
until the completion handler is called.
|
||||
|
||||
@throws boost::system::system_error Thrown on failure.
|
||||
@throws system_error Thrown on failure.
|
||||
|
||||
@note This function always sends an entire message. To
|
||||
send a message in fragments, use @ref write_frame.
|
||||
@@ -1341,7 +1341,7 @@ public:
|
||||
|
||||
@param ec Set to indicate what error occurred, if any.
|
||||
|
||||
@throws boost::system::system_error Thrown on failure.
|
||||
@throws system_error Thrown on failure.
|
||||
|
||||
@note This function always sends an entire message. To
|
||||
send a message in fragments, use @ref write_frame.
|
||||
@@ -1426,7 +1426,7 @@ public:
|
||||
@param buffers One or more buffers containing the frame's
|
||||
payload data.
|
||||
|
||||
@throws boost::system::system_error Thrown on failure.
|
||||
@throws system_error Thrown on failure.
|
||||
*/
|
||||
template<class ConstBufferSequence>
|
||||
void
|
||||
@@ -1500,7 +1500,7 @@ public:
|
||||
Copies will be made of the handler as required. The equivalent
|
||||
function signature of the handler must be:
|
||||
@code void handler(
|
||||
boost::system::error_code const& error // result of operation
|
||||
error_code const& error // result of operation
|
||||
); @endcode
|
||||
*/
|
||||
template<class ConstBufferSequence, class WriteHandler>
|
||||
|
||||
Reference in new issue
Block a user