- Main Page
- Namespaces
- Classes
- Files

- Class List
- Class Hierarchy
- Class Members

Public Types | Public Member Functions | Static Public Member Functions | List of all members
GNet::SocketProtocol Class Reference

An interface for implementing a low-level protocol layer by means of calling read() and write() on a connected non-blocking socket and installing and removing event handlers as appropriate. More...

`#include <gsocketprotocol.h>`

## Public Types
typedef SocketProtocolSink | Sink

## Public Member Functions
| SocketProtocol (EventHandler &, Sink &, StreamSocket &, unsigned int secure_connection_timeout)
| Constructor. The references are kept. More...
| ~SocketProtocol ()
| Destructor. More...
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, std::string::size_type offset=0U)
| Sends data. More...
void | sslConnect ()
| Initiates the TLS/SSL protocol. More...
void | sslAccept ()
| Accepts the TLS/SSL protocol. More...
bool | sslEnabled () const
| Returns true if TLS/SSL is active. More...
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. More...

## Detailed Description

An interface for implementing a low-level protocol layer by means of calling read() and write() on a connected non-blocking socket and installing and removing event handlers as appropriate.

In practice the only supported protocol is TLS/SSL and the implementation delegates to GSsl::Protocol.

Provides send() to send data and onData() in a sink callback interface to receive data.

A TLS/SSL session can be established with sslConnect() or sslAccept() as long as the underlying GSsl::Protocol is sslCapable(). If no TLS/SSL session is in effect then the protocol layer is transparent down to the socket.

Definition at line 54 of file gsocketprotocol.h.

## Member Typedef Documentation

typedef SocketProtocolSink GNet::SocketProtocol::Sink

Definition at line 57 of file gsocketprotocol.h.

## Constructor & Destructor Documentation

GNet::SocketProtocol::SocketProtocol | ( | EventHandler & | handler,
|  | Sink & | sink,
|  | StreamSocket & | socket,
|  | unsigned int | secure_connection_timeout
| ) |  |

Constructor. The references are kept.

Definition at line 517 of file gsocketprotocol.cpp.

GNet::SocketProtocol::~SocketProtocol | ( |  | ) |

Destructor.

Definition at line 523 of file gsocketprotocol.cpp.

## Member Function Documentation

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

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

Definition at line 563 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 528 of file gsocketprotocol.cpp.

bool GNet::SocketProtocol::send | ( | const std::string & | data,
|  | std::string::size_type | offset = `0U`
| ) |  |

Sends data.

Returns false if flow control asserted. Returns true if the data passed in (taking the offset into account) is empty. Throws SendError on error.

Definition at line 538 of file gsocketprotocol.cpp.

void GNet::SocketProtocol::sslAccept | ( |  | ) |

Accepts the TLS/SSL protocol.

Definition at line 553 of file gsocketprotocol.cpp.

bool GNet::SocketProtocol::sslCapable | ( |  | ) |
| static

Returns true if the implementation supports TLS/SSL.

Definition at line 543 of file gsocketprotocol.cpp.

References GSsl::Library::enabled(), and GSsl::Library::instance().

void GNet::SocketProtocol::sslConnect | ( |  | ) |

Initiates the TLS/SSL protocol.

Definition at line 548 of file gsocketprotocol.cpp.

bool GNet::SocketProtocol::sslEnabled | ( |  | ) | const

Returns true if TLS/SSL is active.

Definition at line 558 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 533 of file gsocketprotocol.cpp.

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

- gsocketprotocol.h
- gsocketprotocol.cpp