xrpld
Loading...
Searching...
No Matches
xrpl::PlainHTTPPeer< Handler > Class Template Referenceabstract

#include <PlainHTTPPeer.h>

Inheritance diagram for xrpl::PlainHTTPPeer< Handler >:
Collaboration diagram for xrpl::PlainHTTPPeer< Handler >:

Public Member Functions

template<class ConstBufferSequence>
 PlainHTTPPeer (Port const &port, Handler &handler, boost::asio::io_context &ioc, beast::Journal journal, EndpointType remoteAddress, ConstBufferSequence const &buffers, StreamType &&stream)
void run ()
std::shared_ptr< WSSession > websocketUpgrade () override
 Convert the connection to WebSocket.
Session & session ()
void close () override
virtual void close (bool graceful)=0
 Close the session.
IOList & ios ()
 Return the IOList associated with the work.
T shared_from_this (T... args)
T weak_from_this (T... args)
void write (std::string_view s)
 Send a copy of data asynchronously.
void write (BufferSequence const &buffers)
virtual void write (std::shared_ptr< Writer > const &writer, bool keepAlive)=0

Public Attributes

void * tag
 A user-definable pointer.

Protected Types

using ClockType
using ErrorCode
using YieldContext

Protected Member Functions

PlainHTTPPeer< Handler > & impl ()
void fail (ErrorCode ec, char const *what)
void startTimer ()
void cancelTimer ()
void onTimer ()
void doRead (YieldContext doYield)
void onWrite (ErrorCode const &ec, std::size_t bytesTransferred)
void doWriter (std::shared_ptr< Writer > const &writer, bool keepAlive, YieldContext doYield)
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.
HttpRequestType & request () override
 Returns the current HTTP request.
void write (void const *buffer, std::size_t bytes) override
std::shared_ptr< Session > detach () override
 Detach the session.
void complete () override
 Indicate that the response is complete.

Protected Attributes

Port const & port_
Handler & handler_
boost::asio::executor_work_guard< boost::asio::executor > work_
boost::asio::strand< boost::asio::executor > strand_
EndpointType remoteAddress_
beast::Journal const journal_
std::string id_
std::size_t nid_
boost::asio::streambuf readBuf_
HttpRequestType message_
std::vector< Buffer > wq_
std::vector< Buffer > wq2_
std::mutex mutex_
bool graceful_
bool complete_
boost::system::error_code ec_
int requestCount_
std::size_t bytesIn_
std::size_t bytesOut_

Static Protected Attributes

static constexpr auto kBufferSize
static constexpr auto kTimeoutSeconds
static constexpr auto kTimeoutSecondsLocal

Private Types

using SocketType = boost::asio::ip::tcp::socket
using StreamType = boost::beast::tcp_stream
using EndpointType = boost::asio::ip::tcp::endpoint

Private Member Functions

void doRequest () override
void doClose () override
void destroy ()

Private Attributes

StreamType stream_
SocketType & socket_
IOList * ios_

Friends

class BaseHTTPPeer< Handler, PlainHTTPPeer >

Detailed Description

template<class Handler>
class xrpl::PlainHTTPPeer< Handler >

Definition at line 18 of file PlainHTTPPeer.h.

Member Typedef Documentation

◆ SocketType

template<class Handler>
using xrpl::PlainHTTPPeer< Handler >::SocketType = boost::asio::ip::tcp::socket
private

Definition at line 23 of file PlainHTTPPeer.h.

◆ StreamType

template<class Handler>
using xrpl::PlainHTTPPeer< Handler >::StreamType = boost::beast::tcp_stream
private

Definition at line 24 of file PlainHTTPPeer.h.

◆ EndpointType

template<class Handler>
using xrpl::PlainHTTPPeer< Handler >::EndpointType = boost::asio::ip::tcp::endpoint
private

Definition at line 25 of file PlainHTTPPeer.h.

◆ ClockType

using xrpl::BaseHTTPPeer< Handler, PlainHTTPPeer< Handler > >::ClockType
protectedinherited

Definition at line 45 of file BaseHTTPPeer.h.

◆ ErrorCode

using xrpl::BaseHTTPPeer< Handler, PlainHTTPPeer< Handler > >::ErrorCode
protectedinherited

Definition at line 46 of file BaseHTTPPeer.h.

◆ YieldContext

using xrpl::BaseHTTPPeer< Handler, PlainHTTPPeer< Handler > >::YieldContext
protectedinherited

Definition at line 48 of file BaseHTTPPeer.h.

Constructor & Destructor Documentation

◆ PlainHTTPPeer()

template<class Handler>
template<class ConstBufferSequence>
xrpl::PlainHTTPPeer< Handler >::PlainHTTPPeer ( Port const & port,
Handler & handler,
boost::asio::io_context & ioc,
beast::Journal journal,
EndpointType remoteAddress,
ConstBufferSequence const & buffers,
StreamType && stream )

Definition at line 59 of file PlainHTTPPeer.h.

Member Function Documentation

◆ run()

template<class Handler>
void xrpl::PlainHTTPPeer< Handler >::run ( )

Definition at line 87 of file PlainHTTPPeer.h.

◆ websocketUpgrade()

template<class Handler>
std::shared_ptr< WSSession > xrpl::PlainHTTPPeer< Handler >::websocketUpgrade ( )
overridevirtual

Convert the connection to WebSocket.

Implements xrpl::Session.

Definition at line 108 of file PlainHTTPPeer.h.

◆ doRequest()

template<class Handler>
void xrpl::PlainHTTPPeer< Handler >::doRequest ( )
overrideprivatevirtual

◆ doClose()

template<class Handler>
void xrpl::PlainHTTPPeer< Handler >::doClose ( )
overrideprivatevirtual

◆ session()

Session & xrpl::BaseHTTPPeer< Handler, PlainHTTPPeer< Handler > >::session ( )
inherited

Definition at line 104 of file BaseHTTPPeer.h.

◆ close() [1/2]

void xrpl::BaseHTTPPeer< Handler, PlainHTTPPeer< Handler > >::close ( )
overridevirtualinherited

Implements xrpl::IOList::Work.

Definition at line 110 of file BaseHTTPPeer.h.

◆ close() [2/2]

virtual void xrpl::Session::close ( bool graceful)
pure virtualinherited

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.

Implemented in xrpl::BaseHTTPPeer< Handler, Impl >.

◆ impl()

PlainHTTPPeer< Handler > & xrpl::BaseHTTPPeer< Handler, PlainHTTPPeer< Handler > >::impl ( )
protectedinherited

Definition at line 114 of file BaseHTTPPeer.h.

◆ fail()

void xrpl::BaseHTTPPeer< Handler, PlainHTTPPeer< Handler > >::fail ( ErrorCode ec,
char const * what )
protectedinherited

Definition at line 120 of file BaseHTTPPeer.h.

◆ startTimer()

void xrpl::BaseHTTPPeer< Handler, PlainHTTPPeer< Handler > >::startTimer ( )
protectedinherited

Definition at line 123 of file BaseHTTPPeer.h.

◆ cancelTimer()

void xrpl::BaseHTTPPeer< Handler, PlainHTTPPeer< Handler > >::cancelTimer ( )
protectedinherited

Definition at line 126 of file BaseHTTPPeer.h.

◆ onTimer()

void xrpl::BaseHTTPPeer< Handler, PlainHTTPPeer< Handler > >::onTimer ( )
protectedinherited

Definition at line 129 of file BaseHTTPPeer.h.

◆ doRead()

void xrpl::BaseHTTPPeer< Handler, PlainHTTPPeer< Handler > >::doRead ( YieldContext doYield)
protectedinherited

Definition at line 132 of file BaseHTTPPeer.h.

◆ onWrite()

void xrpl::BaseHTTPPeer< Handler, PlainHTTPPeer< Handler > >::onWrite ( ErrorCode const & ec,
std::size_t bytesTransferred )
protectedinherited

Definition at line 135 of file BaseHTTPPeer.h.

◆ doWriter()

void xrpl::BaseHTTPPeer< Handler, PlainHTTPPeer< Handler > >::doWriter ( std::shared_ptr< Writer > const & writer,
bool keepAlive,
YieldContext doYield )
protectedinherited

Definition at line 138 of file BaseHTTPPeer.h.

◆ journal()

beast::Journal xrpl::BaseHTTPPeer< Handler, PlainHTTPPeer< Handler > >::journal ( )
overrideprotectedvirtualinherited

Returns the Journal to use for logging.

Implements xrpl::Session.

Definition at line 149 of file BaseHTTPPeer.h.

◆ port()

Port const & xrpl::BaseHTTPPeer< Handler, PlainHTTPPeer< Handler > >::port ( )
overrideprotectedvirtualinherited

Returns the Port settings for this connection.

Implements xrpl::Session.

Definition at line 155 of file BaseHTTPPeer.h.

◆ remoteAddress()

beast::ip::Endpoint xrpl::BaseHTTPPeer< Handler, PlainHTTPPeer< Handler > >::remoteAddress ( )
overrideprotectedvirtualinherited

Returns the remote address of the connection.

Implements xrpl::Session.

Definition at line 161 of file BaseHTTPPeer.h.

◆ request()

HttpRequestType & xrpl::BaseHTTPPeer< Handler, PlainHTTPPeer< Handler > >::request ( )
overrideprotectedvirtualinherited

Returns the current HTTP request.

Implements xrpl::Session.

Definition at line 167 of file BaseHTTPPeer.h.

◆ write() [1/4]

void xrpl::BaseHTTPPeer< Handler, PlainHTTPPeer< Handler > >::write ( void const * buffer,
std::size_t bytes )
overrideprotectedvirtualinherited

Implements xrpl::Session.

Definition at line 173 of file BaseHTTPPeer.h.

◆ write() [2/4]

Send a copy of data asynchronously.

Definition at line 69 of file Session.h.

◆ write() [3/4]

void xrpl::Session::write ( BufferSequence const & buffers)
inherited

Definition at line 77 of file Session.h.

◆ write() [4/4]

virtual void xrpl::Session::write ( std::shared_ptr< Writer > const & writer,
bool keepAlive )
pure virtualinherited

◆ detach()

std::shared_ptr< Session > xrpl::BaseHTTPPeer< Handler, PlainHTTPPeer< Handler > >::detach ( )
overrideprotectedvirtualinherited

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 179 of file BaseHTTPPeer.h.

◆ complete()

void xrpl::BaseHTTPPeer< Handler, PlainHTTPPeer< Handler > >::complete ( )
overrideprotectedvirtualinherited

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 182 of file BaseHTTPPeer.h.

◆ destroy()

void xrpl::IOList::Work::destroy ( )
privateinherited

Definition at line 25 of file io_list.h.

◆ ios()

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.

◆ BaseHTTPPeer< Handler, PlainHTTPPeer >

template<class Handler>
friend class BaseHTTPPeer< Handler, PlainHTTPPeer >
friend

Definition at line 151 of file PlainHTTPPeer.h.

Member Data Documentation

◆ stream_

template<class Handler>
StreamType xrpl::PlainHTTPPeer< Handler >::stream_
private

Definition at line 27 of file PlainHTTPPeer.h.

◆ socket_

template<class Handler>
SocketType& xrpl::PlainHTTPPeer< Handler >::socket_
private

Definition at line 28 of file PlainHTTPPeer.h.

◆ kBufferSize

auto xrpl::BaseHTTPPeer< Handler, PlainHTTPPeer< Handler > >::kBufferSize
staticconstexprprotectedinherited

Definition at line 50 of file BaseHTTPPeer.h.

◆ kTimeoutSeconds

auto xrpl::BaseHTTPPeer< Handler, PlainHTTPPeer< Handler > >::kTimeoutSeconds
staticconstexprprotectedinherited

Definition at line 51 of file BaseHTTPPeer.h.

◆ kTimeoutSecondsLocal

auto xrpl::BaseHTTPPeer< Handler, PlainHTTPPeer< Handler > >::kTimeoutSecondsLocal
staticconstexprprotectedinherited

Definition at line 52 of file BaseHTTPPeer.h.

◆ port_

Port const& xrpl::BaseHTTPPeer< Handler, PlainHTTPPeer< Handler > >::port_
protectedinherited

Definition at line 66 of file BaseHTTPPeer.h.

◆ handler_

Handler& xrpl::BaseHTTPPeer< Handler, PlainHTTPPeer< Handler > >::handler_
protectedinherited

Definition at line 67 of file BaseHTTPPeer.h.

◆ work_

boost::asio::executor_work_guard<boost::asio::executor> xrpl::BaseHTTPPeer< Handler, PlainHTTPPeer< Handler > >::work_
protectedinherited

Definition at line 68 of file BaseHTTPPeer.h.

◆ strand_

boost::asio::strand<boost::asio::executor> xrpl::BaseHTTPPeer< Handler, PlainHTTPPeer< Handler > >::strand_
protectedinherited

Definition at line 69 of file BaseHTTPPeer.h.

◆ remoteAddress_

EndpointType xrpl::BaseHTTPPeer< Handler, PlainHTTPPeer< Handler > >::remoteAddress_
protectedinherited

Definition at line 70 of file BaseHTTPPeer.h.

◆ journal_

beast::Journal const xrpl::BaseHTTPPeer< Handler, PlainHTTPPeer< Handler > >::journal_
protectedinherited

Definition at line 71 of file BaseHTTPPeer.h.

◆ id_

std::string xrpl::BaseHTTPPeer< Handler, PlainHTTPPeer< Handler > >::id_
protectedinherited

Definition at line 73 of file BaseHTTPPeer.h.

◆ nid_

std::size_t xrpl::BaseHTTPPeer< Handler, PlainHTTPPeer< Handler > >::nid_
protectedinherited

Definition at line 74 of file BaseHTTPPeer.h.

◆ readBuf_

boost::asio::streambuf xrpl::BaseHTTPPeer< Handler, PlainHTTPPeer< Handler > >::readBuf_
protectedinherited

Definition at line 76 of file BaseHTTPPeer.h.

◆ message_

HttpRequestType xrpl::BaseHTTPPeer< Handler, PlainHTTPPeer< Handler > >::message_
protectedinherited

Definition at line 77 of file BaseHTTPPeer.h.

◆ wq_

std::vector<Buffer> xrpl::BaseHTTPPeer< Handler, PlainHTTPPeer< Handler > >::wq_
protectedinherited

Definition at line 78 of file BaseHTTPPeer.h.

◆ wq2_

std::vector<Buffer> xrpl::BaseHTTPPeer< Handler, PlainHTTPPeer< Handler > >::wq2_
protectedinherited

Definition at line 79 of file BaseHTTPPeer.h.

◆ mutex_

std::mutex xrpl::BaseHTTPPeer< Handler, PlainHTTPPeer< Handler > >::mutex_
protectedinherited

Definition at line 80 of file BaseHTTPPeer.h.

◆ graceful_

bool xrpl::BaseHTTPPeer< Handler, PlainHTTPPeer< Handler > >::graceful_
protectedinherited

Definition at line 81 of file BaseHTTPPeer.h.

◆ complete_

bool xrpl::BaseHTTPPeer< Handler, PlainHTTPPeer< Handler > >::complete_
protectedinherited

Definition at line 82 of file BaseHTTPPeer.h.

◆ ec_

boost::system::error_code xrpl::BaseHTTPPeer< Handler, PlainHTTPPeer< Handler > >::ec_
protectedinherited

Definition at line 83 of file BaseHTTPPeer.h.

◆ requestCount_

int xrpl::BaseHTTPPeer< Handler, PlainHTTPPeer< Handler > >::requestCount_
protectedinherited

Definition at line 85 of file BaseHTTPPeer.h.

◆ bytesIn_

std::size_t xrpl::BaseHTTPPeer< Handler, PlainHTTPPeer< Handler > >::bytesIn_
protectedinherited

Definition at line 86 of file BaseHTTPPeer.h.

◆ bytesOut_

std::size_t xrpl::BaseHTTPPeer< Handler, PlainHTTPPeer< Handler > >::bytesOut_
protectedinherited

Definition at line 87 of file BaseHTTPPeer.h.

◆ ios_

IOList* xrpl::IOList::Work::ios_
privateinherited

Definition at line 28 of file io_list.h.

◆ tag

void* xrpl::Session::tag
inherited

A user-definable pointer.

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

Definition at line 38 of file Session.h.