Minor timeout source cleanups
This commit is contained in:
parent
8a73cb381a
commit
7d95360e62
1 changed files with 6 additions and 10 deletions
|
|
@ -261,8 +261,6 @@ namespace SimpleWeb {
|
||||||
//If content, read that as well
|
//If content, read that as well
|
||||||
auto it=request->header.find("Content-Length");
|
auto it=request->header.find("Content-Length");
|
||||||
if(it!=request->header.end()) {
|
if(it!=request->header.end()) {
|
||||||
//Set timeout on the following boost::asio::async-read or write function
|
|
||||||
auto timer=get_timeout_timer(socket, timeout_content);
|
|
||||||
unsigned long long content_length;
|
unsigned long long content_length;
|
||||||
try {
|
try {
|
||||||
content_length=stoull(it->second);
|
content_length=stoull(it->second);
|
||||||
|
|
@ -273,6 +271,8 @@ namespace SimpleWeb {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if(content_length>num_additional_bytes) {
|
if(content_length>num_additional_bytes) {
|
||||||
|
//Set timeout on the following boost::asio::async-read or write function
|
||||||
|
auto timer=get_timeout_timer(socket, timeout_content);
|
||||||
boost::asio::async_read(*socket, request->streambuf,
|
boost::asio::async_read(*socket, request->streambuf,
|
||||||
boost::asio::transfer_exactly(content_length-num_additional_bytes),
|
boost::asio::transfer_exactly(content_length-num_additional_bytes),
|
||||||
[this, socket, request, timer]
|
[this, socket, request, timer]
|
||||||
|
|
@ -283,15 +283,11 @@ namespace SimpleWeb {
|
||||||
find_resource(socket, request);
|
find_resource(socket, request);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
else {
|
else
|
||||||
if(timer)
|
|
||||||
timer->cancel();
|
|
||||||
find_resource(socket, request);
|
find_resource(socket, request);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else {
|
else
|
||||||
find_resource(socket, request);
|
find_resource(socket, request);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
@ -366,9 +362,9 @@ namespace SimpleWeb {
|
||||||
auto response=std::shared_ptr<Response>(new Response(socket), [this, request, timer](Response *response_ptr) {
|
auto response=std::shared_ptr<Response>(new Response(socket), [this, request, timer](Response *response_ptr) {
|
||||||
auto response=std::shared_ptr<Response>(response_ptr);
|
auto response=std::shared_ptr<Response>(response_ptr);
|
||||||
send(response, [this, response, request, timer](const boost::system::error_code& ec) {
|
send(response, [this, response, request, timer](const boost::system::error_code& ec) {
|
||||||
|
if(timer)
|
||||||
|
timer->cancel();
|
||||||
if(!ec) {
|
if(!ec) {
|
||||||
if(timer)
|
|
||||||
timer->cancel();
|
|
||||||
float http_version;
|
float http_version;
|
||||||
try {
|
try {
|
||||||
http_version=stof(request->http_version);
|
http_version=stof(request->http_version);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue