nickandrew / LS30

Control software for LS-30 alarm system
11 stars 3 forks source link

Use AnyEvent as the event loop #8

Closed nickandrew closed 9 years ago

nickandrew commented 9 years ago

I'd started to write modules to do asynchronous I/O built around a select() loop for several years and included my work to date into LS30. Since then I found AnyEvent which does a much better job of it, so rewrite the event loop parts of LS30 using AnyEvent.

nickandrew commented 9 years ago

Work is in progress. I've got the proxy daemon running; just need to tidy the code. The ServerSocket class was able to be modified in a logical way to use AnyEvent while retaining almost identical API (which says to me that its API was very good in the first place).

I hacked AlarmDaemon::Controller to replace the ListenSocket and ClientSocket classes with direct calls to AnyEvent->io but this proved to be the wrong way to go about it when I got to ServerSocket and realised that ServerSocket is actually doing quite a lot which would be ugly to reimplement and I could do it by calling into the class handleRead function from an AnyEvent->io callback.

nickandrew commented 9 years ago

Nearly complete now. The daemon uses AnyEvent, and so do ordinary querying scripts which use LS30::Commander::sendCommand() to send a command and receive a response.