MeVisLab Toolbox Reference
TlsSocket.h
Go to the documentation of this file.
1// Copyright (c) Fraunhofer MEVIS, Germany. All rights reserved.
2// **InsertLicense** code
3
4#pragma once
5
6#include <asio/TcpSocket.h>
7
8#include <FMEThirdPartyWarningsDisable.h>
9#include <boost/asio/ssl.hpp>
10#include <utility>
11#include <mutex>
12#include <FMEThirdPartyWarningsRestore.h>
13
14
15namespace asio {
16
17 using TlsContext = boost::asio::ssl::context;
18 using TlsStream = boost::asio::ssl::stream<boost::asio::ip::tcp::socket&>;
19
44 {
45 public:
46
47 using HandshakeCompletionHandler = std::function<void(const ErrorCode&)>;
48
49 TlsSocket(std::shared_ptr<Context> io_context, std::shared_ptr<TlsContext> tls_context);
50
51 ~TlsSocket() override;
52
53 void async_handshake(TlsStream::handshake_type handshake_type, const HandshakeCompletionHandler& handler);
54
55 bool is_valid() const override;
56
57 void async_read(void* buffer, const std::size_t buffer_size, const CompletionHandler& handler) override;
58
59 void async_write(const void* buffer, const std::size_t buffer_size, const CompletionHandler& handler) override;
60
61 void close() override;
62
63 private:
64
65 void shutdown_tls();
66
67 std::shared_ptr<TlsContext> tls_context;
68
69 TlsStream tls_stream;
70
71 bool handshake_complete;
72
73 mutable std::mutex mutex;
74 };
75
76}
#define ASYNCHRONOUSIO_EXPORT
Definition System.h:10
std::function< void(const ErrorCode &, const std::size_t)> CompletionHandler
Definition Socket.h:27
A TCP socket class implementing the asio::Socket interface.
Definition TcpSocket.h:39
A TCP socket class with TLS support implementing the asio::Socket interface.
Definition TlsSocket.h:44
~TlsSocket() override
void async_write(const void *buffer, const std::size_t buffer_size, const CompletionHandler &handler) override
void async_handshake(TlsStream::handshake_type handshake_type, const HandshakeCompletionHandler &handler)
void async_read(void *buffer, const std::size_t buffer_size, const CompletionHandler &handler) override
void close() override
std::function< void(const ErrorCode &)> HandshakeCompletionHandler
Definition TlsSocket.h:47
bool is_valid() const override
TlsSocket(std::shared_ptr< Context > io_context, std::shared_ptr< TlsContext > tls_context)
Target mlrange_cast(Source arg)
Generic version of checked ML casts.
boost::system::error_code ErrorCode
Definition ErrorCodes.h:13
boost::asio::ssl::context TlsContext
Definition TlsSocket.h:17
boost::asio::ssl::stream< boost::asio::ip::tcp::socket & > TlsStream
Definition TlsSocket.h:18