9 #ifndef CPPSERVER_HTTP_WSS_SESSION_H
10 #define CPPSERVER_HTTP_WSS_SESSION_H
41 virtual bool Close(
int status) {
return Close(status,
nullptr, 0); }
42 virtual bool Close(
int status,
const void* buffer,
size_t size) {
SendCloseAsync(status, buffer, size); HTTPSSession::Disconnect();
return true; }
43 virtual bool Close(
int status, std::string_view text) {
SendCloseAsync(status, text); HTTPSSession::Disconnect();
return true; }
87 std::string
ReceiveText(
const CppCommon::Timespan& timeout);
89 std::vector<uint8_t>
ReceiveBinary(
const CppCommon::Timespan& timeout);
93 void onReceived(
const void* buffer,
size_t size)
override;
99 void onWSClose(
const void* buffer,
size_t size,
int status = 1000)
override {
Close(); }
103 void onWSError(
const std::string& message)
override {
onError(asio::error::fault,
"WebSocket error", message); }
std::shared_ptr< SSLServer > & server() noexcept
Get the server.
virtual void onError(int error, const std::string &category, const std::string &message)
Handle error notification.
size_t SendResponse()
Send the current HTTP response (synchronous)
HTTPResponse & response() noexcept
Get the HTTP response.
bool SendResponseAsync()
Send the current HTTP response (asynchronous)
WebSocket secure session.
size_t SendPing(std::string_view text, const CppCommon::Timespan &timeout)
bool SendPongAsync(const void *buffer, size_t size)
void onWSPing(const void *buffer, size_t size) override
Handle WebSocket ping notification.
size_t SendPong(const void *buffer, size_t size)
size_t SendText(const void *buffer, size_t size, const CppCommon::Timespan &timeout)
size_t SendClose(int status, std::string_view text)
bool SendPongAsync(std::string_view text)
WSSSession & operator=(const WSSSession &)=delete
virtual bool Close(int status)
size_t SendClose(int status, const void *buffer, size_t size, const CppCommon::Timespan &timeout)
WSSSession(WSSSession &&)=delete
size_t SendBinary(std::string_view text)
bool SendBinaryAsync(std::string_view text)
bool SendTextAsync(std::string_view text)
void onDisconnected() override
Handle session disconnected notification.
bool SendBinaryAsync(const void *buffer, size_t size)
size_t SendBinary(const void *buffer, size_t size)
bool SendCloseAsync(int status, const void *buffer, size_t size)
virtual bool Close(int status, std::string_view text)
size_t SendPing(const void *buffer, size_t size)
WSSSession(const WSSSession &)=delete
bool SendTextAsync(const void *buffer, size_t size)
std::string ReceiveText()
size_t SendPing(const void *buffer, size_t size, const CppCommon::Timespan &timeout)
void onReceivedRequest(const HTTP::HTTPRequest &request) override
Handle HTTP request received notification.
size_t SendClose(int status, std::string_view text, const CppCommon::Timespan &timeout)
bool SendCloseAsync(int status, std::string_view text)
WSSSession & operator=(WSSSession &&)=delete
size_t SendPong(std::string_view text, const CppCommon::Timespan &timeout)
size_t SendClose(int status, const void *buffer, size_t size)
void onReceived(const void *buffer, size_t size) override
Handle buffer received notification.
size_t SendText(std::string_view text, const CppCommon::Timespan &timeout)
std::vector< uint8_t > ReceiveBinary()
bool SendPingAsync(std::string_view text)
virtual ~WSSSession()=default
bool SendPingAsync(const void *buffer, size_t size)
size_t SendBinary(std::string_view text, const CppCommon::Timespan &timeout)
void onReceivedRequestHeader(const HTTP::HTTPRequest &request) override
Handle HTTP request header received notification.
void onWSClose(const void *buffer, size_t size, int status=1000) override
Handle WebSocket close notification.
size_t SendBinary(const void *buffer, size_t size, const CppCommon::Timespan &timeout)
size_t SendPing(std::string_view text)
virtual bool Close(int status, const void *buffer, size_t size)
size_t SendPong(const void *buffer, size_t size, const CppCommon::Timespan &timeout)
void onReceivedRequestError(const HTTP::HTTPRequest &request, const std::string &error) override
Handle HTTP request error notification.
WSSSession(const std::shared_ptr< WSSServer > &server)
size_t SendPong(std::string_view text)
void onWSError(const std::string &message) override
Handle WebSocket error notification.
size_t SendText(const void *buffer, size_t size)
size_t SendText(std::string_view text)
static const uint8_t WS_CLOSE
Close frame.
void PrepareSendFrame(uint8_t opcode, bool mask, const void *buffer, size_t size, int status=0)
Prepare WebSocket send frame.
static const uint8_t WS_TEXT
Text frame.
static const uint8_t WS_BINARY
Binary frame.
static const uint8_t WS_PING
Ping frame.
static const uint8_t WS_FIN
Final frame.
std::mutex _ws_send_lock
Send buffer lock.
static const uint8_t WS_PONG
Pong frame.
std::vector< uint8_t > _ws_send_buffer
Send buffer.
HTTPS session definition.
C++ Server project definitions.
WebSocket C++ Library definition.