xrpld
Loading...
Searching...
No Matches
xrpl::BaseWSPeer< Handler, Impl > Class Template Reference

Represents an active WebSocket connection. More...

#include <BaseWSPeer.h>

Inheritance diagram for xrpl::BaseWSPeer< Handler, Impl >:
Collaboration diagram for xrpl::BaseWSPeer< Handler, Impl >:

Public Member Functions

template<class Body, class Headers>
 BaseWSPeer (Port const &port, Handler &handler, boost::asio::executor const &executor, WaitableTimer timer, EndpointType remoteAddress, boost::beast::http::request< Body, Headers > &&request, beast::Journal journal)
void run () override
Port const & port () const override
HttpRequestType const & request () const override
boost::asio::ip::tcp::endpoint const & remoteEndpoint () const override
void send (std::shared_ptr< WSMsg > w) override
 Send a WebSockets message.
void close () override
void close (boost::beast::websocket::close_reason const &reason) override
void complete () override
 Indicate that the response is complete.
IOList & ios ()
 Return the IOList associated with the work.

Public Attributes

std::shared_ptr< void > appDefined

Protected Types

using ClockType = std::chrono::system_clock
using ErrorCode = boost::system::error_code
using EndpointType = boost::asio::ip::tcp::endpoint
using WaitableTimer = boost::asio::basic_waitable_timer<ClockType>

Protected Member Functions

Impl & impl ()
void onWsHandshake (ErrorCode const &ec)
void doWrite ()
void onWrite (ErrorCode const &ec)
void onWriteFin (ErrorCode const &ec)
void doRead ()
void onRead (ErrorCode const &ec)
void onClose (ErrorCode const &ec)
void startTimer ()
void cancelTimer ()
void onPing (ErrorCode const &ec)
void onPingPong (boost::beast::websocket::frame_type kind, std::string_view payload)
void onTimer (ErrorCode ec)
template<class String>
void fail (ErrorCode ec, String const &what)

Protected Attributes

Port const & port_
Handler & handler_
EndpointType remoteAddress_
beast::WrappedSink sink_
beast::Journal const j_
boost::asio::executor_work_guard< boost::asio::executor > work_
boost::asio::strand< boost::asio::executor > strand_

Private Member Functions

template<class = void>
void destroy ()

Private Attributes

HttpRequestType request_
boost::beast::multi_buffer rb_
boost::beast::multi_buffer wb_
std::list< std::shared_ptr< WSMsg > > wq_
bool doClose_ = false
 The socket has been closed, or will close after the next write finishes.
boost::beast::websocket::close_reason cr_
WaitableTimer timer_
bool closeOnTimer_ = false
bool pingActive_ = false
boost::beast::websocket::ping_data payload_
ErrorCode ec_
std::function< void(boost::beast::websocket::frame_type, std::string_view)> controlCallback_
IOList * ios_ = nullptr

Friends

class BasePeer< Handler, Impl >

Detailed Description

template<class Handler, class Impl>
class xrpl::BaseWSPeer< Handler, Impl >

Represents an active WebSocket connection.

Definition at line 38 of file BaseWSPeer.h.

Member Typedef Documentation

◆ ClockType

template<class Handler, class Impl>
using xrpl::BaseWSPeer< Handler, Impl >::ClockType = std::chrono::system_clock
protected

Definition at line 41 of file BaseWSPeer.h.

◆ ErrorCode

template<class Handler, class Impl>
using xrpl::BaseWSPeer< Handler, Impl >::ErrorCode = boost::system::error_code
protected

Definition at line 42 of file BaseWSPeer.h.

◆ EndpointType

template<class Handler, class Impl>
using xrpl::BaseWSPeer< Handler, Impl >::EndpointType = boost::asio::ip::tcp::endpoint
protected

Definition at line 43 of file BaseWSPeer.h.

◆ WaitableTimer

template<class Handler, class Impl>
using xrpl::BaseWSPeer< Handler, Impl >::WaitableTimer = boost::asio::basic_waitable_timer<ClockType>
protected

Definition at line 44 of file BaseWSPeer.h.

Constructor & Destructor Documentation

◆ BaseWSPeer()

template<class Handler, class Impl>
template<class Body, class Headers>
xrpl::BaseWSPeer< Handler, Impl >::BaseWSPeer ( Port const & port,
Handler & handler,
boost::asio::executor const & executor,
WaitableTimer timer,
EndpointType remoteAddress,
boost::beast::http::request< Body, Headers > && request,
beast::Journal journal )

Definition at line 168 of file BaseWSPeer.h.

Member Function Documentation

◆ run()

template<class Handler, class Impl>
void xrpl::BaseWSPeer< Handler, Impl >::run ( )
overridevirtual

Implements xrpl::WSSession.

Definition at line 185 of file BaseWSPeer.h.

◆ port()

template<class Handler, class Impl>
Port const & xrpl::BaseWSPeer< Handler, Impl >::port ( ) const
nodiscardoverridevirtual

Implements xrpl::WSSession.

Definition at line 87 of file BaseWSPeer.h.

◆ request()

template<class Handler, class Impl>
HttpRequestType const & xrpl::BaseWSPeer< Handler, Impl >::request ( ) const
nodiscardoverridevirtual

Implements xrpl::WSSession.

Definition at line 93 of file BaseWSPeer.h.

◆ remoteEndpoint()

template<class Handler, class Impl>
boost::asio::ip::tcp::endpoint const & xrpl::BaseWSPeer< Handler, Impl >::remoteEndpoint ( ) const
nodiscardoverridevirtual

Implements xrpl::WSSession.

Definition at line 99 of file BaseWSPeer.h.

◆ send()

template<class Handler, class Impl>
void xrpl::BaseWSPeer< Handler, Impl >::send ( std::shared_ptr< WSMsg > w)
overridevirtual

Send a WebSockets message.

Implements xrpl::WSSession.

Definition at line 209 of file BaseWSPeer.h.

◆ close() [1/2]

template<class Handler, class Impl>
void xrpl::BaseWSPeer< Handler, Impl >::close ( )
overridevirtual

Reimplemented from xrpl::BasePeer< Handler, Impl >.

Definition at line 234 of file BaseWSPeer.h.

◆ close() [2/2]

template<class Handler, class Impl>
void xrpl::BaseWSPeer< Handler, Impl >::close ( boost::beast::websocket::close_reason const & reason)
overridevirtual

Implements xrpl::WSSession.

Definition at line 241 of file BaseWSPeer.h.

◆ complete()

template<class Handler, class Impl>
void xrpl::BaseWSPeer< Handler, Impl >::complete ( )
overridevirtual

Indicate that the response is complete.

The handler should call this when it has completed writing the response.

Implements xrpl::WSSession.

Definition at line 265 of file BaseWSPeer.h.

◆ impl()

template<class Handler, class Impl>
Impl & xrpl::BaseWSPeer< Handler, Impl >::impl ( )
protected

Definition at line 118 of file BaseWSPeer.h.

◆ onWsHandshake()

template<class Handler, class Impl>
void xrpl::BaseWSPeer< Handler, Impl >::onWsHandshake ( ErrorCode const & ec)
protected

Definition at line 274 of file BaseWSPeer.h.

◆ doWrite()

template<class Handler, class Impl>
void xrpl::BaseWSPeer< Handler, Impl >::doWrite ( )
protected

Definition at line 284 of file BaseWSPeer.h.

◆ onWrite()

template<class Handler, class Impl>
void xrpl::BaseWSPeer< Handler, Impl >::onWrite ( ErrorCode const & ec)
protected

Definition at line 293 of file BaseWSPeer.h.

◆ onWriteFin()

template<class Handler, class Impl>
void xrpl::BaseWSPeer< Handler, Impl >::onWriteFin ( ErrorCode const & ec)
protected

Definition at line 326 of file BaseWSPeer.h.

◆ doRead()

template<class Handler, class Impl>
void xrpl::BaseWSPeer< Handler, Impl >::doRead ( )
protected

Definition at line 346 of file BaseWSPeer.h.

◆ onRead()

template<class Handler, class Impl>
void xrpl::BaseWSPeer< Handler, Impl >::onRead ( ErrorCode const & ec)
protected

Definition at line 360 of file BaseWSPeer.h.

◆ onClose()

template<class Handler, class Impl>
void xrpl::BaseWSPeer< Handler, Impl >::onClose ( ErrorCode const & ec)
protected

Definition at line 376 of file BaseWSPeer.h.

◆ startTimer()

template<class Handler, class Impl>
void xrpl::BaseWSPeer< Handler, Impl >::startTimer ( )
protected

Definition at line 383 of file BaseWSPeer.h.

◆ cancelTimer()

template<class Handler, class Impl>
void xrpl::BaseWSPeer< Handler, Impl >::cancelTimer ( )
protected

Definition at line 405 of file BaseWSPeer.h.

◆ onPing()

template<class Handler, class Impl>
void xrpl::BaseWSPeer< Handler, Impl >::onPing ( ErrorCode const & ec)
protected

Definition at line 419 of file BaseWSPeer.h.

◆ onPingPong()

template<class Handler, class Impl>
void xrpl::BaseWSPeer< Handler, Impl >::onPingPong ( boost::beast::websocket::frame_type kind,
std::string_view payload )
protected

Definition at line 431 of file BaseWSPeer.h.

◆ onTimer()

template<class Handler, class Impl>
void xrpl::BaseWSPeer< Handler, Impl >::onTimer ( ErrorCode ec)
protected

Definition at line 452 of file BaseWSPeer.h.

◆ fail()

template<class Handler, class Impl>
template<class String>
void xrpl::BaseWSPeer< Handler, Impl >::fail ( ErrorCode ec,
String const & what )
protected

Definition at line 481 of file BaseWSPeer.h.

◆ destroy()

template<class = void>
void xrpl::IOList::Work::destroy ( )
privateinherited

Definition at line 170 of file io_list.h.

◆ ios()

IOList & xrpl::IOList::Work::ios ( )
inherited

Return the IOList associated with the work.

Requirements: The call to IOList::emplace to create the work has already returned.

Definition at line 44 of file io_list.h.

◆ BasePeer< Handler, Impl >

template<class Handler, class Impl>
friend class BasePeer< Handler, Impl >
friend

Definition at line 481 of file BaseWSPeer.h.

Member Data Documentation

◆ request_

template<class Handler, class Impl>
HttpRequestType xrpl::BaseWSPeer< Handler, Impl >::request_
private

Definition at line 50 of file BaseWSPeer.h.

◆ rb_

template<class Handler, class Impl>
boost::beast::multi_buffer xrpl::BaseWSPeer< Handler, Impl >::rb_
private

Definition at line 51 of file BaseWSPeer.h.

◆ wb_

template<class Handler, class Impl>
boost::beast::multi_buffer xrpl::BaseWSPeer< Handler, Impl >::wb_
private

Definition at line 52 of file BaseWSPeer.h.

◆ wq_

template<class Handler, class Impl>
std::list<std::shared_ptr<WSMsg> > xrpl::BaseWSPeer< Handler, Impl >::wq_
private

Definition at line 53 of file BaseWSPeer.h.

◆ doClose_

template<class Handler, class Impl>
bool xrpl::BaseWSPeer< Handler, Impl >::doClose_ = false
private

The socket has been closed, or will close after the next write finishes.

Do not do any more writes, and don't try to close again.

Definition at line 59 of file BaseWSPeer.h.

◆ cr_

template<class Handler, class Impl>
boost::beast::websocket::close_reason xrpl::BaseWSPeer< Handler, Impl >::cr_
private

Definition at line 60 of file BaseWSPeer.h.

◆ timer_

template<class Handler, class Impl>
WaitableTimer xrpl::BaseWSPeer< Handler, Impl >::timer_
private

Definition at line 61 of file BaseWSPeer.h.

◆ closeOnTimer_

template<class Handler, class Impl>
bool xrpl::BaseWSPeer< Handler, Impl >::closeOnTimer_ = false
private

Definition at line 62 of file BaseWSPeer.h.

◆ pingActive_

template<class Handler, class Impl>
bool xrpl::BaseWSPeer< Handler, Impl >::pingActive_ = false
private

Definition at line 63 of file BaseWSPeer.h.

◆ payload_

template<class Handler, class Impl>
boost::beast::websocket::ping_data xrpl::BaseWSPeer< Handler, Impl >::payload_
private

Definition at line 64 of file BaseWSPeer.h.

◆ ec_

template<class Handler, class Impl>
ErrorCode xrpl::BaseWSPeer< Handler, Impl >::ec_
private

Definition at line 65 of file BaseWSPeer.h.

◆ controlCallback_

template<class Handler, class Impl>
std::function<void(boost::beast::websocket::frame_type, std::string_view)> xrpl::BaseWSPeer< Handler, Impl >::controlCallback_
private

Definition at line 66 of file BaseWSPeer.h.

◆ port_

template<class Handler, class Impl>
Port const& xrpl::BasePeer< Handler, Impl >::port_
protectedinherited

Definition at line 28 of file BasePeer.h.

◆ handler_

template<class Handler, class Impl>
Handler& xrpl::BasePeer< Handler, Impl >::handler_
protectedinherited

Definition at line 29 of file BasePeer.h.

◆ remoteAddress_

template<class Handler, class Impl>
EndpointType xrpl::BasePeer< Handler, Impl >::remoteAddress_
protectedinherited

Definition at line 30 of file BasePeer.h.

◆ sink_

template<class Handler, class Impl>
beast::WrappedSink xrpl::BasePeer< Handler, Impl >::sink_
protectedinherited

Definition at line 31 of file BasePeer.h.

◆ j_

template<class Handler, class Impl>
beast::Journal const xrpl::BasePeer< Handler, Impl >::j_
protectedinherited

Definition at line 32 of file BasePeer.h.

◆ work_

template<class Handler, class Impl>
boost::asio::executor_work_guard<boost::asio::executor> xrpl::BasePeer< Handler, Impl >::work_
protectedinherited

Definition at line 34 of file BasePeer.h.

◆ strand_

template<class Handler, class Impl>
boost::asio::strand<boost::asio::executor> xrpl::BasePeer< Handler, Impl >::strand_
protectedinherited

Definition at line 35 of file BasePeer.h.

◆ ios_

IOList* xrpl::IOList::Work::ios_ = nullptr
privateinherited

Definition at line 28 of file io_list.h.

◆ appDefined

std::shared_ptr<void> xrpl::WSSession::appDefined
inherited

Definition at line 90 of file WSSession.h.