xrpld
Loading...
Searching...
No Matches
xrpl::BaseHTTPPeer< Handler, Impl > Class Template Referenceabstract

Represents an active connection. More...

#include <BaseHTTPPeer.h>

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

Classes

struct  Buffer

Public Member Functions

template<class ConstBufferSequence>
 BaseHTTPPeer (Port const &port, Handler &handler, boost::asio::executor const &executor, beast::Journal journal, endpoint_type remoteAddress, ConstBufferSequence const &buffers)
 ~BaseHTTPPeer () override
Sessionsession ()
void close () override
IOListios ()
 Return the IOList associated with the work.
virtual std::shared_ptr< WSSessionwebsocketUpgrade ()=0
 Convert the connection to WebSocket.
void write (std::string_view s)
 Send a copy of data asynchronously.
template<typename BufferSequence>
void write (BufferSequence const &buffers)

Public Attributes

void * tag = nullptr
 A user-definable pointer.

Protected Types

using clock_type = std::chrono::system_clock
using error_code = boost::system::error_code
using endpoint_type = boost::asio::ip::tcp::endpoint
using yield_context = boost::asio::yield_context

Protected Member Functions

Impl & impl ()
void fail (error_code ec, char const *what)
void startTimer ()
void cancelTimer ()
void onTimer ()
void doRead (yield_context doYield)
void onWrite (error_code const &ec, std::size_t bytesTransferred)
void doWriter (std::shared_ptr< Writer > const &writer, bool keepAlive, yield_context doYield)
virtual void doRequest ()=0
virtual void doClose ()=0
beast::Journal journal () override
 Returns the Journal to use for logging.
Port const & port () override
 Returns the Port settings for this connection.
beast::IP::Endpoint remoteAddress () override
 Returns the remote address of the connection.
http_request_typerequest () override
 Returns the current HTTP request.
void write (void const *buffer, std::size_t bytes) override
void write (std::shared_ptr< Writer > const &writer, bool keepAlive) override
std::shared_ptr< Sessiondetach () override
 Detach the session.
void complete () override
 Indicate that the response is complete.
void close (bool graceful) override
 Close the session.

Protected Attributes

Port const & port_
Handler & handler_
boost::asio::executor_work_guard< boost::asio::executor > work_
boost::asio::strand< boost::asio::executor > strand_
endpoint_type remoteAddress_
beast::Journal const journal_
std::string id_
std::size_t nid_
boost::asio::streambuf readBuf_
http_request_type message_
std::vector< Bufferwq_
std::vector< Bufferwq2_
std::mutex mutex_
bool graceful_ = false
bool complete_ = false
boost::system::error_code ec_
int requestCount_ = 0
std::size_t bytesIn_ = 0
std::size_t bytesOut_ = 0

Static Protected Attributes

static constexpr auto kBufferSize = 4 * 1024
static constexpr auto kTimeoutSeconds = 30
static constexpr auto kTimeoutSecondsLocal = 3

Private Member Functions

template<class = void>
void destroy ()

Private Attributes

IOListios_ = nullptr

Detailed Description

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

Represents an active connection.

Definition at line 33 of file BaseHTTPPeer.h.

Member Typedef Documentation

◆ clock_type

template<class Handler, class Impl>
using xrpl::BaseHTTPPeer< Handler, Impl >::clock_type = std::chrono::system_clock
protected

Definition at line 36 of file BaseHTTPPeer.h.

◆ error_code

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

Definition at line 37 of file BaseHTTPPeer.h.

◆ endpoint_type

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

Definition at line 38 of file BaseHTTPPeer.h.

◆ yield_context

template<class Handler, class Impl>
using xrpl::BaseHTTPPeer< Handler, Impl >::yield_context = boost::asio::yield_context
protected

Definition at line 39 of file BaseHTTPPeer.h.

Constructor & Destructor Documentation

◆ BaseHTTPPeer()

template<class Handler, class Impl>
template<class ConstBufferSequence>
xrpl::BaseHTTPPeer< Handler, Impl >::BaseHTTPPeer ( Port const & port,
Handler & handler,
boost::asio::executor const & executor,
beast::Journal journal,
endpoint_type remoteAddress,
ConstBufferSequence const & buffers )

Definition at line 183 of file BaseHTTPPeer.h.

◆ ~BaseHTTPPeer()

template<class Handler, class Impl>
xrpl::BaseHTTPPeer< Handler, Impl >::~BaseHTTPPeer ( )
override

Definition at line 206 of file BaseHTTPPeer.h.

Member Function Documentation

◆ session()

template<class Handler, class Impl>
Session & xrpl::BaseHTTPPeer< Handler, Impl >::session ( )

Definition at line 95 of file BaseHTTPPeer.h.

◆ close() [1/2]

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

Implements xrpl::IOList::Work.

Definition at line 215 of file BaseHTTPPeer.h.

◆ impl()

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

Definition at line 105 of file BaseHTTPPeer.h.

◆ fail()

template<class Handler, class Impl>
void xrpl::BaseHTTPPeer< Handler, Impl >::fail ( error_code ec,
char const * what )
protected

Definition at line 231 of file BaseHTTPPeer.h.

◆ startTimer()

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

Definition at line 243 of file BaseHTTPPeer.h.

◆ cancelTimer()

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

Definition at line 254 of file BaseHTTPPeer.h.

◆ onTimer()

template<class Handler, class Impl>
void xrpl::BaseHTTPPeer< Handler, Impl >::onTimer ( )
protected

Definition at line 262 of file BaseHTTPPeer.h.

◆ doRead()

template<class Handler, class Impl>
void xrpl::BaseHTTPPeer< Handler, Impl >::doRead ( yield_context doYield)
protected

Definition at line 272 of file BaseHTTPPeer.h.

◆ onWrite()

template<class Handler, class Impl>
void xrpl::BaseHTTPPeer< Handler, Impl >::onWrite ( error_code const & ec,
std::size_t bytesTransferred )
protected

Definition at line 292 of file BaseHTTPPeer.h.

◆ doWriter()

template<class Handler, class Impl>
void xrpl::BaseHTTPPeer< Handler, Impl >::doWriter ( std::shared_ptr< Writer > const & writer,
bool keepAlive,
yield_context doYield )
protected

Definition at line 338 of file BaseHTTPPeer.h.

◆ doRequest()

template<class Handler, class Impl>
virtual void xrpl::BaseHTTPPeer< Handler, Impl >::doRequest ( )
protectedpure virtual

◆ doClose()

template<class Handler, class Impl>
virtual void xrpl::BaseHTTPPeer< Handler, Impl >::doClose ( )
protectedpure virtual

◆ journal()

template<class Handler, class Impl>
beast::Journal xrpl::BaseHTTPPeer< Handler, Impl >::journal ( )
overrideprotectedvirtual

Returns the Journal to use for logging.

Implements xrpl::Session.

Definition at line 140 of file BaseHTTPPeer.h.

◆ port()

template<class Handler, class Impl>
Port const & xrpl::BaseHTTPPeer< Handler, Impl >::port ( )
overrideprotectedvirtual

Returns the Port settings for this connection.

Implements xrpl::Session.

Definition at line 146 of file BaseHTTPPeer.h.

◆ remoteAddress()

template<class Handler, class Impl>
beast::IP::Endpoint xrpl::BaseHTTPPeer< Handler, Impl >::remoteAddress ( )
overrideprotectedvirtual

Returns the remote address of the connection.

Implements xrpl::Session.

Definition at line 152 of file BaseHTTPPeer.h.

◆ request()

template<class Handler, class Impl>
http_request_type & xrpl::BaseHTTPPeer< Handler, Impl >::request ( )
overrideprotectedvirtual

Returns the current HTTP request.

Implements xrpl::Session.

Definition at line 158 of file BaseHTTPPeer.h.

◆ write() [1/4]

template<class Handler, class Impl>
void xrpl::BaseHTTPPeer< Handler, Impl >::write ( void const * buffer,
std::size_t bytes )
overrideprotectedvirtual

Implements xrpl::Session.

Definition at line 388 of file BaseHTTPPeer.h.

◆ write() [2/4]

template<class Handler, class Impl>
void xrpl::BaseHTTPPeer< Handler, Impl >::write ( std::shared_ptr< Writer > const & writer,
bool keepAlive )
overrideprotectedvirtual

Implements xrpl::Session.

Definition at line 410 of file BaseHTTPPeer.h.

◆ detach()

template<class Handler, class Impl>
std::shared_ptr< Session > xrpl::BaseHTTPPeer< Handler, Impl >::detach ( )
overrideprotectedvirtual

Detach the session.

This holds the session open so that the response can be sent asynchronously. Calls to io_context::run made by the server will not return until all detached sessions are closed.

Implements xrpl::Session.

Definition at line 426 of file BaseHTTPPeer.h.

◆ complete()

template<class Handler, class Impl>
void xrpl::BaseHTTPPeer< Handler, Impl >::complete ( )
overrideprotectedvirtual

Indicate that the response is complete.

The handler should call this when it has completed writing the response. If Keep-Alive is indicated on the connection, this will trigger a read for the next request; else, the connection will be closed when all remaining data has been sent.

Implements xrpl::Session.

Definition at line 435 of file BaseHTTPPeer.h.

◆ close() [2/2]

template<class Handler, class Impl>
void xrpl::BaseHTTPPeer< Handler, Impl >::close ( bool graceful)
overrideprotectedvirtual

Close the session.

This will be performed asynchronously. The session will be closed gracefully after all pending writes have completed.

Parameters
gracefultrue to wait until all data has finished sending.

Implements xrpl::Session.

Definition at line 465 of file BaseHTTPPeer.h.

◆ destroy()

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

Definition at line 162 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 40 of file io_list.h.

◆ write() [3/4]

void xrpl::Session::write ( std::string_view s)
inherited

Send a copy of data asynchronously.

Definition at line 57 of file Session.h.

◆ write() [4/4]

template<typename BufferSequence>
void xrpl::Session::write ( BufferSequence const & buffers)
inherited

Definition at line 65 of file Session.h.

◆ websocketUpgrade()

virtual std::shared_ptr< WSSession > xrpl::Session::websocketUpgrade ( )
pure virtualinherited

Convert the connection to WebSocket.

Implemented in xrpl::PlainHTTPPeer< Handler >, and xrpl::SSLHTTPPeer< Handler >.

Member Data Documentation

◆ kBufferSize

template<class Handler, class Impl>
auto xrpl::BaseHTTPPeer< Handler, Impl >::kBufferSize = 4 * 1024
staticconstexprprotected

Definition at line 41 of file BaseHTTPPeer.h.

◆ kTimeoutSeconds

template<class Handler, class Impl>
auto xrpl::BaseHTTPPeer< Handler, Impl >::kTimeoutSeconds = 30
staticconstexprprotected

Definition at line 42 of file BaseHTTPPeer.h.

◆ kTimeoutSecondsLocal

template<class Handler, class Impl>
auto xrpl::BaseHTTPPeer< Handler, Impl >::kTimeoutSecondsLocal = 3
staticconstexprprotected

Definition at line 43 of file BaseHTTPPeer.h.

◆ port_

template<class Handler, class Impl>
Port const& xrpl::BaseHTTPPeer< Handler, Impl >::port_
protected

Definition at line 57 of file BaseHTTPPeer.h.

◆ handler_

template<class Handler, class Impl>
Handler& xrpl::BaseHTTPPeer< Handler, Impl >::handler_
protected

Definition at line 58 of file BaseHTTPPeer.h.

◆ work_

template<class Handler, class Impl>
boost::asio::executor_work_guard<boost::asio::executor> xrpl::BaseHTTPPeer< Handler, Impl >::work_
protected

Definition at line 59 of file BaseHTTPPeer.h.

◆ strand_

template<class Handler, class Impl>
boost::asio::strand<boost::asio::executor> xrpl::BaseHTTPPeer< Handler, Impl >::strand_
protected

Definition at line 60 of file BaseHTTPPeer.h.

◆ remoteAddress_

template<class Handler, class Impl>
endpoint_type xrpl::BaseHTTPPeer< Handler, Impl >::remoteAddress_
protected

Definition at line 61 of file BaseHTTPPeer.h.

◆ journal_

template<class Handler, class Impl>
beast::Journal const xrpl::BaseHTTPPeer< Handler, Impl >::journal_
protected

Definition at line 62 of file BaseHTTPPeer.h.

◆ id_

template<class Handler, class Impl>
std::string xrpl::BaseHTTPPeer< Handler, Impl >::id_
protected

Definition at line 64 of file BaseHTTPPeer.h.

◆ nid_

template<class Handler, class Impl>
std::size_t xrpl::BaseHTTPPeer< Handler, Impl >::nid_
protected

Definition at line 65 of file BaseHTTPPeer.h.

◆ readBuf_

template<class Handler, class Impl>
boost::asio::streambuf xrpl::BaseHTTPPeer< Handler, Impl >::readBuf_
protected

Definition at line 67 of file BaseHTTPPeer.h.

◆ message_

template<class Handler, class Impl>
http_request_type xrpl::BaseHTTPPeer< Handler, Impl >::message_
protected

Definition at line 68 of file BaseHTTPPeer.h.

◆ wq_

template<class Handler, class Impl>
std::vector<Buffer> xrpl::BaseHTTPPeer< Handler, Impl >::wq_
protected

Definition at line 69 of file BaseHTTPPeer.h.

◆ wq2_

template<class Handler, class Impl>
std::vector<Buffer> xrpl::BaseHTTPPeer< Handler, Impl >::wq2_
protected

Definition at line 70 of file BaseHTTPPeer.h.

◆ mutex_

template<class Handler, class Impl>
std::mutex xrpl::BaseHTTPPeer< Handler, Impl >::mutex_
protected

Definition at line 71 of file BaseHTTPPeer.h.

◆ graceful_

template<class Handler, class Impl>
bool xrpl::BaseHTTPPeer< Handler, Impl >::graceful_ = false
protected

Definition at line 72 of file BaseHTTPPeer.h.

◆ complete_

template<class Handler, class Impl>
bool xrpl::BaseHTTPPeer< Handler, Impl >::complete_ = false
protected

Definition at line 73 of file BaseHTTPPeer.h.

◆ ec_

template<class Handler, class Impl>
boost::system::error_code xrpl::BaseHTTPPeer< Handler, Impl >::ec_
protected

Definition at line 74 of file BaseHTTPPeer.h.

◆ requestCount_

template<class Handler, class Impl>
int xrpl::BaseHTTPPeer< Handler, Impl >::requestCount_ = 0
protected

Definition at line 76 of file BaseHTTPPeer.h.

◆ bytesIn_

template<class Handler, class Impl>
std::size_t xrpl::BaseHTTPPeer< Handler, Impl >::bytesIn_ = 0
protected

Definition at line 77 of file BaseHTTPPeer.h.

◆ bytesOut_

template<class Handler, class Impl>
std::size_t xrpl::BaseHTTPPeer< Handler, Impl >::bytesOut_ = 0
protected

Definition at line 78 of file BaseHTTPPeer.h.

◆ ios_

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

Definition at line 25 of file io_list.h.

◆ tag

void* xrpl::Session::tag = nullptr
inherited

A user-definable pointer.

The initial value is always zero. Changes to the value are persisted between calls.

Definition at line 36 of file Session.h.