21#ifndef G_NET_SOCKET_PROTOCOL_H
22#define G_NET_SOCKET_PROTOCOL_H
35 class SocketProtocol ;
36 class SocketProtocolImp ;
37 class SocketProtocolSink ;
59 G_EXCEPTION_CLASS( ReadError ,
"peer disconnected" ) ;
60 G_EXCEPTION( SendError ,
"peer disconnected" ) ;
61 G_EXCEPTION( ShutdownError ,
"shutdown error" ) ;
62 G_EXCEPTION( SecureConnectionTimeout ,
"secure connection timeout" ) ;
86 bool send(
const std::string & data , std::size_t offset = 0U ) ;
99 bool send(
const std::vector<G::string_view> & data , std::size_t offset = 0U ) ;
141 std::unique_ptr<SocketProtocolImp> m_imp ;
154 virtual void onData(
const char * , std::size_t ) = 0 ;
157 virtual void onSecure(
const std::string & peer_certificate ,
158 const std::string & protocol ,
const std::string & cipher ) = 0 ;
A base class for classes that handle asynchronous events from the event loop.
A tuple containing an ExceptionHandler interface pointer and a bound 'exception source' pointer.
An interface used by GNet::SocketProtocol to deliver data from a socket.
virtual ~SocketProtocolSink()=default
Destructor.
virtual void onSecure(const std::string &peer_certificate, const std::string &protocol, const std::string &cipher)=0
Called once the secure socket protocol has been successfully negotiated.
virtual void onData(const char *, std::size_t)=0
Called when data is read from the socket.
An interface for implementing a low-level TLS/SSL protocol layer on top of a connected non-blocking s...
bool send(const std::string &data, std::size_t offset=0U)
Sends data.
bool writeEvent()
Called on receipt of a write event.
void otherEvent(EventHandler::Reason)
Called on receipt of an 'other' event.
bool secure() const
Returns true if the connection is currently secure, ie.
static bool secureAcceptCapable()
Returns true if the implementation supports TLS/SSL and a "server" profile has been configured.
void secureAccept()
Waits for the TLS/SSL handshake protocol, acting as a server.
~SocketProtocol()
Destructor.
SocketProtocol(EventHandler &, ExceptionSink, Sink &, StreamSocket &, unsigned int secure_connection_timeout)
Constructor. The references are kept.
void shutdown()
Initiates a TLS-close if secure, together with a Socket::shutdown(1).
std::string peerCertificate() const
Returns the peer's TLS/SSL certificate or the empty string.
static bool secureConnectCapable()
Returns true if the implementation supports TLS/SSL and a "client" profile has been configured.
static void setReadBufferSize(std::size_t n)
Sets the read buffer size. Used in testing.
void readEvent()
Called on receipt of a read event.
void secureConnect()
Initiates the TLS/SSL handshake, acting as a client.
A derivation of GNet::Socket for a stream socket.