Now closes file if connection is interrupted in default_resource example. Also some minor cleanup.
This commit is contained in:
parent
1a39476f92
commit
fa1efed7f0
4 changed files with 31 additions and 21 deletions
|
|
@ -88,9 +88,7 @@ namespace SimpleWeb {
|
|||
remote_endpoint_address=socket.lowest_layer().remote_endpoint().address().to_string();
|
||||
remote_endpoint_port=socket.lowest_layer().remote_endpoint().port();
|
||||
}
|
||||
catch(const std::exception& e) {
|
||||
std::cerr << e.what() << std::endl;
|
||||
}
|
||||
catch(const std::exception& e) {}
|
||||
}
|
||||
};
|
||||
|
||||
|
|
@ -222,20 +220,22 @@ namespace SimpleWeb {
|
|||
std::shared_ptr<boost::asio::deadline_timer> timer;
|
||||
if(timeout_content>0)
|
||||
timer=set_timeout_on_socket(socket, timeout_content);
|
||||
unsigned long long content_length;
|
||||
try {
|
||||
boost::asio::async_read(*socket, request->streambuf,
|
||||
boost::asio::transfer_exactly(stoull(it->second)-num_additional_bytes),
|
||||
[this, socket, request, timer]
|
||||
(const boost::system::error_code& ec, size_t /*bytes_transferred*/) {
|
||||
if(timeout_content>0)
|
||||
timer->cancel();
|
||||
if(!ec)
|
||||
find_resource(socket, request);
|
||||
});
|
||||
content_length=stoull(it->second);
|
||||
}
|
||||
catch(const std::exception& e) {
|
||||
std::cerr << e.what() << std::endl;
|
||||
catch(const std::exception &e) {
|
||||
return;
|
||||
}
|
||||
boost::asio::async_read(*socket, request->streambuf,
|
||||
boost::asio::transfer_exactly(content_length-num_additional_bytes),
|
||||
[this, socket, request, timer]
|
||||
(const boost::system::error_code& ec, size_t /*bytes_transferred*/) {
|
||||
if(timeout_content>0)
|
||||
timer->cancel();
|
||||
if(!ec)
|
||||
find_resource(socket, request);
|
||||
});
|
||||
}
|
||||
else {
|
||||
find_resource(socket, request);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue