E-MailRelay

Classes | Public Member Functions | Static Public Member Functions | Protected Member Functions | List of all members
GNet::ServerPeer Class Referenceabstract

An abstract base class for the GNet::Server's connection to a remote client. More...

`#include <gserverpeer.h>`

Inheritance diagram for GNet::ServerPeer:
[legend]
Collaboration diagram for GNet::ServerPeer:
[legend]

## Classes
struct | Config
| A configuration structure for GNet::ServerPeer. More...

## Public Member Functions
| ServerPeer (EventState, ServerPeerInfo &&, const LineBuffer::Config &)
| Constructor. More...
| ~ServerPeer () override
| Destructor. More...
bool | send (const std::string &data)
| Sends data down the socket to the peer. More...
bool | send (std::string_view data)
| Overload for string_view. More...
bool | send (const std::vector< std::string_view > &data, std::size_t offset=0U)
| Overload to send data using scatter-gather segments. More...
Address | localAddress () const override
| Returns the local address. More...
Address | peerAddress () const override
| Returns the peer address. More...
std::string | connectionState () const override
| Returns the connection state display string. More...
std::string | peerCertificate () const override
| Returns the peer's TLS certificate. More...
LineBufferState | lineBuffer () const
| Returns information about the state of the internal line-buffer. More...
void | setIdleTimeout (unsigned int seconds)
| Sets the idle timeout. More...
void | doOnDelete (const std::string &reason, bool done)
| Used by the GNet::Server class to call onDelete(). More...
| ServerPeer (const ServerPeer &)=delete
| ServerPeer (ServerPeer &&)=delete
ServerPeer & | operator= (const ServerPeer &)=delete
ServerPeer & | operator= (ServerPeer &&)=delete
bool | send (const char *, std::size_t offset)=delete
bool | send (const char *)=delete
bool | send (const std::string &, std::size_t offset)=delete
Public Member Functions inherited from GNet::Connection
virtual | ~Connection ()=default
| Destructor.
virtual Address | localAddress () const =0
| Returns the connection's local address. More...
virtual Address | peerAddress () const =0
| Returns the connection's peer address. More...
virtual std::string | connectionState () const =0
| Returns the connection state as a display string. More...
virtual std::string | peerCertificate () const =0
| Returns the peer's TLS certificate. More...
Public Member Functions inherited from GNet::ExceptionSource
virtual | ~ExceptionSource ()
| Destructor.
| ExceptionSource (const ExceptionSource &)=delete
| ExceptionSource (ExceptionSource &&)=delete
ExceptionSource & | operator= (const ExceptionSource &)=delete
ExceptionSource & | operator= (ExceptionSource &&)=delete

## Static Public Member Functions
static std::string | eventLoggingString (const Address &, const Config &)
| Assembles an event logging string for a new ServerPeer object. More...

## Protected Member Functions
virtual void | onSendComplete ()=0
| Called after flow-control has been released and all residual data sent.
virtual bool | onReceive (const char *data, std::size_t size, std::size_t eolsize, std::size_t linesize, char c0)=0
| Called on receipt of a complete line of data. More...
virtual void | onDelete (const std::string &reason)=0
| Called just before the Server deletes this ServerPeer as the result of an exception (but not as a result of Server destruction). More...
void | secureAccept ()
| Waits for the peer to start a secure session. More...
bool | secureAcceptCapable () const
| Returns true if secureAccept() is usable. More...
StreamSocket & | socket ()
| Returns a reference to the client-server connection socket. More...
void | dropReadHandler ()
| Drops the socket() read handler. More...
void | addReadHandler ()
| Re-adds the socket() read handler. More...
void | expect (std::size_t)
| Modifies the line buffer state so that it delivers a chunk of non-line-delimited data. More...
void | finish ()
| Does a socket shutdown(). See also GNet::Client::finish(). More...
void | onData (const char *, std::size_t) override
| Override from GNet::SocketProtocolSink. More...

## Detailed Description

An abstract base class for the GNet::Server's connection to a remote client.

Instances are created on the heap by the Server::newPeer() override. Exceptions thrown from event handlers are delivered to the owning Server and result in a call to the relevant ServerPeer's onDelete() method followed by its deletion. Every ServerPeer can do line buffering, but line-buffering can be effectively disabled by configuring the line buffer as transparent.

See also
  GNet::Server, GNet::EventHandler

Definition at line 58 of file gserverpeer.h.

## Constructor & Destructor Documentation

## ◆ ServerPeer()

GNet::ServerPeer::ServerPeer | ( | EventState | es,
|  | ServerPeerInfo && | peer_info,
|  | const LineBuffer::Config & | line_buffer_config
| ) |  |

Constructor.

This constructor is only used from within the override of GNet::Server::newPeer(). The EventState exception source refers to the owning Server.

Definition at line 29 of file gserverpeer.cpp.

## ◆ ~ServerPeer()

GNet::ServerPeer::~ServerPeer | ( |  | ) |
| override

Destructor.

Definition at line 52 of file gserverpeer.cpp.

## Member Function Documentation

## ◆ addReadHandler()

void GNet::ServerPeer::addReadHandler | ( |  | ) |
| protected

Re-adds the socket() read handler.

Definition at line 99 of file gserverpeer.cpp.

## ◆ connectionState()

std::string GNet::ServerPeer::connectionState | ( |  | ) | const
| override virtual

Returns the connection state display string.

Override from GNet::Connection.

Implements GNet::Connection.

Definition at line 126 of file gserverpeer.cpp.

## ◆ doOnDelete()

void GNet::ServerPeer::doOnDelete | ( | const std::string & | reason,
|  | bool | done
| ) |  |

Used by the GNet::Server class to call onDelete().

Definition at line 165 of file gserverpeer.cpp.

## ◆ dropReadHandler()

void GNet::ServerPeer::dropReadHandler | ( |  | ) |
| protected

Drops the socket() read handler.

Definition at line 94 of file gserverpeer.cpp.

## ◆ eventLoggingString()

std::string GNet::ServerPeer::eventLoggingString | ( | const Address & | a,
|  | const Config & | config
| ) |  |
| static

Assembles an event logging string for a new ServerPeer object.

Definition at line 58 of file gserverpeer.cpp.

## ◆ expect()

void GNet::ServerPeer::expect | ( | std::size_t | n | ) |
| protected

Modifies the line buffer state so that it delivers a chunk of non-line-delimited data.

Definition at line 82 of file gserverpeer.cpp.

## ◆ finish()

void GNet::ServerPeer::finish | ( |  | ) |
| protected

Does a socket shutdown(). See also GNet::Client::finish().

Definition at line 213 of file gserverpeer.cpp.

## ◆ lineBuffer()

GNet::LineBufferState GNet::ServerPeer::lineBuffer | ( |  | ) | const

Returns information about the state of the internal line-buffer.

Definition at line 193 of file gserverpeer.cpp.

## ◆ localAddress()

GNet::Address GNet::ServerPeer::localAddress | ( |  | ) | const
| override virtual

Returns the local address.

Throws on error. Override from GNet::Connection.

Implements GNet::Connection.

Definition at line 115 of file gserverpeer.cpp.

## ◆ onData()

void GNet::ServerPeer::onData | ( | const char * | data,
|  | std::size_t | size
| ) |  |
| override protected virtual

Override from GNet::SocketProtocolSink.

Protected and non-final to allow derived classes to ignore incoming data for DoS prevention.

Implements GNet::SocketProtocolSink.

Definition at line 178 of file gserverpeer.cpp.

## ◆ onDelete()

virtual void GNet::ServerPeer::onDelete | ( | const std::string & | reason | ) |
| protected pure virtual

Called just before the Server deletes this ServerPeer as the result of an exception (but not as a result of Server destruction).

The reason is the empty string if caused by a GNet::Done exception. Consider making the implementation non-throwing, in the spirit of a destructor, since the ServerPeer object is about to be deleted.

## ◆ onReceive()

virtual bool GNet::ServerPeer::onReceive | ( | const char * | data,
|  | std::size_t | size,
|  | std::size_t | eolsize,
|  | std::size_t | linesize,
|  | char | c0
| ) |  |
| protected pure virtual

Called on receipt of a complete line of data.

This method is the sink function for the internal GNet::LineBuffer. See GNet::LineBuffer::apply().

## ◆ peerAddress()

GNet::Address GNet::ServerPeer::peerAddress | ( |  | ) | const
| override virtual

Returns the peer address.

Throws on error. Override from GNet::Connection.

Implements GNet::Connection.

Definition at line 121 of file gserverpeer.cpp.

## ◆ peerCertificate()

std::string GNet::ServerPeer::peerCertificate | ( |  | ) | const
| override virtual

Returns the peer's TLS certificate.

Override from GNet::Connection.

Implements GNet::Connection.

Definition at line 131 of file gserverpeer.cpp.

## ◆ secureAccept()

void GNet::ServerPeer::secureAccept | ( |  | ) |
| protected

Waits for the peer to start a secure session.

Uses a profile called "server" by default; see GSsl::Library::addProfile(). The callback GNet::SocketProtocolSink::onSecure() is triggered when the secure session is established.

Definition at line 71 of file gserverpeer.cpp.

## ◆ secureAcceptCapable()

bool GNet::ServerPeer::secureAcceptCapable | ( |  | ) | const
| protected

Returns true if secureAccept() is usable.

Definition at line 76 of file gserverpeer.cpp.

## ◆ send() [1/3]

bool GNet::ServerPeer::send | ( | const std::string & | data | ) |

Sends data down the socket to the peer.

Returns true if completely sent; returns false if flow control asserted (see onSendComplete()). If flow control is asserted then there should be no new calls to send() until onSendComplete() is triggered. Throws on error.

Definition at line 136 of file gserverpeer.cpp.

## ◆ send() [2/3]

bool GNet::ServerPeer::send | ( | const std::vector< std::string_view > & | data,
|  | std::size_t | offset = `0U`
| ) |  |

Overload to send data using scatter-gather segments.

If false is returned then segment data pointers must stay valid until onSendComplete() is triggered.

Definition at line 151 of file gserverpeer.cpp.

## ◆ send() [3/3]

bool GNet::ServerPeer::send | ( | std::string_view | data | ) |

Overload for string_view.

Definition at line 143 of file gserverpeer.cpp.

## ◆ setIdleTimeout()

void GNet::ServerPeer::setIdleTimeout | ( | unsigned int | seconds | ) |

Sets the idle timeout.

Definition at line 204 of file gserverpeer.cpp.

## ◆ socket()

GNet::StreamSocket & GNet::ServerPeer::socket | ( |  | ) |
| protected

Returns a reference to the client-server connection socket.

Definition at line 88 of file gserverpeer.cpp.

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

- /tmp/slackdce/slackrepo.HKsbdz/build_emailrelay/emailrelay-2.6/src/gnet/gserverpeer.h
- /tmp/slackdce/slackrepo.HKsbdz/build_emailrelay/emailrelay-2.6/src/gnet/gserverpeer.cpp