Sys::Virt::EventImpl3pm
Event loop implementation parent class
Overview
The "Sys::Virt::EventImpl" module represents the contract for integrating libvirt with an event loop. This package is abstract and intended to be subclassed to provide an actual implementation.
This module is new in 9.5.0. To use this module while also supporting pre-9.5.0 versions, could may consider the code below to set up inheritance.
package YourImpl;use strict;use warnings;BEGIN {if (require Sys::Virt::EventImpl) {eval "use parent 'Sys::Virt::EventImpl';";}else {eval "use parent 'Sys::Virt::Event';";}}
Event loop implementation
When implementing an event loop, the implementation must be a sub-class of the "Sys::Virt::EventImpl" class. It must override these functions:
- my $watch_id = $self->add_handle( $fd, $events, $callback, $opaque, $ff )
-
Registers
$callbackto be invoked for$eventson$fd. Use"_run_handle_callback"to do the actual invocation from the event loop (see "Callback helpers" below).Next to the events explicitly indicated by
$events,"Sys::Virt::Event::HANDLE_ERROR"and"Sys::Virt::Event::HANDLE_HANGUP"should always trigger the callback.Returns a positive integer
$watch_idor-1on error.
- $self->update_handle($watch_id, $events)
-
Replaces the events currencly triggering
$watch_idwith$events.
- my $ret = $self->remove_handle($watch_id)
-
Removes the
$callbackfrom the$fd.Returns
0on success or-1on failure.IMPORTANT This should also make sure that
"_free_callback_opaque"is called after this function has been executed: not doing so will prevent the connection from being garbage collected.
- my $timer_id = $self->add_timeout($frequency, $callback, $opaque, $ff)
- $self->update_timeout($timer_id, $frequency)
-
Replaces the interval on the timer with
$frequency.
- my $ret = $self->remove_timeout($timer_id)
-
Discards the timer.
Returns
0on success or-1on failure.IMPORTANT This should also make sure that
"_free_callback_opaque"is called after this function has been executed: not doing so will prevent the connection from being garbage collected.
Callback helpers
- $self->_run_handle_callback($watch_id, $fd, $events, $cb, $opaque)
-
A helper method for executing a callback in response to one of more
$eventson the file handle$fd. The$watchnumber is the unique identifier associated with the file descriptor. The$cband$opaqueparameters are the callback and data registered for the handle.
- $self->_run_timeout_callback($timer_id, $cb, $opaque)
-
A helper method for executing a callback in response to the expiry of a timeout identified by
$timer. The$cband$opaqueparameters are the callback and data registered for the timeout.
- $self->_free_callback_opaque($ff, $opaque)
-
A helper method for freeing the data associated with a callback. The
$ffand$opaqueparameters are the callback and data registered for the handle/timeout.IMPORTANT This helper must be called outside of any callbacks; that is after the
"remove_handle"or"remove_timeout"callbacks complete.
Releases
2 releases since Debian 13 (Trixie); the text changed 1 time.