21#ifndef G_NET_SERVER_PEER_H
22#define G_NET_SERVER_PEER_H
43 class ServerPeerInfo ;
60 G_EXCEPTION( IdleTimeout ,
tx(
"idle timeout") ) ;
65 unsigned int idle_timeout {0U} ;
66 bool kick_idle_timer_on_send {
false} ;
67 bool no_throw_on_peer_disconnect {
false} ;
69 Config & set_idle_timeout(
unsigned int ) noexcept ;
70 Config & set_kick_idle_timer_on_send(
bool =
true ) noexcept ;
71 Config & set_no_throw_on_peer_disconnect(
bool =
true ) noexcept ;
72 Config & set_all_timeouts(
unsigned int ) noexcept ;
83 bool send(
const std::string & data ) ;
93 bool send(
const std::vector<G::string_view> & data , std::size_t offset = 0U ) ;
114 void doOnDelete(
const std::string & reason ,
bool done ) ;
129 virtual bool onReceive(
const char * data , std::size_t size , std::size_t eolsize , std::size_t linesize ,
char c0 ) = 0 ;
132 virtual void onDelete(
const std::string & reason ) = 0 ;
159 void expect( std::size_t ) ;
167 void readEvent()
override ;
168 void writeEvent()
override ;
169 void otherEvent( EventHandler::Reason )
override ;
170 void onPeerDisconnect()
override ;
171 std::string exceptionSourceId()
const override ;
174 void onData(
const char * , std::size_t )
override ;
185 bool send(
const char * , std::size_t offset ) = delete ;
186 bool send(
const char * ) = delete ;
187 bool send(
const std::string & , std::size_t offset ) = delete ;
190 void onIdleTimeout() ;
191 bool onDataImp(
const char * , std::size_t , std::size_t , std::size_t ,
char ) ;
196 std::unique_ptr<StreamSocket> m_socket ;
201 mutable std::string m_exception_source_id ;
204inline GNet::ServerPeer::Config & GNet::ServerPeer::Config::set_idle_timeout(
unsigned int t )
noexcept { idle_timeout = t ;
return *this ; }
205inline GNet::ServerPeer::Config & GNet::ServerPeer::Config::set_kick_idle_timer_on_send(
bool b )
noexcept { kick_idle_timer_on_send = b ;
return *this ; }
206inline 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 ; }
207inline GNet::ServerPeer::Config & GNet::ServerPeer::Config::set_socket_protocol_config(
const SocketProtocol::Config & config ) { socket_protocol_config = config ;
return *this ; }
208inline GNet::ServerPeer::Config & GNet::ServerPeer::Config::set_no_throw_on_peer_disconnect(
bool b )
noexcept { no_throw_on_peer_disconnect = 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...
A tuple containing an ExceptionHandler interface pointer and a bound 'exception source' pointer.
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.
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 data. See GNet::LineBuffer.
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 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.
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.
ServerPeer(ExceptionSink, ServerPeerInfo &&, const LineBuffer::Config &)
Constructor.
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.
A class like c++17's std::string_view.
constexpr const char * tx(const char *p)
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.