Fixes #91: added timeout on Client's async_connect
This commit is contained in:
parent
14d848be3e
commit
dc7762e63b
2 changed files with 8 additions and 2 deletions
|
|
@ -383,8 +383,11 @@ namespace SimpleWeb {
|
||||||
socket=std::unique_ptr<HTTP>(new HTTP(io_service));
|
socket=std::unique_ptr<HTTP>(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*/){
|
(const boost::system::error_code &ec, boost::asio::ip::tcp::resolver::iterator /*it*/){
|
||||||
|
if(timer)
|
||||||
|
timer->cancel();
|
||||||
if(!ec) {
|
if(!ec) {
|
||||||
boost::asio::ip::tcp::no_delay option(true);
|
boost::asio::ip::tcp::no_delay option(true);
|
||||||
this->socket->set_option(option);
|
this->socket->set_option(option);
|
||||||
|
|
|
||||||
|
|
@ -53,8 +53,11 @@ namespace SimpleWeb {
|
||||||
socket=std::unique_ptr<HTTPS>(new HTTPS(io_service, context));
|
socket=std::unique_ptr<HTTPS>(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*/){
|
(const boost::system::error_code &ec, boost::asio::ip::tcp::resolver::iterator /*it*/){
|
||||||
|
if(timer)
|
||||||
|
timer->cancel();
|
||||||
if(!ec) {
|
if(!ec) {
|
||||||
boost::asio::ip::tcp::no_delay option(true);
|
boost::asio::ip::tcp::no_delay option(true);
|
||||||
this->socket->lowest_layer().set_option(option);
|
this->socket->lowest_layer().set_option(option);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue