Closed deadem closed 4 years ago
Thanks for reporting this issue! I'll address it as soon as the current work on issue #76 will be completed.
@deadem
Can you run cl -?
from the VC++ command prompt and tell us your compiler version?
Mine is 19.00.24210, and I had had to patch RESTinio-0.4.9.1 code to compile the example.
Microsoft (R) C/C++ Optimizing Compiler Version 19.00.24215.1 for x86 I'm using restinio 0.4.2, but problem exists in newer versions too
Can you modify your example that way and try it:
server = std::make_unique<restinio::http_server_t<Traits>>(restinio::own_io_context(),
restinio::run_on_this_thread_settings_t<Traits>().port(8888).address("0.0.0.0").request_handler([shutdown](auto req) {
auto & resp = req->create_response();
resp.header().should_keep_alive( false );
resp.set_body(std::make_shared<Body>([shutdown]() { shutdown(); })).done();
return restinio::request_accepted();
}));
Sure.
That line fix the problem: resp.header().should_keep_alive(false);
But how to get same result with keep-alive enabled?
Ow! I can disable keep-alive
in the last request only. Thanks! ;)
I can disable keep-alive in the last request only.
Yes. Because it seems that there is no sense to call shutdown
and close
methods for underlying socket in the destructor of connection
object in your scenario. io_context
will be stopped at that moment and calls to shutdown/close
won't have an effect. So you have to disable keep-alive
for the last request manually.
I've try to process only one request and then shutdown.
Here the example based on restinio 0.4.2 (using VS2015)
When
WORDS_COUNT
variable is relatively small (e.q. 10) server send full body content before shutown. But if I make it greater than 10000, server closes socket with pending data. I think there issocket::shutdown()
missed before call theacceptor::close()
function.