Fixes #101: added Config::timeout_connect
This commit is contained in:
parent
19627bbe6b
commit
91d01fb8ec
2 changed files with 9 additions and 5 deletions
|
|
@ -64,6 +64,8 @@ namespace SimpleWeb {
|
||||||
public:
|
public:
|
||||||
/// Set timeout on requests in seconds. Default value: 0 (no timeout).
|
/// Set timeout on requests in seconds. Default value: 0 (no timeout).
|
||||||
size_t timeout=0;
|
size_t timeout=0;
|
||||||
|
/// Set connect timeout in seconds. Default value: 0 (Config::timeout is then used instead).
|
||||||
|
size_t timeout_connect=0;
|
||||||
/// Set proxy server (server:port)
|
/// Set proxy server (server:port)
|
||||||
std::string proxy_server;
|
std::string proxy_server;
|
||||||
};
|
};
|
||||||
|
|
@ -209,12 +211,14 @@ namespace SimpleWeb {
|
||||||
|
|
||||||
virtual void connect()=0;
|
virtual void connect()=0;
|
||||||
|
|
||||||
std::shared_ptr<boost::asio::deadline_timer> get_timeout_timer() {
|
std::shared_ptr<boost::asio::deadline_timer> get_timeout_timer(size_t timeout=0) {
|
||||||
if(config.timeout==0)
|
if(timeout==0)
|
||||||
|
timeout=config.timeout;
|
||||||
|
if(timeout==0)
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
|
||||||
auto timer=std::make_shared<boost::asio::deadline_timer>(io_service);
|
auto timer=std::make_shared<boost::asio::deadline_timer>(io_service);
|
||||||
timer->expires_from_now(boost::posix_time::seconds(config.timeout));
|
timer->expires_from_now(boost::posix_time::seconds(timeout));
|
||||||
timer->async_wait([this](const boost::system::error_code& ec) {
|
timer->async_wait([this](const boost::system::error_code& ec) {
|
||||||
if(!ec) {
|
if(!ec) {
|
||||||
close();
|
close();
|
||||||
|
|
@ -390,7 +394,7 @@ namespace SimpleWeb {
|
||||||
socket=std::unique_ptr<HTTP>(new HTTP(io_service));
|
socket=std::unique_ptr<HTTP>(new HTTP(io_service));
|
||||||
}
|
}
|
||||||
|
|
||||||
auto timer=get_timeout_timer();
|
auto timer=get_timeout_timer(config.timeout_connect);
|
||||||
boost::asio::async_connect(*socket, it, [this, 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)
|
if(timer)
|
||||||
|
|
|
||||||
|
|
@ -53,7 +53,7 @@ namespace SimpleWeb {
|
||||||
socket=std::unique_ptr<HTTPS>(new HTTPS(io_service, context));
|
socket=std::unique_ptr<HTTPS>(new HTTPS(io_service, context));
|
||||||
}
|
}
|
||||||
|
|
||||||
auto timer=get_timeout_timer();
|
auto timer=get_timeout_timer(config.timeout_connect);
|
||||||
boost::asio::async_connect(socket->lowest_layer(), it, [this, 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)
|
if(timer)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue