Slide 12
Slide 12 text
The Event Loop
• Twisted, Tornado, Tulip, libevent, libuv, ZeroMQ,
node.js …
• All single-threaded, all use non-blocking sockets
• Event loop ties everything together
o It’s literally an endless loop that runs until program termination
o Calls an I/O multiplexing method upon each “run” of the loop
• epoll/kqueue preferred, fallback to poll, then select
o Enumerate entire set of file descriptors
• Data ready for reading without blocking? Great!
o read() it, then invoke the relevant protocol.data_received()
• Data can be written without blocking? Great! Write it!
• Nothing to do? Fine, skip to the next file descriptor.