From dc7762e63b204df45bc65f53949f27d908e429c6 Mon Sep 17 00:00:00 2001 From: eidheim Date: Sun, 11 Dec 2016 10:53:33 +0100 Subject: [PATCH] Fixes #91: added timeout on Client's async_connect --- client_http.hpp | 5 ++++- client_https.hpp | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/client_http.hpp b/client_http.hpp index 5e13252..f534762 100644 --- a/client_http.hpp +++ b/client_http.hpp @@ -383,8 +383,11 @@ namespace SimpleWeb { socket=std::unique_ptr(new HTTP(io_service)); } - boost::asio::async_connect(*socket, it, [this] + auto timer=get_timeout_timer(); + boost::asio::async_connect(*socket, it, [this, timer] (const boost::system::error_code &ec, boost::asio::ip::tcp::resolver::iterator /*it*/){ + if(timer) + timer->cancel(); if(!ec) { boost::asio::ip::tcp::no_delay option(true); this->socket->set_option(option); diff --git a/client_https.hpp b/client_https.hpp index e5c59ef..2ad3406 100644 --- a/client_https.hpp +++ b/client_https.hpp @@ -53,8 +53,11 @@ namespace SimpleWeb { socket=std::unique_ptr(new HTTPS(io_service, context)); } - boost::asio::async_connect(socket->lowest_layer(), it, [this] + auto timer=get_timeout_timer(); + boost::asio::async_connect(socket->lowest_layer(), it, [this, timer] (const boost::system::error_code &ec, boost::asio::ip::tcp::resolver::iterator /*it*/){ + if(timer) + timer->cancel(); if(!ec) { boost::asio::ip::tcp::no_delay option(true); this->socket->lowest_layer().set_option(option);