userver: server::websocket::WebSocketConnection Class Reference
Loading...
Searching...
No Matches
server::websocket::WebSocketConnection Class Referenceabstract

#include <userver/server/websocket/server.hpp>

Detailed Description

Main class for Websocket connection.

Examples
samples/websocket_service/websocket_service.cpp.

Definition at line 63 of file server.hpp.

Public Member Functions

 WebSocketConnection (WebSocketConnection &&)=delete
 
 WebSocketConnection (const WebSocketConnection &)=delete
 
WebSocketConnectionoperator= (WebSocketConnection &&)=delete
 
WebSocketConnectionoperator= (const WebSocketConnection &)=delete
 
virtual void Recv (Message &message)=0
 Read a message from websocket, handling pings under the hood.
 
virtual void Send (const Message &message)=0
 Send a message to websocket.
 
virtual void SendText (std::string_view message)=0
 
template<typename ContiguousContainer >
void SendBinary (const ContiguousContainer &message)
 
virtual void Close (CloseStatus status_code)=0
 
virtual const engine::io::SockaddrRemoteAddr () const =0
 
virtual void AddFinalTags (tracing::Span &span) const =0
 
virtual void AddStatistics (Statistics &stats) const =0
 

Protected Member Functions

virtual void DoSendBinary (utils::span< const std::byte > message)=0
 

Member Function Documentation

◆ Recv()

virtual void server::websocket::WebSocketConnection::Recv ( Message & message)
pure virtual

Read a message from websocket, handling pings under the hood.

Parameters
messageinput message
Exceptions
engine::io::IoExceptionin case of socket errors
Note
Recv() is not thread-safe by itself (you may not call Recv() from multiple coroutines at once), but it is safe to call Recv() and Send() from different coroutines at once thus implementing full-duplex socket connection.
Examples
samples/websocket_service/websocket_service.cpp.

◆ Send()

virtual void server::websocket::WebSocketConnection::Send ( const Message & message)
pure virtual

Send a message to websocket.

Parameters
messagemessage to send
Exceptions
engine::io::IoExceptionin case of socket errors
Note
Send() is not thread-safe by itself (you may not call Send() from multiple coroutines at once), but it is safe to call Recv() and Send() from different coroutines at once thus implementing full-duplex socket connection.
Examples
samples/websocket_service/websocket_service.cpp.

◆ SendBinary()

template<typename ContiguousContainer >
void server::websocket::WebSocketConnection::SendBinary ( const ContiguousContainer & message)
inline

Definition at line 95 of file server.hpp.


The documentation for this class was generated from the following file: