mirror of
https://github.com/XRPLF/clio.git
synced 2026-08-22 21:20:52 +00:00
@@ -28,11 +28,11 @@
|
||||
namespace web {
|
||||
|
||||
/**
|
||||
* @brief Each executor fulfills this interface
|
||||
* @brief Specifies the requirements a Webserver handler must fulfill.
|
||||
*/
|
||||
// clang-format off
|
||||
template <typename T>
|
||||
concept ServerHandler = requires(T handler, std::string const& req, std::shared_ptr<ConnectionBase> const& ws, boost::beast::error_code ec) {
|
||||
concept SomeServerHandler = requires(T handler, std::string req, std::shared_ptr<ConnectionBase> ws, boost::beast::error_code ec) {
|
||||
// the callback when server receives a request
|
||||
{ handler(req, ws) };
|
||||
// the callback when there is an error
|
||||
|
||||
@@ -28,8 +28,9 @@ namespace web {
|
||||
namespace http = boost::beast::http;
|
||||
|
||||
/**
|
||||
* @brief Base class for all connections
|
||||
* This class is used to represent a connection in RPC executor and subscription manager
|
||||
* @brief Base class for all connections.
|
||||
*
|
||||
* This class is used to represent a connection in RPC executor and subscription manager.
|
||||
*/
|
||||
struct ConnectionBase : public util::Taggable
|
||||
{
|
||||
@@ -40,20 +41,32 @@ public:
|
||||
std::string const clientIp;
|
||||
bool upgraded = false;
|
||||
|
||||
/**
|
||||
* @brief Create a new connection base.
|
||||
*
|
||||
* @param tagFactory The factory that generates tags to track sessions and requests
|
||||
* @param ip The IP address of the connected peer
|
||||
*/
|
||||
ConnectionBase(util::TagDecoratorFactory const& tagFactory, std::string ip) : Taggable(tagFactory), clientIp(ip)
|
||||
{
|
||||
}
|
||||
|
||||
virtual ~ConnectionBase() = default;
|
||||
|
||||
/**
|
||||
* @brief Send the response to the client
|
||||
* @brief Send the response to the client.
|
||||
*
|
||||
* @param msg The message to send
|
||||
* @param status The HTTP status code; defaults to OK
|
||||
*/
|
||||
virtual void
|
||||
send(std::string&& msg, http::status status = http::status::ok) = 0;
|
||||
|
||||
/**
|
||||
* @brief Send via shared_ptr of string, that enables SubscriptionManager to publish to clients
|
||||
* @brief Send via shared_ptr of string, that enables SubscriptionManager to publish to clients.
|
||||
*
|
||||
* @param msg The message to send
|
||||
* @throws Not supported unless implemented in child classes. Will always throw std::runtime_error.
|
||||
*/
|
||||
virtual void
|
||||
send(std::shared_ptr<std::string> msg)
|
||||
@@ -62,18 +75,14 @@ public:
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Indicates whether the connection had an error and is considered
|
||||
* dead
|
||||
* @brief Indicates whether the connection had an error and is considered dead.
|
||||
*
|
||||
* @return true
|
||||
* @return false
|
||||
* @return true if the connection is considered dead; false otherwise
|
||||
*/
|
||||
bool
|
||||
dead()
|
||||
{
|
||||
return ec_ != boost::system::error_code{};
|
||||
}
|
||||
|
||||
virtual ~ConnectionBase() = default;
|
||||
};
|
||||
} // namespace web
|
||||
|
||||
Reference in New Issue
Block a user