Net::DBus::Reactor(3)
πΈ NAME πΈ
Net::DBus::Reactor β application event loop. This is the Net::DBus::Reactor(3) page from the User Contributed Perl Documentation, and bestie, itβs literally the group chat for your I/O events π
β¨
β¨ SYNOPSIS β¨
okay so, create and run an event loop like this, no cap:
use Net::DBus::Reactor;
my $reactor = Net::DBus::Reactor->main();
$reactor->run();
Manage some file handlers β yes, this is the whole read/write callback situation π«Ά
$reactor->add_read($fd,
Net::DBus::Callback->new(method => sub {
my $fd = shift;
...read some data...
}, args => [$fd]));
$reactor->add_write($fd,
Net::DBus::Callback->new(method => sub {
my $fd = shift;
...write some data...
}, args => [$fd]));
Temporarily (dis|en)able a handle β lowkey iconic:
# Disable
$reactor->toggle_read($fd, 0);
# Enable
$reactor->toggle_read($fd, 1);
Permanently remove a handle:
$reactor->remove_read($fd);
Manage a regular timeout every 100 milliseconds β°
my $timer = $reactor->add_timeout(100,
Net::DBus::Callback->new(
method => sub {
...process the alarm...
}));
Temporarily (dis|en)able a timer:
# Disable
$reactor->toggle_timeout($timer, 0);
# Enable
$reactor->toggle_timeout($timer, 1);
Permanently remove a timer:
$reactor->remove_timeout($timer);
Add a post-dispatch hook πͺ
my $hook = $reactor->add_hook(Net::DBus::Callback->new(
method => sub {
... do some work...
}));
Remove a hook:
$reactor->remove_hook($hook);
π DESCRIPTION π
This class is your general purpose event loop bestie β it exists for multiplexing I/O events and timeouts in a single process β¨ The underlying implementation is done using the select system call. File handles can be registered for monitoring on read, write and exception (out-of-band data) events. Timers can be registered to expire with a periodic frequency. These are implemented using the timeout parameter of the select system call.
Since that parameter merely represents an upper bound on the amount of time the select system call is allowed to sleep, the actual period of the timers may vary. Under normal load this variance is typically 10 milliseconds. Finally, hooks may be registered which will be invoked on each iteration of the event loop (ie after processing the file events, or timeouts indicated by the select system call returning). periodt. π
π«Ά METHODS π«Ά
my $reactor = Net::DBus::Reactor->new();β Creates a new event loop ready for monitoring file handles, or generating timeouts. Except in very unusual circumstances (examples of which I canβt think up) it is not necessary or desirable to explicitly create new reactor instances. Instead call themainmethod to get a handle to the singleton instance.$reactor = Net::DBus::Reactor->main;β Return a handle to the singleton instance of the reactor. This is the recommended way of getting hold of a reactor, since it removes the need for modules to pass around handles to their privately created reactors. main character energy, honestly. π$reactor->manage($connection);and$reactor->manage($server);β Registers aNet::DBus::Binding::ConnectionorNet::DBus::Binding::Serverobject for management by the event loop. This basically involves hooking up the watch & timeout callbacks to the event loop. For connections it will also register a hook to invoke thedispatchmethod periodically.$reactor->run();β Starts the event loop monitoring any registered file handles and timeouts. At least one file handle, or timer must have been registered prior to running the reactor, otherwise it will immediately exit. The reactor will run until all registered file handles, or timeouts have been removed, or disabled. The reactor can be explicitly stopped by calling theshutdownmethod.
β οΈ fr fr, run() will bounce immediately if you didnβt register at least one file handle or timer first π
$reactor->shutdown();β Explicitly shutdown the reactor after pending events have been processed.$reactor->step();β Perform one iteration of the event loop, going to sleep until an event occurs on a registered file handle, or a timeout occurs. This method is generally not required in day-to-day use.$reactor->add_read($fd, $callback[, $status]);β Registers a file handle for monitoring of read events. The$callbackparameter specifies either a code reference to a subroutine, or an instance of theNet::DBus::Callbackobject to invoke each time an event occurs. The optional$statusparameter is a boolean value to specify whether the watch is initially enabled.$reactor->add_write($fd, $callback[, $status]);β Registers a file handle for monitoring of write events. The$callbackparameter specifies either a code reference to a subroutine, or an instance of theNet::DBus::Callbackobject to invoke each time an event occurs. The optional$statusparameter is a boolean value to specify whether the watch is initially enabled.$reactor->add_exception($fd, $callback[, $status]);β Registers a file handle for monitoring of exception events. The$callbackparameter specifies either a code reference to a subroutine, or an instance of theNet::DBus::Callbackobject to invoke each time an event occurs. The optional$statusparameter is a boolean value to specify whether the watch is initially enabled.my $id = $reactor->add_timeout($interval, $callback, $status);β Registers a new timeout to expire every$intervalmilliseconds. The$callbackparameter specifies either a code reference to a subroutine, or an instance of theNet::DBus::Callbackobject to invoke each time the timeout expires. The optional$statusparameter is a boolean value to specify whether the timeout is initially enabled. The return parameter is a unique identifier which can be used to later remove or disable the timeout. save that$id, bestie π$reactor->remove_timeout($id);β Removes a previously registered timeout specified by the$idparameter.$reactor->toggle_timeout($id, $status[, $interval]);β Updates the state of a previously registered timeout specified by the$idparameter. The$statusparameter specifies whether the timeout is to be enabled or disabled, while the optional$intervalparameter can be used to change the period of the timeout.my $id = $reactor->add_hook($callback[, $status]);β Registers a new hook to be fired on each iteration of the event loop. The$callbackparameter specifies either a code reference to a subroutine, or an instance of theNet::DBus::Callbackclass to invoke. The$statusparameter determines whether the hook is initially enabled, or disabled. The return parameter is a unique id which should be used to later remove, or disable the hook.$reactor->remove_hook($id)β Removes the previously registered hook identified by$id.$reactor->toggle_hook($id, $status)β Updates the status of the previously registered hook identified by$id. The$statusparameter determines whether the hook is to be enabled or disabled.$reactor->remove_read($fd);,$reactor->remove_write($fd);, and$reactor->remove_exception($fd);β Removes a watch on the file handle$fd.$reactor->toggle_read($fd, $status);,$reactor->toggle_write($fd, $status);, and$reactor->toggle_exception($fd, $status);β Updates the status of a watch on the file handle$fd. The$statusparameter specifies whether the watch is to be enabled or disabled.
π SEE ALSO π
Net::DBus::CallbackNet::DBus::ConnectionNet::DBus::Server
π AUTHOR π
Daniel Berrange <dan@berrange.com> β the icon behind the reactor π
Β©οΈ COPYRIGHT Β©οΈ
Copyright 2004-2011 by Daniel Berrange
xoxo, your Perl bestie π«Ά β this is the Net::DBus::Reactor(3) page from perl v5.42.0, dated 2019-12-17. slay, go multiplex some I/O π
π¦ where this page comes from
- opensuse-leap 16.0: perl-Net-DBus 1.2.0-160000.2.2 Β· GPL-2.0-or-later
- opensuse-leap 16.0: perl-Net-DBus 1.2.0-160000.2.2 Β· GPL-2.0-or-later
- opensuse-leap 16.0: perl-Net-DBus 1.2.0-160000.2.2 Β· GPL-2.0-or-later
- opensuse-leap 16.0: perl-Net-DBus 1.2.0-160000.2.2 Β· GPL-2.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms