6

There are many example thread based web servers online, but I haven't really seen anything that gives a good example of an event-loop based one (without being very complex, e.g. lighttp and nginx).

Are there any? If not, what should I read/look at to help me learn how to make a server of this sort? (This includes asynchronous IO in C, etc.)

I already understand the basics of how event-loop based programming works, especially in higher level languages like Python, but I need to be able to implement one in C.

Aaron Yodaiken
  • 19,163
  • 32
  • 103
  • 184

3 Answers3

2

Here is one which is part of TupleServer source that uses libevent.

Andrew White
  • 52,720
  • 19
  • 113
  • 137
0

In short, simple : libevent.org and example : http://www.wangafu.net/~nickm/libevent-book/ . As long as you get your hand in libevent, it's API working with http which is evhttp is not really robust, there is an alternative at https://github.com/ellzey/libevhtp . And of course libmicrohttpd works just fine.

tmh1999
  • 63
  • 5
0

Not sure how full featured your server needs to be, but here's a small C based web server that could be used as a starting point. It forks a child process for each connection, so it's easy to understand, but not the most efficient.

Ravi
  • 3,718
  • 7
  • 39
  • 57