Yesterday during a quiet moment at the MSFT bash I was at I decided that I would like to see if it was possible to write a framework that had an event loop (a-la poll()/select()/epoll) yet could be made to run in either completely event-based mode (i.e. all flow control is in the event loop itself) - a "push" model where events get pushed to you, or a "pull" mode, where you ask for lines from the socket (like while (<$sock>) { process_line($_) }
) and process them one by one.
It worked. I used livejournal author Brad Fitzpatrick's Danga::Socket module (which implements either a poll() or epoll event loop depending on what is available on the host platform) and managed to design a framework that could do this. It's about 150 LOC so I won't post it here.
So now what's left to do is think about how I can integrate this into qpsmtpd so that I can have a completely event based system that works in both tcpserver mode and pure-event-based mode. Lots more work, but an interesting project nonetheless.
Re:Event::Lib
Matts on 2004-09-01T22:37:34
Yes, it looks neat. Except it doesn't do async file IO - you still need Linux::AIO for that. Plus Danga::Socket is pure perl (uses syscall() to call the kernel epoll functions!)