Kurlyk
Loading...
Searching...
No Matches
IWebSocketSender.hpp
Go to the documentation of this file.
1#pragma once
2#ifndef _KURLYK_IWEBSOCKET_SENDER_HPP_INCLUDED
3#define _KURLYK_IWEBSOCKET_SENDER_HPP_INCLUDED
4
7
8namespace kurlyk {
9
14 public:
15
17 IWebSocketSender() = default;
18
20 virtual ~IWebSocketSender() = default;
21
24 virtual std::string get_http_version() = 0;
25
28 virtual Headers get_headers() = 0;
29
32 virtual std::string get_remote_endpoint() = 0;
33
39 virtual bool send_message(
40 const std::string &message,
41 long rate_limit_id = 0,
42 std::function<void(const std::error_code&)> callback = nullptr) = 0;
43
50 const std::string &message,
51 long rate_limit_id = 0,
52 std::function<void(const std::error_code&)> callback = nullptr) {
53 const bool accepted = send_message(message, rate_limit_id, std::move(callback));
54 return SubmitResult{accepted, std::error_code()};
55 }
56
62 virtual bool send_close(
63 int status = 1000,
64 const std::string &reason = std::string(),
65 std::function<void(const std::error_code&)> callback = nullptr) = 0;
66
73 int status = 1000,
74 const std::string &reason = std::string(),
75 std::function<void(const std::error_code&)> callback = nullptr) {
76 const bool accepted = send_close(status, reason, std::move(callback));
77 return SubmitResult{accepted, std::error_code()};
78 }
79
82 virtual bool is_connected() const = 0;
83
84 };
85
87 using WebSocketSenderPtr = std::shared_ptr<IWebSocketSender>;
88
89} // namespace kurlyk
90
91#endif // _KURLYK_IWEBSOCKET_SENDER_HPP_INCLUDED
virtual SubmitResult submit_close(int status=1000, const std::string &reason=std::string(), std::function< void(const std::error_code &)> callback=nullptr)
Attempts to submit a close request and reports the admission result.
virtual bool send_message(const std::string &message, long rate_limit_id=0, std::function< void(const std::error_code &)> callback=nullptr)=0
Sends a WebSocket message.
virtual Headers get_headers()=0
Retrieves the headers associated with the WebSocket connection.
IWebSocketSender()=default
Default constructor for IWebSocketSender.
virtual SubmitResult submit_message(const std::string &message, long rate_limit_id=0, std::function< void(const std::error_code &)> callback=nullptr)
Attempts to submit a WebSocket message and reports the admission result.
virtual bool send_close(int status=1000, const std::string &reason=std::string(), std::function< void(const std::error_code &)> callback=nullptr)=0
Sends a close request to the WebSocket server.
virtual ~IWebSocketSender()=default
Virtual destructor for safe cleanup through the sender abstraction.
virtual bool is_connected() const =0
Checks if the WebSocket connection is currently active.
virtual std::string get_remote_endpoint()=0
Retrieves the remote endpoint information.
virtual std::string get_http_version()=0
Retrieves the HTTP version used in the WebSocket connection.
Primary namespace for the Kurlyk library, encompassing initialization, request management,...
utils::CaseInsensitiveMultimap Headers
Alias for HTTP headers, providing a case-insensitive unordered multimap.
std::shared_ptr< IWebSocketSender > WebSocketSenderPtr
Shared pointer alias for the sender abstraction used in WebSocketEventData.
Represents the synchronous result of trying to enqueue or submit work.