11#error "asio.hpp must be included before including this, see asiolink.h as to why" 
   18#include <boost/noncopyable.hpp> 
   28class TLSSocket : 
public IOAsioSocket<C>, 
private boost::noncopyable {
 
   53        return (socket_.native_handle());
 
 
   78        if (socket_.is_open()) {
 
   80            const bool non_blocking_orig = socket_.non_blocking();
 
   85            socket_.non_blocking(
true);
 
  101            socket_.non_blocking(non_blocking_orig);
 
  110            return ((err == 0) || (err == EAGAIN) || (err == EWOULDBLOCK));
 
 
  161    void asyncSend(
const void* 
data, 
size_t length, C& callback);
 
  193                                     size_t& cumulative, 
size_t& offset,
 
  232    std::unique_ptr<TlsStream<C>> stream_ptr_;
 
  235    TlsStream<C>& stream_;
 
  238    typename TlsStream<C>::lowest_layer_type& socket_;
 
  262    stream_ptr_(), stream_(stream),
 
  263    socket_(stream_.lowest_layer()), send_buffer_() {
 
 
  270    : io_service_(io_service),
 
  271      stream_ptr_(new TlsStream<C>(io_service, context)),
 
  272      stream_(*stream_ptr_), socket_(stream_.lowest_layer()), send_buffer_() {
 
 
  284template <
typename C> 
void 
  289    if (!socket_.is_open()) {
 
  291            socket_.open(boost::asio::ip::tcp::v4());
 
  293            socket_.open(boost::asio::ip::tcp::v6());
 
  300        socket_.set_option(boost::asio::socket_base::reuse_address(
true));
 
 
  319template <
typename C> 
void 
  321    if (!socket_.is_open()) {
 
  323                  "a TLS socket that is not open");
 
  325    stream_.handshake(callback);
 
 
  331template <
typename C> 
void 
  333    if (!socket_.is_open()) {
 
  335                  "attempt to send on a TLS socket that is not open");
 
  340        send_buffer_->writeData(
data, length);
 
  343        boost::asio::async_write(stream_,
 
  344                                 boost::asio::buffer(send_buffer_->getData(),
 
  345                                                     send_buffer_->getLength()),
 
  347    } 
catch (
const boost::numeric::bad_numeric_cast&) {
 
  349                  "attempt to send buffer larger than 64kB");
 
 
  353template <
typename C> 
void 
  356    if (!socket_.is_open()) {
 
  358                  "attempt to send on a TLS socket that is not open");
 
  366        uint16_t count = boost::numeric_cast<uint16_t>(length);
 
  370        send_buffer_->writeUint16(count);
 
  371        send_buffer_->writeData(
data, length);
 
  374        boost::asio::async_write(stream_,
 
  375                                 boost::asio::buffer(send_buffer_->getData(),
 
  376                                                     send_buffer_->getLength()),
 
  378    } 
catch (
const boost::numeric::bad_numeric_cast&) {
 
  380                  "attempt to send buffer larger than 64kB");
 
 
  387template <
typename C> 
void 
  390    if (!socket_.is_open()) {
 
  392                  "attempt to receive from a TLS socket that is not open");
 
  413    if (offset >= length) {
 
  415                  "TCP receive buffer");
 
  418        static_cast<void*
>(
static_cast<uint8_t*
>(
data) + offset);
 
  421    stream_.async_read_some(boost::asio::buffer(buffer_start, length - offset),
 
 
  427template <
typename C> 
bool 
  429                                  size_t& cumulative, 
size_t& offset,
 
  433    const uint8_t* 
data = 
static_cast<const uint8_t*
>(staging);
 
  434    size_t data_length = length;
 
  438    if (cumulative < 2) {
 
  442        cumulative += length;
 
  443        if (cumulative < 2) {
 
  462        data_length = cumulative - 2;
 
  466        cumulative += length;
 
  476    if (expected >= outbuff->getLength()) {
 
  480        size_t copy_amount = std::min(expected - outbuff->getLength(),
 
  482        outbuff->writeData(
data, copy_amount);
 
  486    return (expected == outbuff->getLength());
 
 
  491template <
typename C> 
void 
  493    if (socket_.is_open()) {
 
 
  500template <
typename C> 
void 
  502    if (!socket_.is_open()) {
 
  504                  "a TLS socket that is not open");
 
  506    stream_.shutdown(callback);
 
 
 
  512template <
typename C> 
void 
  514    if (socket_.is_open() && stream_ptr_) {
 
 
 
 
 
 
 
 
 
 
 
 
The IOEndpoint class is an abstract base class to represent a communication endpoint.
virtual short getFamily() const =0
Returns the address family of the endpoint.
virtual short getProtocol() const =0
Returns the protocol number of the endpoint (TCP, UDP...)
The TCPEndpoint class is a concrete derived class of IOEndpoint that represents an endpoint of a TCP ...
const boost::asio::ip::tcp::endpoint & getASIOEndpoint() const
virtual void asyncReceive(void *data, size_t length, size_t offset, IOEndpoint *endpoint, C &callback)
Receive Asynchronously.
virtual TlsStream< C >::lowest_layer_type & getASIOSocket() const
Returns reference to the underlying ASIO socket.
bool isUsable() const
Checks if the connection is usable.
virtual bool isOpenSynchronous() const
Is "open()" synchronous predicate.
virtual TlsStream< C > & getTlsStream() const
Returns reference to the underlying TLS stream.
virtual void asyncSend(const void *data, size_t length, const IOEndpoint *endpoint, C &callback)
Send Asynchronously.
virtual void handshake(C &callback)
Perform Handshake.
virtual ~TLSSocket()
Destructor.
virtual int getProtocol() const
Return protocol of socket.
virtual bool processReceivedData(const void *staging, size_t length, size_t &cumulative, size_t &offset, size_t &expected, isc::util::OutputBufferPtr &outbuff)
Process received data packet.
virtual void shutdown(C &callback)
TLS shutdown.
virtual void cancel()
Cancel I/O On Socket.
virtual void open(const IOEndpoint *endpoint, C &callback)
Open Socket.
TLSSocket(TlsStream< C > &stream)
Constructor from a TLS stream.
virtual void close()
Close socket.
virtual int getNative() const
Return file descriptor of underlying socket.
The OutputBuffer class is a buffer abstraction for manipulating mutable data.
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
#define isc_throw_assert(expr)
Replacement for assert() that throws if the expression is false.
boost::shared_ptr< TlsContext > TlsContextPtr
The type of shared pointers to TlsContext objects.
boost::shared_ptr< IOService > IOServicePtr
Defines a smart pointer to an IOService instance.
uint16_t readUint16(void const *const buffer, size_t const length)
uint16_t wrapper over readUint.
boost::shared_ptr< OutputBuffer > OutputBufferPtr
Type of pointers to output buffers.
Defines the logger used by the top-level component of kea-lfc.