25#include "../../abi/string.hpp"
26#include "../sse_message.hpp"
35namespace essence::net::abstract {
45 explicit sse_connection(T&& value) : wrapper_{std::make_shared<wrapper<T>>(std::forward<T>(value))} {}
53 return wrapper_->canceled();
61 return wrapper_->request_uri();
69 return wrapper_->remote_address();
76 wrapper_->send_message(message);
98 return wrapper_->underlying_ptr();
103 virtual ~base() =
default;
104 virtual bool canceled() = 0;
105 virtual uri request_uri() = 0;
106 virtual abi::string remote_address() = 0;
107 virtual void send_message(
const sse_message& message) = 0;
108 virtual void tick() = 0;
109 virtual void close() = 0;
110 virtual void* underlying_ptr() = 0;
113 template <
typename T>
114 class wrapper final :
public base {
116 template <std::convertible_to<T> U>
117 explicit wrapper(U&& value) : value_{std::forward<U>(value)} {}
119 bool canceled()
override {
120 return value_.canceled();
123 uri request_uri()
override {
124 return value_.request_uri();
127 abi::string remote_address()
override {
128 return value_.remote_address();
131 void send_message(
const sse_message& message)
override {
132 value_.send_message(message);
135 void tick()
override {
139 void close()
override {
143 void* underlying_ptr()
override {
151 std::shared_ptr<base> wrapper_;
155namespace essence::net {
156 using sse_connection_handler = std::function<void(abstract::sse_connection connection)>;
An interface: manages an SSE connection and its lifetime.
Definition sse_connection.hpp:39
void send_message(const sse_message &message) const
Sends a message to the client.
Definition sse_connection.hpp:75
bool canceled() const
Checks whether the internal operation has been canceled and if true the user must stop all invocation...
Definition sse_connection.hpp:52
void tick() const
Keep alive and raise an error when the network is disconnected.
Definition sse_connection.hpp:82
uri request_uri() const
Gets the request URI.
Definition sse_connection.hpp:60
abi::string remote_address() const
Gets the remote address.
Definition sse_connection.hpp:68
void close() const
Closes the connection.
Definition sse_connection.hpp:89
void * underlying_ptr() const
Gets the underlying pointer.
Definition sse_connection.hpp:97
A message describing a server-sent event.
Definition sse_message.hpp:34