Client::io_service is now shared_ptr

This commit is contained in:
eidheim 2017-06-12 07:57:10 +02:00
commit 45f84489bc
2 changed files with 21 additions and 21 deletions

View file

@ -149,8 +149,8 @@ namespace SimpleWeb {
throw system_error(ec); throw system_error(ec);
} }
}); });
io_service.reset(); io_service->reset();
io_service.run(); io_service->run();
return request_read(); return request_read();
} }
@ -193,8 +193,8 @@ namespace SimpleWeb {
throw system_error(ec); throw system_error(ec);
} }
}); });
io_service.reset(); io_service->reset();
io_service.run(); io_service->run();
return request_read(); return request_read();
} }
@ -209,7 +209,7 @@ namespace SimpleWeb {
} }
protected: protected:
asio::io_service io_service; std::shared_ptr<asio::io_service> io_service;
asio::ip::tcp::resolver resolver; asio::ip::tcp::resolver resolver;
std::unique_ptr<socket_type> socket; std::unique_ptr<socket_type> socket;
@ -218,7 +218,7 @@ namespace SimpleWeb {
std::string host; std::string host;
unsigned short port; unsigned short port;
ClientBase(const std::string& host_port, unsigned short default_port) : resolver(io_service) { ClientBase(const std::string& host_port, unsigned short default_port) : io_service(new asio::io_service()), resolver(*io_service) {
auto parsed_host_port=parse_host_port(host_port, default_port); auto parsed_host_port=parse_host_port(host_port, default_port);
host=parsed_host_port.first; host=parsed_host_port.first;
port=parsed_host_port.second; port=parsed_host_port.second;
@ -246,7 +246,7 @@ namespace SimpleWeb {
if(timeout==0) if(timeout==0)
return nullptr; return nullptr;
auto timer=std::make_shared<asio::deadline_timer>(io_service); auto timer=std::make_shared<asio::deadline_timer>(*io_service);
timer->expires_from_now(boost::posix_time::seconds(timeout)); timer->expires_from_now(boost::posix_time::seconds(timeout));
timer->async_wait([this](const error_code& ec) { timer->async_wait([this](const error_code& ec) {
if(!ec) { if(!ec) {
@ -339,8 +339,8 @@ namespace SimpleWeb {
throw system_error(ec); throw system_error(ec);
} }
}); });
io_service.reset(); io_service->reset();
io_service.run(); io_service->run();
return response; return response;
} }
@ -434,7 +434,7 @@ namespace SimpleWeb {
if(!ec) { if(!ec) {
{ {
std::lock_guard<std::mutex> lock(socket_mutex); std::lock_guard<std::mutex> lock(socket_mutex);
socket=std::unique_ptr<HTTP>(new HTTP(io_service)); socket=std::unique_ptr<HTTP>(new HTTP(*io_service));
} }
auto timer=get_timeout_timer(config.timeout_connect); auto timer=get_timeout_timer(config.timeout_connect);
@ -459,8 +459,8 @@ namespace SimpleWeb {
throw system_error(ec); throw system_error(ec);
} }
}); });
io_service.reset(); io_service->reset();
io_service.run(); io_service->run();
} }
} }
}; };

View file

@ -55,7 +55,7 @@ namespace SimpleWeb {
if(!ec) { if(!ec) {
{ {
std::lock_guard<std::mutex> lock(socket_mutex); std::lock_guard<std::mutex> lock(socket_mutex);
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(config.timeout_connect); auto timer=get_timeout_timer(config.timeout_connect);
@ -80,8 +80,8 @@ namespace SimpleWeb {
throw system_error(ec); throw system_error(ec);
} }
}); });
io_service.reset(); io_service->reset();
io_service.run(); io_service->run();
if(!config.proxy_server.empty()) { if(!config.proxy_server.empty()) {
asio::streambuf write_buffer; asio::streambuf write_buffer;
@ -99,8 +99,8 @@ namespace SimpleWeb {
throw system_error(ec); throw system_error(ec);
} }
}); });
io_service.reset(); io_service->reset();
io_service.run(); io_service->run();
std::shared_ptr<Response> response(new Response()); std::shared_ptr<Response> response(new Response());
timer=get_timeout_timer(); timer=get_timeout_timer();
@ -114,8 +114,8 @@ namespace SimpleWeb {
throw system_error(ec); throw system_error(ec);
} }
}); });
io_service.reset(); io_service->reset();
io_service.run(); io_service->run();
parse_response_header(response); parse_response_header(response);
if (response->status_code.empty() || response->status_code.compare(0, 3, "200") != 0) { if (response->status_code.empty() || response->status_code.compare(0, 3, "200") != 0) {
std::lock_guard<std::mutex> lock(socket_mutex); std::lock_guard<std::mutex> lock(socket_mutex);
@ -135,8 +135,8 @@ namespace SimpleWeb {
throw system_error(ec); throw system_error(ec);
} }
}); });
io_service.reset(); io_service->reset();
io_service.run(); io_service->run();
} }
} }
}; };