11 using Error = boost::system::error_code;
14 : address_(std::move(address)), port_(std::move(port)), s_(ioService_), disconnectTimer_(ioService_),
15 connectionTimeout_(boost::posix_time::seconds(connectionTimeout_sec)) {}
19 disconnectionTimerStart();
20 boost::asio::ip::tcp::resolver r(ioService_);
21 boost::asio::async_connect(
22 s_, r.resolve({address_, port_}), [&](
const Error ec,
auto) { disconnectionTimerCancel(ec); });
27 catch(
const boost::exception&) {
33 std::vector<uint32_t> d(numWords);
34 disconnectionTimerStart();
35 boost::asio::async_read(s_, boost::asio::buffer(d), [&](
Error ec, std::size_t) { disconnectionTimerCancel(ec); });
43 disconnectionTimerStart();
44 boost::asio::async_write(s_, boost::asio::buffer(d), [&](
Error ec, std::size_t) { disconnectionTimerCancel(ec); });
53 s_.shutdown(boost::asio::ip::tcp::socket::shutdown_both);
62 void Connection::disconnectionTimerStart() {
63 disconnectTimer_.expires_from_now(connectionTimeout_);
64 disconnectTimer_.async_wait([&](
const Error& ec) {
65 if(ec == boost::asio::error::operation_aborted) {
73 void Connection::disconnectionTimerCancel(
const Error& ec) {
74 disconnectTimer_.cancel();