MeVisLab Toolbox Reference
asio::TlsSocket Class Reference

A TCP socket class with TLS support implementing the asio::Socket interface. More...

#include <TlsSocket.h>

Inheritance diagram for asio::TlsSocket:
asio::TcpSocket asio::Socket

Public Types

using HandshakeCompletionHandler = std::function< void(const ErrorCode &)>
 
- Public Types inherited from asio::Socket
using CompletionHandler = std::function< void(const ErrorCode &, const std::size_t)>
 

Public Member Functions

 TlsSocket (std::shared_ptr< Context > io_context, std::shared_ptr< TlsContext > tls_context)
 
 ~TlsSocket () override
 
void async_handshake (TlsStream::handshake_type handshake_type, const HandshakeCompletionHandler &handler)
 
bool is_valid () const override
 
void async_read (void *buffer, const std::size_t buffer_size, const CompletionHandler &handler) override
 
void async_write (const void *buffer, const std::size_t buffer_size, const CompletionHandler &handler) override
 
void close () override
 
- Public Member Functions inherited from asio::TcpSocket
 TcpSocket (std::shared_ptr< Context > context)
 
 ~TcpSocket () override
 
template<typename ConnectCompletionHandler >
void async_connect (const std::string &host, const unsigned short port, ConnectCompletionHandler &&handler)
 
bool is_open () const
 
 TcpSocket (const TcpSocket &)=delete
 
TcpSocketoperator= (const TcpSocket &)=delete
 
- Public Member Functions inherited from asio::Socket
virtual ~Socket ()=default
 

Additional Inherited Members

- Protected Attributes inherited from asio::TcpSocket
std::shared_ptr< Contextcontext
 
boost::asio::ip::tcp::socket socket
 

Detailed Description

A TCP socket class with TLS support implementing the asio::Socket interface.

Synopsis:

auto context = std::make_shared<asio::Context>();
auto tls_context = std::make_shared<asio::TlsContext>(asio::TlsContext::tlsv12_client);
asio::TlsSocket socket{ context, tls_context };
socket.async_connect("127.0.0.1", 443, [&socket] (const asio::ErrorCode& connectEC) {
if (!connectEC) {
// connection established, handshake...
socket.async_handshake(asio::TlsStream::client, [&errorCode](const asio::ErrorCode& handshakeEC) {
if (!handshakeEC) {
// handshake successfull, socket ready for encrypted I/O.
}
});
}
});
context->run(); // this blocks (as usual) and normally done somewhere else.
std::shared_ptr< Context > context
Definition: TcpSocket.h:95
boost::asio::ip::tcp::socket socket
Definition: TcpSocket.h:97
A TCP socket class with TLS support implementing the asio::Socket interface.
Definition: TlsSocket.h:44
boost::system::error_code ErrorCode
Definition: ErrorCodes.h:13

Definition at line 43 of file TlsSocket.h.

Member Typedef Documentation

◆ HandshakeCompletionHandler

using asio::TlsSocket::HandshakeCompletionHandler = std::function<void(const ErrorCode&)>

Definition at line 47 of file TlsSocket.h.

Constructor & Destructor Documentation

◆ TlsSocket()

asio::TlsSocket::TlsSocket ( std::shared_ptr< Context io_context,
std::shared_ptr< TlsContext tls_context 
)

◆ ~TlsSocket()

asio::TlsSocket::~TlsSocket ( )
override

Member Function Documentation

◆ async_handshake()

void asio::TlsSocket::async_handshake ( TlsStream::handshake_type  handshake_type,
const HandshakeCompletionHandler handler 
)

◆ async_read()

void asio::TlsSocket::async_read ( void *  buffer,
const std::size_t  buffer_size,
const CompletionHandler handler 
)
overridevirtual

Reimplemented from asio::TcpSocket.

◆ async_write()

void asio::TlsSocket::async_write ( const void *  buffer,
const std::size_t  buffer_size,
const CompletionHandler handler 
)
overridevirtual

Reimplemented from asio::TcpSocket.

◆ close()

void asio::TlsSocket::close ( )
overridevirtual

Reimplemented from asio::TcpSocket.

◆ is_valid()

bool asio::TlsSocket::is_valid ( ) const
overridevirtual

Reimplemented from asio::TcpSocket.


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