VideoTools
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
GNet::SocketProtocol Class Reference

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 &, 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...
 
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 sslConnect ()
 Initiates the TLS/SSL protocol.
 
void sslAccept ()
 Accepts the TLS/SSL protocol.
 
bool sslEnabled () const
 Returns true if TLS/SSL is active.
 
std::string peerCertificate () const
 Returns the peer's TLS/SSL certificate or the empty string. More...
 

Static Public Member Functions

static bool sslCapable ()
 Returns true if the implementation supports TLS/SSL.
 

Detailed Description

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 sslConnect() or sslAccept(), 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. The read handler delivers data via the onData() callback interface; the write handler is used to flush the output pipeline.

Definition at line 54 of file gsocketprotocol.h.

Member Function Documentation

std::string GNet::SocketProtocol::peerCertificate ( ) const

Returns the peer's TLS/SSL certificate or the empty string.

Definition at line 699 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 659 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; 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 669 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 674 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 664 of file gsocketprotocol.cpp.


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