|
E-MailRelay
|
An interface for implementing a low-level TLS/SSL protocol layer on top of a connected non-blocking socket. More...
#include <gsocketprotocol.h>
Public Types | |
| typedef SocketProtocolSink | Sink |
Public Member Functions | |
| G_EXCEPTION_CLASS (ReadError,"peer disconnected") | |
| SocketProtocol (EventHandler &, ExceptionHandler &, Sink &, StreamSocket &, unsigned int secure_connection_timeout) | |
| Constructor. The references are kept. | |
| ~SocketProtocol () | |
| Destructor. | |
| void | readEvent () |
| Called on receipt of a read event. More... | |
| bool | writeEvent () |
| Called on receipt of a write event. More... | |
| void | otherEvent (EventHandler::Reason) |
| Called on receipt of an 'other' event. More... | |
| bool | send (const std::string &data, size_t offset=0U) |
| Sends data. More... | |
| bool | send (const std::vector< std::pair< const char *, size_t > > &data) |
| Overload to send data using scatter-gather segments. More... | |
| void | secureConnect () |
| Initiates the TLS/SSL handshake, acting as a client. | |
| void | secureAccept () |
| Waits for the TLS/SSL handshake protocol, acting as a server. | |
| std::string | peerCertificate () const |
| Returns the peer's TLS/SSL certificate or the empty string. More... | |
Static Public Member Functions | |
| static bool | secureConnectCapable () |
| Returns true if the implementation supports TLS/SSL and a "client" profile has been configured. More... | |
| static bool | secureAcceptCapable () |
| Returns true if the implementation supports TLS/SSL and a "server" profile has been configured. More... | |
| static void | setReadBufferSize (size_t n) |
| Sets the read buffer size. Used in testing. | |
An interface for implementing a low-level TLS/SSL protocol layer on top of a connected non-blocking socket.
Provides send() to send data, and onData() in a callback interface to receive data. The TLS/SSL socket protocol session is negotiated with the peer by calling secureConnect() or secureAccept(), and thereafter the interface is half-duplex. If no TLS/SSL session is in effect ('raw') then the protocol layer is transparent down to the socket.
The interface has read-event and write-event handlers that should be called when events are detected on the socket file descriptor. In raw mode the read handler delivers data via the onData() callback interface and the write handler is used to flush the output pipeline.
Definition at line 53 of file gsocketprotocol.h.
| void GNet::SocketProtocol::otherEvent | ( | EventHandler::Reason | reason | ) |
Called on receipt of an 'other' event.
Throws an exception. For simple socket-close events (on Windows) the read queue is processed (see SocketProtocolSink::onData()) and the socket is shutdown() before the exception is thrown.
Definition at line 760 of file gsocketprotocol.cpp.
| std::string GNet::SocketProtocol::peerCertificate | ( | ) | const |
Returns the peer's TLS/SSL certificate or the empty string.
Definition at line 795 of file gsocketprotocol.cpp.
| void GNet::SocketProtocol::readEvent | ( | ) |
Called on receipt of a read event.
Delivers data via the sink interface. Throws ReadError on error.
Definition at line 750 of file gsocketprotocol.cpp.
|
static |
Returns true if the implementation supports TLS/SSL and a "server" profile has been configured.
See also GSsl::enabledAs().
Definition at line 785 of file gsocketprotocol.cpp.
|
static |
Returns true if the implementation supports TLS/SSL and a "client" profile has been configured.
See also GSsl::enabledAs().
Definition at line 775 of file gsocketprotocol.cpp.
| bool GNet::SocketProtocol::send | ( | const std::string & | data, |
| size_t | offset = 0U |
||
| ) |
Sends data.
Returns false if flow control asserted before all the data is sent. Returns true if all the data was sent, or if the data passed in (taking the offset into account) is empty. Throws SendError on error.
If flow control is asserted then the socket write-event handler is installed and send() returns false. Unsent portions of the data string are copied internally. When the subsequent write-event is triggered the user should call writeEvent(). There should be no new calls to send() until writeEvent() returns true.
Definition at line 765 of file gsocketprotocol.cpp.
| bool GNet::SocketProtocol::send | ( | const std::vector< std::pair< const char *, size_t > > & | data | ) |
Overload to send data using scatter-gather segments.
If false is returned then segment data pointers must stay valid until writeEvent() returns true.
Definition at line 770 of file gsocketprotocol.cpp.
| bool GNet::SocketProtocol::writeEvent | ( | ) |
Called on receipt of a write event.
Sends more pending data down the connection. Returns true if all pending data was sent. Throws SendError on error.
Definition at line 755 of file gsocketprotocol.cpp.
1.8.9.1