@@ -25,10 +25,13 @@ under the License.
2525#include " ssl_stream.h"
2626#elif BOOST_VERSION < 107000
2727#include < boost/beast/experimental/core/ssl_stream.hpp>
28- #else
28+ #elif BOOST_VERSION < 108600
2929#include < boost/beast/http.hpp>
3030#include < boost/beast/ssl.hpp>
3131#include < boost/beast/websocket/ssl.hpp>
32+ #else
33+ #include < boost/asio/ssl.hpp>
34+ #include < boost/beast/websocket/ssl.hpp>
3235#endif
3336
3437namespace http = boost::beast::http; // from <boost/beast/http.hpp>
@@ -48,13 +51,26 @@ namespace ETP_NS
4851 virtual ~SslClientSession () {}
4952
5053 // Called by the base class
54+ #if BOOST_VERSION < 107000
5155 FETPAPI_DLL_IMPORT_OR_EXPORT std::unique_ptr<websocket::stream<boost::beast::ssl_stream<tcp::socket>>>& ws () { return ws_; }
56+ #elif BOOST_VERSION < 108600
57+ FETPAPI_DLL_IMPORT_OR_EXPORT std::unique_ptr<websocket::stream<boost::beast::ssl_stream<boost::beast::tcp_stream>>>& ws () { return ws_; }
58+ #else
59+ FETPAPI_DLL_IMPORT_OR_EXPORT std::unique_ptr< websocket::stream<boost::asio::ssl::stream<boost::beast::tcp_stream>>>& ws () { return ws_; }
60+ #endif
5261
5362 bool isTls () const final { return true ; }
5463
55- void asyncConnect ()
64+ void asyncConnect (const tcp::resolver::results_type& results )
5665 {
66+ #if BOOST_VERSION < 107000
5767 ws_.reset (new websocket::stream<boost::beast::ssl_stream<tcp::socket>>(ioc, sslContext_));
68+ #elif BOOST_VERSION < 108600
69+ ws_.reset (new websocket::stream<boost::beast::ssl_stream<boost::beast::tcp_stream>>(ioc, sslContext_));
70+ #else
71+ ws_.reset (new websocket::stream<boost::asio::ssl::stream<boost::beast::tcp_stream>>(ioc, sslContext_));
72+ #endif
73+
5874 ws_->binary (true );
5975#if BOOST_VERSION < 107000
6076 ws_->write_buffer_size (frameSize_);
@@ -69,7 +85,12 @@ namespace ETP_NS
6985 std::cerr << " Websocket on connect (SNI): " << ecSNI.message () << std::endl;
7086 }
7187
88+ // Reality check: IPv6 is unlikely to be available yet
89+ std::vector<tcp::endpoint> endpoints = std::vector<tcp::endpoint>(results.begin (), results.end ());
90+ std::stable_partition (endpoints.begin (), endpoints.end (), [](auto entry) {return entry.protocol () == tcp::v4 (); });
91+
7292 // Make the connection on the IP address we get from a lookup
93+ #if BOOST_VERSION < 107000
7394 boost::asio::async_connect (
7495 ws_->next_layer ().next_layer (),
7596 endpoints.begin (),
@@ -78,9 +99,20 @@ namespace ETP_NS
7899 &SslClientSession::on_ssl_connect,
79100 std::static_pointer_cast<SslClientSession>(shared_from_this ()),
80101 std::placeholders::_1));
102+ #else
103+ boost::beast::get_lowest_layer (*ws_).async_connect (
104+ endpoints,
105+ boost::beast::bind_front_handler (
106+ &SslClientSession::on_ssl_connect,
107+ std::static_pointer_cast<SslClientSession>(shared_from_this ())));
108+ #endif
81109 }
82110
111+ #if BOOST_VERSION < 107000
83112 void on_ssl_connect (boost::system::error_code ec) {
113+ #else
114+ void on_ssl_connect (boost::beast::error_code ec, tcp::resolver::results_type::endpoint_type) {
115+ #endif
84116 if (ec) {
85117 std::cerr << " on_ssl_connect : " << ec.message () << std::endl;
86118 }
@@ -110,7 +142,7 @@ namespace ETP_NS
110142 ws_->next_layer ().async_handshake (
111143 boost::asio::ssl::stream_base::client,
112144 std::bind (
113- &AbstractClientSessionCRTP::on_connect ,
145+ &AbstractClientSessionCRTP::on_ssl_handshake ,
114146 std::static_pointer_cast<AbstractClientSessionCRTP>(shared_from_this ()),
115147 std::placeholders::_1));
116148 }
@@ -166,14 +198,20 @@ namespace ETP_NS
166198 ws_->next_layer ().async_handshake (
167199 boost::asio::ssl::stream_base::client,
168200 std::bind (
169- &AbstractClientSessionCRTP::on_connect ,
201+ &AbstractClientSessionCRTP::on_ssl_handshake ,
170202 std::static_pointer_cast<AbstractClientSessionCRTP>(shared_from_this ()),
171203 std::placeholders::_1));
172204 }
173205
174206 private:
175207 boost::asio::ssl::context sslContext_;
208+ #if BOOST_VERSION < 107000
176209 std::unique_ptr<websocket::stream<boost::beast::ssl_stream<tcp::socket>>> ws_;
210+ #elif BOOST_VERSION < 108600
211+ std::unique_ptr<websocket::stream<boost::beast::ssl_stream<boost::beast::tcp_stream>>> ws_;
212+ #else
213+ std::unique_ptr<websocket::stream<boost::asio::ssl::stream<boost::beast::tcp_stream>>> ws_;
214+ #endif
177215 http::request<http::empty_body> proxyHandshake;
178216 http::response<http::empty_body> proxyHandshakeResponse;
179217 // use own response parser
0 commit comments