SWC-DB  v0.5.12 C++ documentations
SWC-DB© (Super Wide Column Database) - High Performance Scalable Database (https://github.com/kashirin-alex/swc-db)
SWC::Comm::ConnHandler Class Referenceabstract

#include <swcdb/core/comm/ConnHandler.h>

+ Inheritance diagram for SWC::Comm::ConnHandler:
+ Collaboration diagram for SWC::Comm::ConnHandler:

Classes

struct  Outgoing
 
struct  Pending
 
struct  PendingHash
 
struct  Receiver_Buffer
 
struct  Receiver_Header
 
struct  Receiver_HeaderPrefix
 
struct  Sender_Ack
 
struct  Sender_noAck
 

Public Member Functions

 ConnHandler (const ConnHandler &)=delete
 
 ConnHandler (ConnHandler &&)=delete
 
ConnHandleroperator= (const ConnHandler &)=delete
 
ConnHandleroperator= (ConnHandler &&)=delete
 
SWC_CAN_INLINE size_t endpoint_remote_hash () const noexcept
 
SWC_CAN_INLINE size_t endpoint_local_hash () const noexcept
 
SWC_CAN_INLINE Core::Encoder::Type get_encoder () const noexcept
 
virtual bool is_secure () const noexcept
 
void new_connection ()
 
virtual bool is_open () const noexcept=0
 
size_t pending_read () noexcept
 
SWC_CAN_INLINE bool due ()
 
virtual void do_close () noexcept=0
 
bool send_error (int error, const std::string &msg, const Event::Ptr &ev) noexcept
 
bool response_ok (const Event::Ptr &ev) noexcept
 
bool send_response (Buffers::Ptr cbuf, DispatchHandler::Ptr hdlr=nullptr) noexcept
 
bool send_request (Buffers::Ptr cbuf, DispatchHandler::Ptr hdlr)
 
void print (std::ostream &out) const
 

Public Attributes

Core::AtomicBool connected
 
const AppContext::Ptr app_ctx
 
EndPoint endpoint_remote
 
EndPoint endpoint_local
 

Protected Member Functions

SWC_CAN_INLINE ConnHandler (AppContext::Ptr &a_app_ctx) noexcept
 
SWC_CAN_INLINE ConnHandlerPtr ptr () noexcept
 
virtual ~ConnHandler () noexcept
 
virtual SocketLayersocket_layer () noexcept=0
 
virtual void read (uint8_t **bufp, size_t *remainp, asio::error_code &ec)=0
 
virtual void do_async_write (Core::Vector< asio::const_buffer > &&buffers, Sender_noAck &&hdlr) noexcept=0
 
virtual void do_async_write (Core::Vector< asio::const_buffer > &&buffers, Sender_Ack &&hdlr) noexcept=0
 
virtual void do_async_read (uint8_t *data, uint32_t sz, Receiver_HeaderPrefix &&hdlr) noexcept=0
 
virtual void do_async_read (uint8_t *data, uint32_t sz, Receiver_Header &&hdlr) noexcept=0
 
virtual void do_async_read (uint8_t *data, uint32_t sz, Receiver_Buffer &&hdlr) noexcept=0
 
void do_close_run () noexcept
 
void disconnected () noexcept
 

Protected Attributes

Core::MutexSptd m_mutex
 

Private Member Functions

void write_or_queue (Outgoing &&outgoing)
 
void write_next ()
 
void write (Outgoing &outgoing)
 
void read () noexcept
 
void recv_buffers (Event::Ptr &&ev)
 
void received (Event::Ptr &&ev) noexcept
 
SWC_CAN_INLINE void do_close_recv () noexcept
 
void run_pending (Event::Ptr &&ev)
 

Private Attributes

uint32_t m_next_req_id
 
Core::QueueSafeStated< Outgoingm_outgoing
 
std::unordered_map< uint32_t, Pending, PendingHashm_pending
 
size_t m_recv_bytes
 
uint8_t _buf_header [Header::MAX_LENGTH]
 

Detailed Description

Definition at line 29 of file ConnHandler.h.

Constructor & Destructor Documentation

◆ ConnHandler() [1/3]

SWC::Comm::ConnHandler::ConnHandler ( const ConnHandler )
delete

◆ ConnHandler() [2/3]

SWC::Comm::ConnHandler::ConnHandler ( ConnHandler &&  )
delete

◆ ConnHandler() [3/3]

SWC_CAN_INLINE SWC::Comm::ConnHandler::ConnHandler ( AppContext::Ptr a_app_ctx)
inlineprotectednoexcept

Definition at line 162 of file ConnHandler.h.

◆ ~ConnHandler()

virtual SWC::Comm::ConnHandler::~ConnHandler ( )
inlineprotectedvirtualnoexcept

Definition at line 174 of file ConnHandler.h.

Member Function Documentation

◆ disconnected()

void SWC::Comm::ConnHandler::disconnected ( )
protectednoexcept

Definition at line 459 of file ConnHandler.cc.

References SWC::LOG_ERROR, m_mutex, m_outgoing, m_pending, print(), SWC_CURRENT_EXCEPTION, SWC_LOG_OSTREAM, and SWC_LOG_OUT.

Referenced by SWC::Comm::ConnHandlerPlain::do_close(), and SWC::Comm::ConnHandlerSSL::do_close().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ do_async_read() [1/3]

virtual void SWC::Comm::ConnHandler::do_async_read ( uint8_t *  data,
uint32_t  sz,
Receiver_Buffer &&  hdlr 
)
protectedpure virtualnoexcept

◆ do_async_read() [2/3]

virtual void SWC::Comm::ConnHandler::do_async_read ( uint8_t *  data,
uint32_t  sz,
Receiver_Header &&  hdlr 
)
protectedpure virtualnoexcept

◆ do_async_read() [3/3]

virtual void SWC::Comm::ConnHandler::do_async_read ( uint8_t *  data,
uint32_t  sz,
Receiver_HeaderPrefix &&  hdlr 
)
protectedpure virtualnoexcept

Implemented in SWC::Comm::ConnHandlerSSL, and SWC::Comm::ConnHandlerPlain.

Referenced by read(), and recv_buffers().

+ Here is the caller graph for this function:

◆ do_async_write() [1/2]

virtual void SWC::Comm::ConnHandler::do_async_write ( Core::Vector< asio::const_buffer > &&  buffers,
Sender_Ack &&  hdlr 
)
protectedpure virtualnoexcept

◆ do_async_write() [2/2]

virtual void SWC::Comm::ConnHandler::do_async_write ( Core::Vector< asio::const_buffer > &&  buffers,
Sender_noAck &&  hdlr 
)
protectedpure virtualnoexcept

Implemented in SWC::Comm::ConnHandlerSSL, and SWC::Comm::ConnHandlerPlain.

Referenced by write().

+ Here is the caller graph for this function:

◆ do_close()

virtual void SWC::Comm::ConnHandler::do_close ( )
pure virtualnoexcept

Implemented in SWC::Comm::ConnHandlerSSL, and SWC::Comm::ConnHandlerPlain.

Referenced by do_close_recv(), and write().

+ Here is the caller graph for this function:

◆ do_close_recv()

SWC_CAN_INLINE void SWC::Comm::ConnHandler::do_close_recv ( )
inlineprivatenoexcept

Definition at line 225 of file ConnHandler.h.

References app_ctx, do_close(), m_recv_bytes, and ptr().

+ Here is the call graph for this function:

◆ do_close_run()

void SWC::Comm::ConnHandler::do_close_run ( )
protectednoexcept

Definition at line 32 of file ConnHandler.cc.

References app_ctx, and ptr().

Referenced by SWC::Comm::ConnHandlerPlain::do_close(), and SWC::Comm::ConnHandlerSSL::do_close().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ due()

SWC_CAN_INLINE bool SWC::Comm::ConnHandler::due ( )
inline

Definition at line 141 of file ConnHandler.h.

References m_outgoing, and pending_read().

+ Here is the call graph for this function:

◆ endpoint_local_hash()

SWC_CAN_INLINE size_t SWC::Comm::ConnHandler::endpoint_local_hash ( ) const
inlinenoexcept

Definition at line 120 of file ConnHandler.h.

References SWC::Comm::endpoint_hash(), and endpoint_local.

+ Here is the call graph for this function:

◆ endpoint_remote_hash()

SWC_CAN_INLINE size_t SWC::Comm::ConnHandler::endpoint_remote_hash ( ) const
inlinenoexcept

Definition at line 115 of file ConnHandler.h.

References SWC::Comm::endpoint_hash(), and endpoint_remote.

+ Here is the call graph for this function:

◆ get_encoder()

SWC_CAN_INLINE Core::Encoder::Type SWC::Comm::ConnHandler::get_encoder ( ) const
inlinenoexcept

Definition at line 125 of file ConnHandler.h.

References app_ctx, endpoint_local, and endpoint_remote.

Referenced by print(), and write_or_queue().

+ Here is the caller graph for this function:

◆ is_open()

virtual bool SWC::Comm::ConnHandler::is_open ( ) const
pure virtualnoexcept

Implemented in SWC::Comm::ConnHandlerSSL, and SWC::Comm::ConnHandlerPlain.

Referenced by print().

+ Here is the caller graph for this function:

◆ is_secure()

virtual bool SWC::Comm::ConnHandler::is_secure ( ) const
inlinevirtualnoexcept

Reimplemented in SWC::Comm::ConnHandlerSSL.

Definition at line 132 of file ConnHandler.h.

Referenced by print().

+ Here is the caller graph for this function:

◆ new_connection()

void SWC::Comm::ConnHandler::new_connection ( )

Definition at line 16 of file ConnHandler.cc.

References app_ctx, endpoint_local, endpoint_remote, SWC::LOG_DEBUG, print(), ptr(), read(), socket_layer(), SWC_LOG_OSTREAM, and SWC_LOG_OUT.

+ Here is the call graph for this function:

◆ operator=() [1/2]

ConnHandler& SWC::Comm::ConnHandler::operator= ( ConnHandler &&  )
delete

◆ operator=() [2/2]

ConnHandler& SWC::Comm::ConnHandler::operator= ( const ConnHandler )
delete

Referenced by run_pending(), and write().

+ Here is the caller graph for this function:

◆ pending_read()

size_t SWC::Comm::ConnHandler::pending_read ( )
noexcept

Definition at line 27 of file ConnHandler.cc.

References m_mutex, and m_pending.

Referenced by due().

+ Here is the caller graph for this function:

◆ print()

void SWC::Comm::ConnHandler::print ( std::ostream &  out) const

Definition at line 69 of file ConnHandler.cc.

References endpoint_local, endpoint_remote, get_encoder(), is_open(), is_secure(), and SWC::Core::Encoder::to_string().

Referenced by disconnected(), and new_connection().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ ptr()

SWC_CAN_INLINE ConnHandlerPtr SWC::Comm::ConnHandler::ptr ( )
inlineprotectednoexcept

Definition at line 170 of file ConnHandler.h.

Referenced by do_close_recv(), do_close_run(), new_connection(), read(), recv_buffers(), run_pending(), and write().

+ Here is the caller graph for this function:

◆ read() [1/2]

void SWC::Comm::ConnHandler::read ( )
privatenoexcept

Definition at line 411 of file ConnHandler.cc.

References _buf_header, connected, do_async_read(), m_recv_bytes, SWC::Comm::Header::PREFIX_LENGTH, and ptr().

Referenced by new_connection(), SWC::Comm::ConnHandlerPlain::read(), and SWC::Comm::ConnHandlerSSL::read().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ read() [2/2]

virtual void SWC::Comm::ConnHandler::read ( uint8_t **  bufp,
size_t *  remainp,
asio::error_code &  ec 
)
protectedpure virtual

◆ received()

void SWC::Comm::ConnHandler::received ( Event::Ptr &&  ev)
privatenoexcept

Definition at line 438 of file ConnHandler.cc.

References SWC::Comm::Header::FLAG_REQUEST_BIT, SWC::LOG_ERROR, SWC::Comm::print(), SWC::Common::Files::RgrData::read(), SWC_CURRENT_EXCEPTION, SWC_LOG_OSTREAM, and SWC_LOG_OUT.

+ Here is the call graph for this function:

◆ recv_buffers()

void SWC::Comm::ConnHandler::recv_buffers ( Event::Ptr &&  ev)
private

Definition at line 421 of file ConnHandler.cc.

References SWC::Core::Buffer< T >::base, do_async_read(), ptr(), SWC::Core::Buffer< T >::reallocate(), and SWC::Core::Buffer< T >::size.

+ Here is the call graph for this function:

◆ response_ok()

bool SWC::Comm::ConnHandler::response_ok ( const Event::Ptr ev)
noexcept

Definition at line 45 of file ConnHandler.cc.

References SWC::Comm::Buffers::make(), and SWC::Error::OK.

+ Here is the call graph for this function:

◆ run_pending()

void SWC::Comm::ConnHandler::run_pending ( Event::Ptr &&  ev)
private

Definition at line 489 of file ConnHandler.cc.

References app_ctx, SWC::Comm::Header::FLAG_REQUEST_BIT, SWC::Comm::Header::FLAG_RESPONSE_PARTIAL_BIT, SWC::Comm::ConnHandler::Pending::hdlr, m_mutex, m_pending, operator=(), ptr(), socket_layer(), SWC_CAN_INLINE, and SWC::Comm::ConnHandler::Pending::timer.

+ Here is the call graph for this function:

◆ send_error()

bool SWC::Comm::ConnHandler::send_error ( int  error,
const std::string &  msg,
const Event::Ptr ev 
)
noexcept

Definition at line 36 of file ConnHandler.cc.

References SWC::Comm::Buffers::create_error_message().

+ Here is the call graph for this function:

◆ send_request()

bool SWC::Comm::ConnHandler::send_request ( Buffers::Ptr  cbuf,
DispatchHandler::Ptr  hdlr 
)

Definition at line 60 of file ConnHandler.cc.

References connected, SWC::Comm::Header::FLAG_REQUEST_BIT, and write_or_queue().

+ Here is the call graph for this function:

◆ send_response()

bool SWC::Comm::ConnHandler::send_response ( Buffers::Ptr  cbuf,
DispatchHandler::Ptr  hdlr = nullptr 
)
noexcept

Definition at line 51 of file ConnHandler.cc.

References SWC::Comm::Header::FLAG_REQUEST_MASK.

◆ socket_layer()

virtual SocketLayer* SWC::Comm::ConnHandler::socket_layer ( )
protectedpure virtualnoexcept

Implemented in SWC::Comm::ConnHandlerSSL, and SWC::Comm::ConnHandlerPlain.

Referenced by new_connection(), run_pending(), and write().

+ Here is the caller graph for this function:

◆ write()

void SWC::Comm::ConnHandler::write ( ConnHandler::Outgoing outgoing)
private

Definition at line 162 of file ConnHandler.cc.

References SWC::Comm::Protocol::Rgr::Handler::assign_id(), SWC::Comm::ConnHandler::Outgoing::cbuf, connected, do_async_write(), do_close(), SWC::Comm::Header::FLAG_REQUEST_BIT, SWC::Comm::Header::FLAG_REQUEST_MASK, SWC::Comm::Header::FLAG_RESPONSE_IGNORE_BIT, SWC::Comm::ConnHandler::Outgoing::hdlr, m_mutex, m_next_req_id, m_pending, SWC::Comm::Event::make(), operator=(), ptr(), SWC::Error::REQUEST_TIMEOUT, socket_layer(), SWC_CAN_INLINE, and write_next().

Referenced by write_next(), and write_or_queue().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ write_next()

void SWC::Comm::ConnHandler::write_next ( )
private

Definition at line 86 of file ConnHandler.cc.

References m_outgoing, and write().

Referenced by write().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ write_or_queue()

void SWC::Comm::ConnHandler::write_or_queue ( ConnHandler::Outgoing &&  outgoing)
private

Definition at line 79 of file ConnHandler.cc.

References get_encoder(), m_outgoing, and write().

Referenced by send_request().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Member Data Documentation

◆ _buf_header

uint8_t SWC::Comm::ConnHandler::_buf_header[Header::MAX_LENGTH]
private

Definition at line 246 of file ConnHandler.h.

Referenced by read().

◆ app_ctx

◆ connected

◆ endpoint_local

EndPoint SWC::Comm::ConnHandler::endpoint_local

Definition at line 112 of file ConnHandler.h.

Referenced by endpoint_local_hash(), get_encoder(), new_connection(), and print().

◆ endpoint_remote

EndPoint SWC::Comm::ConnHandler::endpoint_remote

Definition at line 111 of file ConnHandler.h.

Referenced by endpoint_remote_hash(), get_encoder(), new_connection(), and print().

◆ m_mutex

Core::MutexSptd SWC::Comm::ConnHandler::m_mutex
protected

Definition at line 208 of file ConnHandler.h.

Referenced by disconnected(), pending_read(), run_pending(), and write().

◆ m_next_req_id

uint32_t SWC::Comm::ConnHandler::m_next_req_id
private

Definition at line 240 of file ConnHandler.h.

Referenced by write().

◆ m_outgoing

Core::QueueSafeStated<Outgoing> SWC::Comm::ConnHandler::m_outgoing
private

Definition at line 241 of file ConnHandler.h.

Referenced by disconnected(), due(), write_next(), and write_or_queue().

◆ m_pending

std::unordered_map<uint32_t, Pending, PendingHash> SWC::Comm::ConnHandler::m_pending
private

Definition at line 244 of file ConnHandler.h.

Referenced by disconnected(), pending_read(), run_pending(), and write().

◆ m_recv_bytes

size_t SWC::Comm::ConnHandler::m_recv_bytes
private

Definition at line 245 of file ConnHandler.h.

Referenced by do_close_recv(), and read().


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