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.
Event-driven programming requires less memory than multi-threaded programming because there are no threads that require stack memory. The entire system can run as a single thread, which requires only one single stack.
In computer programming, event-driven programming is a programming paradigm in which the flow of the program is determined by events such as user actions (mouse clicks, key presses), sensor outputs, or message passing from other programs or threads.
An event-driven application is a computer program that is written to respond to actions generated by the user or the system. In a computing context, an event is any identifiable occurrence that has significance for system hardware or software.
An event-driven server typically has a single thread which manages all connections to the server. The thread uses the select() system call to simultaneously wait for events on these connections. When a call to select() returns, the server's main loop invokes event handlers for each of the ready descriptors.
Here is one which is part of TupleServer source that uses libevent.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With