Ask HN: Resources for Building a Webserver in C?
31–40 of 67 posts
Re: Ask HN: Resources for Building a Webserver in C?
#32Earlier quoted context omitted.
A little context: I'm specifically interested in compressing my analytics stack. I'm currently interacting with HTTP Messages at a higher level. The problem, as I see it, is the webserver is already doing this work but without useful output. I'd like to implement my analytics paradigm natively at the webserver level.
I'm not sure I follow - you want a smart, small webserver that takes in a http request and updates an analytic store based on headers? Sounds like something nginx might handle via lua scripting? Otherwise, maybe you want: https://github.com/lammertb/libhttp Or you might want to look at either of: https://www.acme.com/software/thttpd/ https://github.com/openbsd/src/tree/master/usr.sbin/httpd If you really want to buil…
There are certainly off the shelf options, but I enjoy reinventing the wheel and dislike dependencies. I'd like to use C because I have interest in OS level webservers.
Re: Ask HN: Resources for Building a Webserver in C?
#33Beej's guide to network programming: https://beej.us/guide/bgnet/
This guide is great for introducing the bsd socket api but this is really not the API you want to use if you want to create a production quality web server in C in 2022. You need the uring io API.
Re: Ask HN: Resources for Building a Webserver in C?
#34Beej's guide to network programming: https://beej.us/guide/bgnet/
Re: Ask HN: Resources for Building a Webserver in C?
#35Unix Network Programming by W. Richard Stevens and parts of The Linux Programming Interface by Michael Kerrisk
Re: Ask HN: Resources for Building a Webserver in C?
#36It multiplexes multiple clients (sockets) over a thread, so you can write an event loop in each thread and serve far more requests per thread than you could if it was one thread per client or one process per client. (epollserver_threaded.c)
It uses a thread safe multiconsumer multiproducer ringbuffer to communicate between threads.
https://github.com/samsquire/epoll-server
I use Alexander Krizhanovsky's of Tempesta technologies Lock-Free Multi-Producer Multi-Consumer Queue on Ring Buffer
https://www.linuxjournal.com/content/lock-free-multi-produce...
Re: Ask HN: Resources for Building a Webserver in C?
#37"Write a tiny web server in C" was a standard exercise when I was in high school, and later again in university. I think I did that at least 3 times as an assignment so far. I reused the final version for a different university exercise instead of bothering with Tomcat as I was required, and back in 2015, dumped the end result here: https://github.com/AgentD/websrv where I kept adding to it for a while for fun. The H…
Re: Ask HN: Resources for Building a Webserver in C?
#38Re: Ask HN: Resources for Building a Webserver in C?
#39Ok then! Writing a web server in C is bloody stupid. A web server's performance is mostly limited by concurrency issues and various IO latencies, not by how fast the machine code runs. Thus, there are zero advantages to writing a web server in C and mountains of disadvantages. Save your time and write your web server in a good language, Java, Go, Python, Nim, but not C.
Re: Ask HN: Resources for Building a Webserver in C?
#40It actually ran a production site at an old company I worked at until fairly recently.
http://git.annexia.org/?p=c2lib.git;a=tree http://git.annexia.org/?p=pthrlib.git;a=tree http://git.annexia.org/?p=rws.git;a=tree