3 ms·
"I tried building the equivalent in C++, but it was so painful that I eventually gave up." Unsurprisingly there's a good number of C and C++ webserver repos. T
by TheOtherHobbes 3y ago
"I tried building the equivalent in C++, but it was so painful that I eventually gave up."
Unsurprisingly there's a good number of C and C++ webserver repos. They're not all terrible - although some certainly are.
Would be interesting to see how the more usable ones compare.
- kmlx 3y agoit should be quite trivial to write a basic webserver in C.
- rbanffy 3y agoThat's probably why there are so many, and so many terrible options out there. It's relatively simple to write a trivial web server in C. To make a fast and usable web server in C is most likely anything but trivial. You'll need: - a way to register URL patterns and assign handler functions to them. - a way to set shared mutable process-wide things such as connections to external services and make sure one thread doesn't trample on - or needlessly block - other thread's changes. - a transparent way to make handlers work inside a single thread using asynchronous IO functions wherever possible. Fair enough - we are no longer in the trivial web server anymore.
- xena 3y agoThen please show us how it is done.
- lionkor 3y agobasic web server, for example https://github.com/lionkor/http https://github.com/lionkor/http. anything eith a real workload is kinda irrelevant here, as this benchmark only focuses on hello world.
- xxs 3y agoWriting 'hello world', or a fixed set of dispatch calls is still trivial with epoll now. In the late '90s when the web APIs (before REST) started to become a thing, writing an http C server few specific calls was quite the thing - there was no epoll, yet. Likely, I can write one (http1.1) in Java just using java.nio + DirectBuffer; no converting anything to String (similar to using void* for everything)... in several hours. It'd even scale with the amount of cores the machines has. It won't do much but as a micro benchmark (hello world) would be up there. That's nothing about usefulness of the code, or skill - it's just the benchmark is not useful for anything outside toying with.
- rcarmo 3y agoACME.com to the rescue: https://acme.com/software/mini_httpd https://acme.com/software/mini_httpd (slow) https://acme.com/software/thttpd https://acme.com/software/thttpd (pretty decent)
- FpUser 3y agoIt takes virtually no time with something like cpp-httplib. but I guess one have to discover it first.