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

#include <userver/websocket/connection.hpp>

Detailed Description

Main class for Websocket connection.

Examples
samples/websocket_service/main.cpp.

Definition at line 36 of file connection.hpp.

Public Member Functions

 WebSocketConnection (WebSocketConnection &&)=delete
 
 WebSocketConnection (const WebSocketConnection &)=delete
 
WebSocketConnectionoperator= (WebSocketConnection &&)=delete
 
WebSocketConnectionoperator= (const WebSocketConnection &)=delete
 
virtual ~WebSocketConnection ()
 Closes the connection by closing the underlying OS socket.
 
virtual void Recv (Message &message)=0
 Read a message from websocket, handling pings under the hood.
 
virtual bool TryRecv (Message &message)=0
 Behaves in the same way as Recv(), but in case of first bytes of message are not yet ready to receive gives the control up to a client.
 
virtual void Send (const Message &message)=0
 Send a message to websocket.
 
virtual void SendText (std::string_view message)=0
 Send a message to websocket.
 
virtual void SendPing ()=0
 Send a ping message to websocket.
 
virtual std::size_t NotAnsweredSequentialPingsCount ()=0
 Get the number of not answered sequential pings; calls to SendPing() increment this value, Recv and TryRecv reset this value if some 'pong' is received.
 
template<typename ContiguousContainer>
void SendBinary (const ContiguousContainer &message)
 Sends binary data from container message.
 
virtual void Close (CloseStatus status_code)=0
 Closes the connection with specified status_code.
 
virtual const engine::io::SockaddrRemoteAddr () const =0
 
virtual void AddFinalTags (tracing::Span &span) const =0
 
virtual void AddStatistics (Statistics &stats) const =0
 
virtual engine::io::ReadAwaiterReadAwaiter ()=0
 
virtual engine::io::WriteAwaiterWriteAwaiter ()=0
 

Protected Member Functions

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

Member Function Documentation

◆ NotAnsweredSequentialPingsCount()

virtual std::size_t websocket::WebSocketConnection::NotAnsweredSequentialPingsCount ( )
pure virtual

Get the number of not answered sequential pings; calls to SendPing() increment this value, Recv and TryRecv reset this value if some 'pong' is received.

Returns
the number of not answered sequential pings

◆ Recv()

virtual void 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). It is not safe to call Recv() and Send() from different coroutines at once if TLS is used. Consider using Send()+TryRecv() from the same coroutine instead.
Examples
samples/websocket_service/main.cpp.

◆ Send()

virtual void 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). It is not safe to call Recv() and Send() from different coroutines at once if TLS is used. Consider using Send()+TryRecv() from the same coroutine instead.
Examples
samples/websocket_service/main.cpp.

◆ SendBinary()

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

Sends binary data from container message.

Definition at line 86 of file connection.hpp.

◆ SendPing()

virtual void websocket::WebSocketConnection::SendPing ( )
pure virtual

Send a ping message to websocket.

Exceptions
engine::io::IoExceptionin case of socket errors

◆ SendText()

virtual void websocket::WebSocketConnection::SendText ( std::string_view 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). It is not safe to call Recv() and Send() from different coroutines at once if TLS is used. Consider using Send()+TryRecv() from the same coroutine instead.

◆ TryRecv()

virtual bool websocket::WebSocketConnection::TryRecv ( Message & message)
pure virtual

Behaves in the same way as Recv(), but in case of first bytes of message are not yet ready to receive gives the control up to a client.

Returns
false in case of messages absence, otherwise true and behaves like Recv()

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