Changeset 20017
- Timestamp:
- 12/28/20 17:25:10 (4 years ago)
- Location:
- trunk/FACT++/src
- Files:
-
- 3 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) -
trunk/FACT++/src/ConnectionSSL.h
r19049 r20017 8 8 #include <boost/bind.hpp> 9 9 #include <boost/asio.hpp> 10 #include <boost/optional.hpp> 10 11 #include <boost/asio/ssl.hpp> 11 12 #include <boost/function.hpp> … … 14 15 #include "MessageImp.h" 15 16 16 class ConnectionSSL : public MessageImp, public boost::asio::ssl::context, 17 public boost::asio::ssl::stream<boost::asio::ip::tcp::socket> 17 typedef boost::optional<boost::asio::ssl::stream<boost::asio::ip::tcp::socket>> Stream; 18 19 class ConnectionSSL : public MessageImp, public boost::asio::ssl::context/*, 20 public Stream*/ 18 21 { 22 public: 23 Stream stream; 24 19 25 private: 20 26 MessageImp *fLog; … … 99 105 void HandleSentData(const boost::system::error_code& error, size_t); 100 106 void HandleHandshake(const boost::asio::ip::tcp::endpoint &endpoint, const boost::system::error_code& error); 107 void HandleAsyncShutdown(const boost::system::error_code &error); 101 108 102 109 int Write(const Time &t, const std::string &txt, int qos=kInfo); … … 143 150 bool IsTxQueueEmpty() const { return fQueueSize==0; /*fOutQueue.empty();*/ } 144 151 145 int IsClosed() const { return ! lowest_layer().is_open(); }152 int IsClosed() const { return !stream->lowest_layer().is_open(); } 146 153 147 154 bool IsDisconnected() const { return fConnectionStatus==kDisconnected; } -
trunk/FACT++/src/tngweather.cc
r19711 r20017 261 261 void StartReadReport() 262 262 { 263 async_read_some(ba::buffer(fArray),263 stream->async_read_some(ba::buffer(fArray), 264 264 boost::bind(&ConnectionWeather::HandleRead, this, 265 265 dummy::error, dummy::bytes_transferred)); … … 466 466 return T::GetCurrentState(); 467 467 } 468 469 int Reconnect(const EventImp &evt) 470 { 471 // Close all connections to supress the warning in SetEndpoint 472 fWeather.PostClose(false); 473 474 // Now wait until all connection have been closed and 475 // all pending handlers have been processed 476 poll(); 477 478 if (evt.GetBool()) 479 fWeather.SetEndpoint(evt.GetString()); 480 481 // Now we can reopen the connection 468 */ 469 int Connect() 470 { 482 471 fWeather.PostClose(true); 483 484 472 return T::GetCurrentState(); 485 473 } 486 */ 474 487 475 int Execute() 488 476 { … … 515 503 (bind(&StateMachineWeather::Disconnect, this)) 516 504 ("disconnect from ethernet"); 517 518 AddEvent("RECONNECT", "O")519 (bind(&StateMachineWeather::Reconnect, this, placeholders::_1))520 ("(Re)connect ethernet connection to FTM, a new address can be given"521 "|[host][string]:new ethernet address in the form <host:port>");522 505 */ 506 T::AddEvent("CONNECT", "", State::kDisconnected) 507 (bind(&StateMachineWeather::Connect, this)) 508 ("Connect"); 509 523 510 } 524 511
Note:
See TracChangeset
for help on using the changeset viewer.