4 ms·
it should be quite trivial to write a basic webserver in C.
by kmlx 3y ago
it 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.