21#ifndef G_NET_SERVER_PEER_H
22#define G_NET_SERVER_PEER_H
44 class ServerPeerInfo ;
61 G_EXCEPTION( IdleTimeout ,
tx(
"idle timeout") )
66 unsigned int idle_timeout {0U} ;
67 bool kick_idle_timer_on_send {
false} ;
68 bool no_throw_on_peer_disconnect {
false} ;
69 bool log_address {
false} ;
70 bool log_port {
false} ;
72 Config & set_idle_timeout(
unsigned int ) noexcept ;
73 Config & set_kick_idle_timer_on_send(
bool =
true ) noexcept ;
74 Config & set_no_throw_on_peer_disconnect(
bool =
true ) noexcept ;
75 Config & set_all_timeouts(
unsigned int ) noexcept ;
76 Config & set_log_address(
bool =
true ) noexcept ;
77 Config & set_log_port(
bool =
true ) noexcept ;
88 bool send(
const std::string & data ) ;
95 bool send( std::string_view data ) ;
98 bool send(
const std::vector<std::string_view> & data , std::size_t offset = 0U ) ;
126 void doOnDelete(
const std::string & reason ,
bool done ) ;
138 virtual bool onReceive(
const char * data , std::size_t size , std::size_t eolsize , std::size_t linesize ,
char c0 ) = 0 ;
143 virtual void onDelete(
const std::string & reason ) = 0 ;
170 void expect( std::size_t ) ;
178 void readEvent()
override ;
179 void writeEvent()
override ;
180 void otherEvent( EventHandler::Reason )
override ;
181 void onPeerDisconnect()
override ;
185 void onData(
const char * , std::size_t )
override ;
196 bool send(
const char * , std::size_t offset ) = delete ;
197 bool send(
const char * ) = delete ;
198 bool send(
const std::string & , std::size_t offset ) = delete ;
201 void onIdleTimeout() ;
202 bool onDataImp(
const char * , std::size_t , std::size_t , std::size_t ,
char ) ;
207 std::unique_ptr<StreamSocket> m_socket ;
212 std::string m_event_logging_string ;
215inline GNet::ServerPeer::Config & GNet::ServerPeer::Config::set_idle_timeout(
unsigned int t )
noexcept { idle_timeout = t ;
return *this ; }
216inline GNet::ServerPeer::Config & GNet::ServerPeer::Config::set_kick_idle_timer_on_send(
bool b )
noexcept { kick_idle_timer_on_send = b ;
return *this ; }
217inline GNet::ServerPeer::Config & GNet::ServerPeer::Config::set_all_timeouts(
unsigned int t )
noexcept { idle_timeout = t ; socket_protocol_config.secure_connection_timeout = t ;
return *this ; }
218inline GNet::ServerPeer::Config & GNet::ServerPeer::Config::set_socket_protocol_config(
const SocketProtocol::Config & config ) { socket_protocol_config = config ;
return *this ; }
219inline GNet::ServerPeer::Config & GNet::ServerPeer::Config::set_no_throw_on_peer_disconnect(
bool b )
noexcept { no_throw_on_peer_disconnect = b ;
return *this ; }
220inline GNet::ServerPeer::Config & GNet::ServerPeer::Config::set_log_address(
bool b )
noexcept { log_address = b ;
return *this ; }
221inline GNet::ServerPeer::Config & GNet::ServerPeer::Config::set_log_port(
bool b )
noexcept { log_port = b ;
return *this ; }
The GNet::Address class encapsulates a TCP/UDP transport address.
An abstract interface which provides information about a network connection.
A base class for classes that have a file descriptor and handle asynchronous events from the event lo...
An interface for GNet classes that define a logging context string.
A lightweight object containing an ExceptionHandler pointer, optional ExceptionSource pointer and opt...
A mixin base class that identifies the source of an exception when delivered to GNet::ExceptionHandle...
Provides information about the state of a line buffer.
A class that does line buffering, supporting auto-detection of line endings and fixed-size block extr...
A move-only structure used in GNet::Server::newPeer() and containing the new socket.
An abstract base class for the GNet::Server's connection to a remote client.
void expect(std::size_t)
Modifies the line buffer state so that it delivers a chunk of non-line-delimited data.
void addReadHandler()
Re-adds the socket() read handler.
void dropReadHandler()
Drops the socket() read handler.
~ServerPeer() override
Destructor.
static std::string eventLoggingString(const Address &, const Config &)
Assembles an event logging string for a new ServerPeer object.
bool secureAcceptCapable() const
Returns true if secureAccept() is usable.
void secureAccept()
Waits for the peer to start a secure session.
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.
Address peerAddress() const override
Returns the peer address.
std::string connectionState() const override
Returns the connection state display string.
void doOnDelete(const std::string &reason, bool done)
Used by the GNet::Server class to call onDelete().
void setIdleTimeout(unsigned int seconds)
Sets the idle timeout.
Address localAddress() const override
Returns the local address.
LineBufferState lineBuffer() const
Returns information about the state of the internal line-buffer.
ServerPeer(EventState, ServerPeerInfo &&, const LineBuffer::Config &)
Constructor.
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 res...
std::string peerCertificate() const override
Returns the peer's TLS certificate.
bool send(const std::string &data)
Sends data down the socket to the peer.
StreamSocket & socket()
Returns a reference to the client-server connection socket.
virtual void onSendComplete()=0
Called after flow-control has been released and all residual data sent.
void onData(const char *, std::size_t) override
Override from GNet::SocketProtocolSink.
void finish()
Does a socket shutdown(). See also GNet::Client::finish().
An interface used by GNet::SocketProtocol to deliver data from a socket.
An interface for implementing a low-level TLS/SSL protocol layer on top of a connected non-blocking s...
A derivation of GNet::Socket for a stream socket.
A timer class template in which the timeout is delivered to the specified method.
constexpr const char * tx(const char *p) noexcept
A briefer alternative to G::gettext_noop().
A configuration structure for GNet::LineBuffer.
A configuration structure for GNet::ServerPeer.
A configuration structure for GNet::SocketProtocol.