[libvirt-users] Sys::Virt integration into other event loops

Scott Wiersdorf scott at betterservers.com
Fri Mar 14 20:18:45 UTC 2014


On Mar 14, 2014, at 9:32 AM, Daniel P. Berrange <berrange at redhat.com> wrote:
> - Register and run your own event loop impl by calling the method
>   Sys::Virt::Event::register(), passing in a custom subclass of
>   the Sys::Virt::Event class. This is what you should do to integrate
>   with existing event loop impls like AnyEvent.
> 
> If you're set on using AnyEvent, then you want todo option 2 here. There's
> no particularly good docs or example code here, but you can see how todo
> this by looking at the Perl test suite. eg the t/800-events.t file. This
> test suite does a pure perl event loop based on select(). 

Yes, I’ve used this file as a reference and implemented a Sys::Virt::Event subclass—works fine. I had to make one little change to make it not block:

   my $n = select($ro=$ri,$wo=$wi,$eo=$ei,
                   (defined $timeout ? ($timeout ? $timeout/1000 : 0) : undef));

should be:

   my $n = select($ro=$ri,$wo=$wi,$eo=$ei,
                   (defined $timeout ? ($timeout ? $timeout/1000 : 0) : 0));

because the 'undef' will cause select() to block until there’s something readable. On our systems, this seems to be every 4 seconds for some reason (is there a 4 second timeout in libvirt itself?).

> You’d probably want to adapt that and call into AnyEvent, instead of select().
> The add_handle/remove_handle/update_handle/add_timeout/update_timeout/
> remove_timeout methods should all call into appropriate AnyEvent APIs.
> Then you just need to run AnyEvent as normal.

Sounds good; if I can get something cleaner than this:

while (! $quit) {
    EV::run EV::RUN_ONCE;
    $ev->run_once();  ## $ev is an instance of Sys::Virt::Event subclass
}

I’ll be sure to share it. Thanks again.

Scott

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://listman.redhat.com/archives/libvirt-users/attachments/20140314/7df37c2d/attachment.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 496 bytes
Desc: Message signed with OpenPGP using GPGMail
URL: <http://listman.redhat.com/archives/libvirt-users/attachments/20140314/7df37c2d/attachment.sig>


More information about the libvirt-users mailing list