2#include <boost/asio.hpp>
4#include <boost/asio/ssl.hpp>
6#include "crow/settings.h"
7#if BOOST_VERSION >= 107000
8#define GET_IO_SERVICE(s) ((boost::asio::io_context&)(s).get_executor().context())
10#define GET_IO_SERVICE(s) ((s).get_io_service())
14 using namespace boost;
15 using tcp = asio::ip::tcp;
26 boost::asio::io_service& get_io_service()
28 return GET_IO_SERVICE(socket_);
43 tcp::endpoint remote_endpoint()
45 return socket_.remote_endpoint();
50 return socket_.is_open();
55 boost::system::error_code ec;
59 void shutdown_readwrite()
61 boost::system::error_code ec;
62 socket_.shutdown(boost::asio::socket_base::shutdown_type::shutdown_both, ec);
67 boost::system::error_code ec;
68 socket_.shutdown(boost::asio::socket_base::shutdown_type::shutdown_send, ec);
73 boost::system::error_code ec;
74 socket_.shutdown(boost::asio::socket_base::shutdown_type::shutdown_receive, ec);
80 f(boost::system::error_code());
89 using context = boost::asio::ssl::context;
90 using ssl_socket_t = boost::asio::ssl::stream<tcp::socket>;
91 SSLAdaptor(boost::asio::io_service& io_service, context* ctx)
92 : ssl_socket_(new ssl_socket_t(io_service, *ctx))
96 boost::asio::ssl::stream<tcp::socket>& socket()
101 tcp::socket::lowest_layer_type&
104 return ssl_socket_->lowest_layer();
107 tcp::endpoint remote_endpoint()
109 return raw_socket().remote_endpoint();
114 return ssl_socket_ ? raw_socket().is_open() :
false;
121 boost::system::error_code ec;
122 raw_socket().close(ec);
126 void shutdown_readwrite()
130 boost::system::error_code ec;
131 raw_socket().shutdown(boost::asio::socket_base::shutdown_type::shutdown_both, ec);
135 void shutdown_write()
139 boost::system::error_code ec;
140 raw_socket().shutdown(boost::asio::socket_base::shutdown_type::shutdown_send, ec);
148 boost::system::error_code ec;
149 raw_socket().shutdown(boost::asio::socket_base::shutdown_type::shutdown_receive, ec);
153 boost::asio::io_service& get_io_service()
155 return GET_IO_SERVICE(raw_socket());
158 template <
typename F>
161 ssl_socket_->async_handshake(boost::asio::ssl::stream_base::server,
162 [f](
const boost::system::error_code& ec) {
167 std::unique_ptr<boost::asio::ssl::stream<tcp::socket>> ssl_socket_;
A wrapper for the asio::ip::tcp::socket and asio::ssl::stream.
Definition: socket_adaptors.h:19
tcp::socket & socket()
Get the object handling data transfers, this can be either a TCP socket or an SSL stream (if SSL is e...
Definition: socket_adaptors.h:38
tcp::socket & raw_socket()
Get the TCP socket handling data trasfers, regardless of what layer is handling transfers on top of t...
Definition: socket_adaptors.h:32