rippled
Loading...
Searching...
No Matches
Classes | Public Member Functions | Public Attributes | Protected Types | Protected Member Functions | Protected Attributes | Private Member Functions | Private Attributes | List of all members
ripple::BaseHTTPPeer< Handler, Impl > Class Template Referenceabstract

Represents an active connection. More...

#include <BaseHTTPPeer.h>

Inheritance diagram for ripple::BaseHTTPPeer< Handler, Impl >:
Inheritance graph
[legend]
Collaboration diagram for ripple::BaseHTTPPeer< Handler, Impl >:
Collaboration graph
[legend]

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 remote_address, ConstBufferSequence const &buffers)
 
virtual ~BaseHTTPPeer ()
 
Sessionsession ()
 
void close () override
 
io_listios ()
 Return the io_list associated with the work.
 
virtual std::shared_ptr< WSSessionwebsocketUpgrade ()=0
 Convert the connection to WebSocket.
 
void write (std::string const &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

enum  { bufferSize = 4 * 1024 , timeoutSeconds = 30 , timeoutSecondsLocal = 3 }
 
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 start_timer ()
 
void cancel_timer ()
 
void on_timer ()
 
void do_read (yield_context do_yield)
 
void on_write (error_code const &ec, std::size_t bytes_transferred)
 
void do_writer (std::shared_ptr< Writer > const &writer, bool keep_alive, yield_context do_yield)
 
virtual void do_request ()=0
 
virtual void do_close ()=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 keep_alive) 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 remote_address_
 
beast::Journal const journal_
 
std::string id_
 
std::size_t nid_
 
boost::asio::streambuf read_buf_
 
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 request_count_ = 0
 
std::size_t bytes_in_ = 0
 
std::size_t bytes_out_ = 0
 

Private Member Functions

template<class = void>
void destroy ()
 

Private Attributes

io_listios_ = nullptr
 

Detailed Description

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

Represents an active connection.

Definition at line 52 of file BaseHTTPPeer.h.

Member Typedef Documentation

◆ clock_type

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

Definition at line 55 of file BaseHTTPPeer.h.

◆ error_code

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

Definition at line 56 of file BaseHTTPPeer.h.

◆ endpoint_type

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

Definition at line 57 of file BaseHTTPPeer.h.

◆ yield_context

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

Definition at line 58 of file BaseHTTPPeer.h.

Member Enumeration Documentation

◆ anonymous enum

template<class Handler , class Impl >
anonymous enum
protected
Enumerator
bufferSize 
timeoutSeconds 
timeoutSecondsLocal 

Definition at line 60 of file BaseHTTPPeer.h.

Constructor & Destructor Documentation

◆ BaseHTTPPeer()

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

Definition at line 211 of file BaseHTTPPeer.h.

◆ ~BaseHTTPPeer()

template<class Handler , class Impl >
ripple::BaseHTTPPeer< Handler, Impl >::~BaseHTTPPeer ( )
virtual

Definition at line 234 of file BaseHTTPPeer.h.

Member Function Documentation

◆ session()

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

Definition at line 120 of file BaseHTTPPeer.h.

◆ close() [1/2]

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

Implements ripple::io_list::work.

Definition at line 244 of file BaseHTTPPeer.h.

◆ impl()

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

Definition at line 130 of file BaseHTTPPeer.h.

◆ fail()

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

Definition at line 259 of file BaseHTTPPeer.h.

◆ start_timer()

template<class Handler , class Impl >
void ripple::BaseHTTPPeer< Handler, Impl >::start_timer ( )
protected

Definition at line 272 of file BaseHTTPPeer.h.

◆ cancel_timer()

template<class Handler , class Impl >
void ripple::BaseHTTPPeer< Handler, Impl >::cancel_timer ( )
protected

Definition at line 283 of file BaseHTTPPeer.h.

◆ on_timer()

template<class Handler , class Impl >
void ripple::BaseHTTPPeer< Handler, Impl >::on_timer ( )
protected

Definition at line 291 of file BaseHTTPPeer.h.

◆ do_read()

template<class Handler , class Impl >
void ripple::BaseHTTPPeer< Handler, Impl >::do_read ( yield_context  do_yield)
protected

Definition at line 302 of file BaseHTTPPeer.h.

◆ on_write()

template<class Handler , class Impl >
void ripple::BaseHTTPPeer< Handler, Impl >::on_write ( error_code const &  ec,
std::size_t  bytes_transferred 
)
protected

Definition at line 323 of file BaseHTTPPeer.h.

◆ do_writer()

template<class Handler , class Impl >
void ripple::BaseHTTPPeer< Handler, Impl >::do_writer ( std::shared_ptr< Writer > const &  writer,
bool  keep_alive,
yield_context  do_yield 
)
protected

Definition at line 371 of file BaseHTTPPeer.h.

◆ do_request()

template<class Handler , class Impl >
virtual void ripple::BaseHTTPPeer< Handler, Impl >::do_request ( )
protectedpure virtual

◆ do_close()

template<class Handler , class Impl >
virtual void ripple::BaseHTTPPeer< Handler, Impl >::do_close ( )
protectedpure virtual

◆ journal()

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

Returns the Journal to use for logging.

Implements ripple::Session.

Definition at line 168 of file BaseHTTPPeer.h.

◆ port()

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

Returns the Port settings for this connection.

Implements ripple::Session.

Definition at line 174 of file BaseHTTPPeer.h.

◆ remoteAddress()

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

Returns the remote address of the connection.

Implements ripple::Session.

Definition at line 180 of file BaseHTTPPeer.h.

◆ request()

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

Returns the current HTTP request.

Implements ripple::Session.

Definition at line 186 of file BaseHTTPPeer.h.

◆ write() [1/4]

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

Implements ripple::Session.

Definition at line 424 of file BaseHTTPPeer.h.

◆ write() [2/4]

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

Implements ripple::Session.

Definition at line 449 of file BaseHTTPPeer.h.

◆ detach()

template<class Handler , class Impl >
std::shared_ptr< Session > ripple::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 ripple::Session.

Definition at line 467 of file BaseHTTPPeer.h.

◆ complete()

template<class Handler , class Impl >
void ripple::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 ripple::Session.

Definition at line 476 of file BaseHTTPPeer.h.

◆ close() [2/2]

template<class Handler , class Impl >
void ripple::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 ripple::Session.

Definition at line 507 of file BaseHTTPPeer.h.

◆ destroy()

template<class = void>
void ripple::io_list::work::destroy ( )
privateinherited

Definition at line 182 of file io_list.h.

◆ ios()

io_list & ripple::io_list::work::ios ( )
inherited

Return the io_list associated with the work.

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

Definition at line 60 of file io_list.h.

◆ write() [3/4]

void ripple::Session::write ( std::string const &  s)
inherited

Send a copy of data asynchronously.

Definition at line 76 of file Session.h.

◆ write() [4/4]

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

Definition at line 84 of file Session.h.

◆ websocketUpgrade()

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

Convert the connection to WebSocket.

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

Member Data Documentation

◆ port_

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

Definition at line 82 of file BaseHTTPPeer.h.

◆ handler_

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

Definition at line 83 of file BaseHTTPPeer.h.

◆ work_

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

Definition at line 84 of file BaseHTTPPeer.h.

◆ strand_

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

Definition at line 85 of file BaseHTTPPeer.h.

◆ remote_address_

template<class Handler , class Impl >
endpoint_type ripple::BaseHTTPPeer< Handler, Impl >::remote_address_
protected

Definition at line 86 of file BaseHTTPPeer.h.

◆ journal_

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

Definition at line 87 of file BaseHTTPPeer.h.

◆ id_

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

Definition at line 89 of file BaseHTTPPeer.h.

◆ nid_

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

Definition at line 90 of file BaseHTTPPeer.h.

◆ read_buf_

template<class Handler , class Impl >
boost::asio::streambuf ripple::BaseHTTPPeer< Handler, Impl >::read_buf_
protected

Definition at line 92 of file BaseHTTPPeer.h.

◆ message_

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

Definition at line 93 of file BaseHTTPPeer.h.

◆ wq_

template<class Handler , class Impl >
std::vector<buffer> ripple::BaseHTTPPeer< Handler, Impl >::wq_
protected

Definition at line 94 of file BaseHTTPPeer.h.

◆ wq2_

template<class Handler , class Impl >
std::vector<buffer> ripple::BaseHTTPPeer< Handler, Impl >::wq2_
protected

Definition at line 95 of file BaseHTTPPeer.h.

◆ mutex_

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

Definition at line 96 of file BaseHTTPPeer.h.

◆ graceful_

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

Definition at line 97 of file BaseHTTPPeer.h.

◆ complete_

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

Definition at line 98 of file BaseHTTPPeer.h.

◆ ec_

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

Definition at line 99 of file BaseHTTPPeer.h.

◆ request_count_

template<class Handler , class Impl >
int ripple::BaseHTTPPeer< Handler, Impl >::request_count_ = 0
protected

Definition at line 101 of file BaseHTTPPeer.h.

◆ bytes_in_

template<class Handler , class Impl >
std::size_t ripple::BaseHTTPPeer< Handler, Impl >::bytes_in_ = 0
protected

Definition at line 102 of file BaseHTTPPeer.h.

◆ bytes_out_

template<class Handler , class Impl >
std::size_t ripple::BaseHTTPPeer< Handler, Impl >::bytes_out_ = 0
protected

Definition at line 103 of file BaseHTTPPeer.h.

◆ ios_

io_list* ripple::io_list::work::ios_ = nullptr
privateinherited

Definition at line 45 of file io_list.h.

◆ tag

void* ripple::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 55 of file Session.h.