Re: Sys::Virt integration into other event loops

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Mar 14, 2014, at 9:32 AM, Daniel P. Berrange <berrange@xxxxxxxxxx> 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

Attachment: signature.asc
Description: Message signed with OpenPGP using GPGMail

_______________________________________________
libvirt-users mailing list
libvirt-users@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvirt-users

[Index of Archives]     [Virt Tools]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Yosemite News]     [KDE Users]

  Powered by Linux