<html><head><meta http-equiv="Content-Type" content="text/html charset=windows-1252"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;">On Mar 14, 2014, at 9:32 AM, Daniel P. Berrange <<a href="mailto:berrange@redhat.com">berrange@redhat.com</a>> wrote:<br><div><blockquote type="cite"><div style="font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;">- Register and run your own event loop impl by calling the method<br>  Sys::Virt::Event::register(), passing in a custom subclass of<br>  the Sys::Virt::Event class. This is what you should do to integrate<br>  with existing event loop impls like AnyEvent.<br><br>If you're set on using AnyEvent, then you want todo option 2 here. There's<br>no particularly good docs or example code here, but you can see how todo<br>this by looking at the Perl test suite. eg the t/800-events.t file. This </div></blockquote><blockquote type="cite"><div style="font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;">test suite does a pure perl event loop based on select(). </div></blockquote><div><br></div><div>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:</div><div><br></div><div><div>   my $n = select($ro=$ri,$wo=$wi,$eo=$ei,</div><div>                   (defined $timeout ? ($timeout ? $timeout/1000 : 0) : undef));</div></div><div><br></div><div>should be:</div><div><br></div><div><div>   my $n = select($ro=$ri,$wo=$wi,$eo=$ei,</div><div>                   (defined $timeout ? ($timeout ? $timeout/1000 : 0) : 0));</div></div><div><br></div><div>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?).</div><br><blockquote type="cite"><div style="font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;">You’d probably want to adapt that and call into AnyEvent, instead of select().<br>The add_handle/remove_handle/update_handle/add_timeout/update_timeout/<br>remove_timeout methods should all call into appropriate AnyEvent APIs.<br>Then you just need to run AnyEvent as normal.<br></div></blockquote><div><br></div><div>Sounds good; if I can get something cleaner than this:</div><div><br></div></div><blockquote style="margin: 0 0 0 40px; border: none; padding: 0px;"><div><div><div>while (! $quit) {</div></div></div><div><div><div>    EV::run EV::RUN_ONCE;</div></div></div><div><div><div>    $ev->run_once();  ## $ev is an instance of Sys::Virt::Event subclass</div></div></div><div><div><div>}</div></div></div></blockquote><div><div><div><br></div><div>I’ll be sure to share it. Thanks again.</div></div><br></div><div>Scott</div><br></body></html>