4 #include <boost/asio.hpp>
5 #include <boost/asio/version.hpp>
7 #include <boost/asio/ssl.hpp>
10 #ifndef ASIO_STANDALONE
11 #define ASIO_STANDALONE
14 #include <asio/version.hpp>
15 #ifdef CROW_ENABLE_SSL
16 #include <asio/ssl.hpp>
19 #include "crow/settings.h"
21 #if (CROW_USE_BOOST && BOOST_VERSION >= 107000) || (ASIO_VERSION >= 101300)
22 #define GET_IO_SERVICE(s) ((asio::io_context&)(s).get_executor().context())
24 #define GET_IO_SERVICE(s) ((s).get_io_service())
30 namespace asio = boost::asio;
31 using error_code = boost::system::error_code;
33 using error_code = asio::error_code;
35 using tcp = asio::ip::tcp;
45 asio::io_service& get_io_service()
47 return GET_IO_SERVICE(socket_);
62 tcp::endpoint remote_endpoint()
64 return socket_.remote_endpoint();
69 return socket_.is_open();
78 void shutdown_readwrite()
81 socket_.shutdown(asio::socket_base::shutdown_type::shutdown_both, ec);
87 socket_.shutdown(asio::socket_base::shutdown_type::shutdown_send, ec);
93 socket_.shutdown(asio::socket_base::shutdown_type::shutdown_receive, ec);
105 #ifdef CROW_ENABLE_SSL
108 using context = asio::ssl::context;
109 using ssl_socket_t = asio::ssl::stream<tcp::socket>;
110 SSLAdaptor(asio::io_service& io_service, context* ctx):
111 ssl_socket_(
new ssl_socket_t(io_service, *ctx))
114 asio::ssl::stream<tcp::socket>& socket()
119 tcp::socket::lowest_layer_type&
122 return ssl_socket_->lowest_layer();
125 tcp::endpoint remote_endpoint()
127 return raw_socket().remote_endpoint();
132 return ssl_socket_ ? raw_socket().is_open() :
false;
140 raw_socket().close(ec);
144 void shutdown_readwrite()
149 raw_socket().shutdown(asio::socket_base::shutdown_type::shutdown_both, ec);
153 void shutdown_write()
158 raw_socket().shutdown(asio::socket_base::shutdown_type::shutdown_send, ec);
167 raw_socket().shutdown(asio::socket_base::shutdown_type::shutdown_receive, ec);
171 asio::io_service& get_io_service()
173 return GET_IO_SERVICE(raw_socket());
179 ssl_socket_->async_handshake(asio::ssl::stream_base::server,
180 [f](
const error_code& ec) {
185 std::unique_ptr<asio::ssl::stream<tcp::socket>> ssl_socket_;
The main namespace of the library. In this namespace is defined the most important classes and functi...
Definition: socket_adaptors.h:107
A wrapper for the asio::ip::tcp::socket and asio::ssl::stream.
Definition: socket_adaptors.h:39
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:51
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:57