Live data from Hacker News

Ask HN: Resources for Building a Webserver in C?

news.ycombinator.com

21–30 of 67 posts

Re: Ask HN: Resources for Building a Webserver in C?

#22

"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…

Beej is fantastic resource!

Re: Ask HN: Resources for Building a Webserver in C?

#23

Earlier quoted context omitted.

conceptually things are pretty limited - this is really simple if you are just playing around, and are just doing http 1 o bind a socket o manage incoming connections o parse http headers o 'routing' - demultiplex handlers based on URL o encode response unless its a little embedded thing one usually uses some kind of select/epoll machinery to multiplex the work on each channel. I guess thread-per-request is another m…

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.

Parse server logs, if that helps.

Re: Ask HN: Resources for Building a Webserver in C?

#24

Earlier quoted context omitted.

conceptually things are pretty limited - this is really simple if you are just playing around, and are just doing http 1 o bind a socket o manage incoming connections o parse http headers o 'routing' - demultiplex handlers based on URL o encode response unless its a little embedded thing one usually uses some kind of select/epoll machinery to multiplex the work on each channel. I guess thread-per-request is another m…

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 build (another) web server in C.

Not entirely clear why want to use C for this, though?

Re: Ask HN: Resources for Building a Webserver in C?

#28
post #24

Earlier 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…

for some applications it really might be easier to write a little thing than integrate into some giant framework. and I do think that building these things really helps one understand what's going on in all those layers

but I have to agree about C. unless the whole point is to ingrate with some existing codebase, there are several language choices which should turn this from a day or two of work to an hour or two - with a more robust outcome

Re: Ask HN: Resources for Building a Webserver in C?

#29
post #17
post #5

Beej'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.

Might want to check out:

https://unixism.net/loti/tutorial/webserver_liburing.html

(and maybe the older tutorial too):

https://unixism.net/2019/04/linux-applications-performance-i...

Post reply on HN