c-cube / tiny_httpd

Minimal HTTP server using good old threads + blocking IO, with a small request router.
https://c-cube.github.io/tiny_httpd
75 stars 11 forks source link

Graceful shutdown #69

Closed vphantom closed 1 year ago

vphantom commented 1 year ago

Just creating the work environment, I'm not done yet.

vphantom commented 1 year ago

I still need to address two issues:

vphantom commented 1 year ago

Yikes, I'm not touching my 2nd point with a 10-foot pole. Your call stack is deep to finally get to the actual Unix.read from parse_req_start so my chances of refactoring that to exit between requests in a decent number of days is zero. 😬

Basically we would have to offer a high-level option to the line reading function, which we would use only when reading the first line of a new request, that we want to trickle down to the low actual I/O function that we want to keep an eye on our running bool every second with Unix.select wrapped around the Unix.read. This would affect a ton of stuff I don't really understand so I'll just tolerate the 60-second delay in shutting down.

This is thus ready for review.

vphantom commented 1 year ago

Yup, great idea. Will do within the hour.

c-cube commented 1 year ago

Thank you!