Changeset 20017 for trunk/FACT++/src/ConnectionSSL.cc
- Timestamp:
- 12/28/20 17:25:10 (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/FACT++/src/ConnectionSSL.cc
r20005 r20017 18 18 namespace dummy = ba::placeholders; 19 19 20 typedef ssl::stream<boost::asio::ip::tcp::socket> stream;21 22 20 using ba::ip::tcp; 23 21 … … 34 32 void ConnectionSSL::AsyncRead(const ba::mutable_buffers_1 buffers, int type) 35 33 { 36 ba::async_read(* this, buffers,34 ba::async_read(*stream, buffers, 37 35 boost::bind(&ConnectionSSL::HandleReceivedData, this, 38 36 dummy::error, dummy::bytes_transferred, type)); … … 41 39 void ConnectionSSL::AsyncWrite(const ba::const_buffers_1 &buffers) 42 40 { 43 ba::async_write(* this, buffers,41 ba::async_write(*stream, buffers, 44 42 boost::bind(&ConnectionSSL::HandleSentData, this, 45 43 dummy::error, dummy::bytes_transferred)); … … 69 67 70 68 // AsyncConnect + Deadline 71 69 stream->lowest_layer().async_connect(endpoint, 72 70 boost::bind(&ConnectionSSL::ConnectIter, 73 71 this, iterator, ba::placeholders::error)); … … 80 78 { 81 79 // AsyncConnect + Deadline 82 lowest_layer().async_connect(fEndpoint,80 stream->lowest_layer().async_connect(fEndpoint, 83 81 boost::bind(&ConnectionSSL::ConnectAddr, 84 82 this, fEndpoint, ba::placeholders::error)); … … 87 85 //AsyncWait(fConnectTimeout, 5, &ConnectionSSL::HandleConnectTimeout); 88 86 } 87 88 void ConnectionSSL::HandleAsyncShutdown(const bs::error_code &error) 89 { 90 stream->lowest_layer().close(); 91 92 if (!error || error==error.default_error_condition()) 93 return; 94 95 ostringstream str; 96 str << "Shutdown of SSL connection to " << URL() << "[" << error.value() << "]: " << error.message() << " (" << error << ")";// << endl; 97 Error(str); 98 } 99 89 100 90 101 // ------------------------ close -------------------------- … … 103 114 104 115 // Close possible open connections 105 lowest_layer().close(); 116 if (!IsClosed()) 117 { 118 // Adapted from 119 // https://stackoverflow.com/questions/49122521/cant-implement-boostasiosslstreamboostasioiptcpsocket-reconnect 120 121 #if BOOST_VERSION < 107000 122 auto& io_context = stream->get_io_service(); 123 #else 124 const auto& io_context = stream->get_executor(); 125 #endif 126 127 stream->lowest_layer().cancel(); // Remove all pending stuff in the queue 128 stream->async_shutdown(boost::bind(&ConnectionSSL::HandleAsyncShutdown, this, dummy::error)); 129 130 stream.emplace(io_context, *this); 131 } 106 132 107 133 // Reset the connection status … … 128 154 void ConnectionSSL::PostClose(bool restart) 129 155 { 130 get_io_service().post(boost::bind(&ConnectionSSL::CloseImp, this, restart)); 156 #if BOOST_VERSION < 107000 157 stream->get_io_service().post(boost::bind(&ConnectionSSL::CloseImp, this, restart)); 158 #else 159 ba::post(boost::bind(&ConnectionSSL::CloseImp, this, restart)); 160 #endif 131 161 } 132 162 … … 265 295 if (!error) 266 296 { 267 lowest_layer().set_option(boost::asio::socket_base::keep_alive(true));297 stream->lowest_layer().set_option(boost::asio::socket_base::keep_alive(true)); 268 298 269 299 const int optval = 30; 270 300 271 #if BOOST_VERSION < 107000301 #if BOOST_VERSION < 107000 272 302 // First keep alive after 30s 273 setsockopt( lowest_layer().native(), SOL_TCP, TCP_KEEPIDLE, &optval, sizeof(optval));303 setsockopt(stream->lowest_layer().native(), SOL_TCP, TCP_KEEPIDLE, &optval, sizeof(optval)); 274 304 // New keep alive after 30s 275 setsockopt( lowest_layer().native(), SOL_TCP, TCP_KEEPINTVL, &optval, sizeof(optval));305 setsockopt(stream->lowest_layer().native(), SOL_TCP, TCP_KEEPINTVL, &optval, sizeof(optval)); 276 306 #else 277 307 // First keep alive after 30s 278 setsockopt( lowest_layer().native_handle(), SOL_TCP, TCP_KEEPIDLE, &optval, sizeof(optval));308 setsockopt(stream->lowest_layer().native_handle(), SOL_TCP, TCP_KEEPIDLE, &optval, sizeof(optval)); 279 309 // New keep alive after 30s 280 setsockopt( lowest_layer().native_handle(), SOL_TCP, TCP_KEEPINTVL, &optval, sizeof(optval));310 setsockopt(stream->lowest_layer().native_handle(), SOL_TCP, TCP_KEEPINTVL, &optval, sizeof(optval)); 281 311 #endif 282 312 … … 331 361 //set_default_verify_paths(); 332 362 333 async_handshake(stream::client,363 stream->async_handshake(boost::asio::ssl::stream<boost::asio::ip::tcp::socket>::client, 334 364 boost::bind(&ConnectionSSL::HandleHandshake, this, 335 365 endpoint, dummy::error)); … … 454 484 else 455 485 { 456 tcp::resolver resolver(get_io_service()); 486 #if BOOST_VERSION < 107000 487 tcp::resolver resolver(stream->get_io_service()); 488 #else 489 tcp::resolver resolver(stream->get_executor()); 490 #endif 457 491 458 492 tcp::resolver::query query(fAddress, fPort); … … 529 563 530 564 ConnectionSSL::ConnectionSSL(ba::io_service& ioservice, ostream &out) : MessageImp(out), 565 #if BOOST_VERSION < 107000 531 566 ssl::context(ioservice, boost::asio::ssl::context::method::sslv23_client), 532 stream(ioservice, *this), fLog(0), fVerbose(true), fDebugTx(false), 567 #else 568 ssl::context(boost::asio::ssl::context::method::sslv23_client), 569 #endif 570 stream(boost::in_place_init, ioservice, *this), 571 fLog(0), fVerbose(true), fDebugTx(false), 533 572 fInTimeout(ioservice), fOutTimeout(ioservice), fConnectionTimer(ioservice), 534 573 fQueueSize(0), fConnectionStatus(kDisconnected)
Note:
See TracChangeset
for help on using the changeset viewer.