1Net::DBus::Reactor(3) User Contributed Perl DocumentationNet::DBus::Reactor(3)
2
3
4

NAME

6       Net::DBus::Reactor - application event loop
7

SYNOPSIS

9       Create and run an event loop:
10
11          use Net::DBus::Reactor;
12          my $reactor = Net::DBus::Reactor->main();
13
14          $reactor->run();
15
16       Manage some file handlers
17
18          $reactor->add_read($fd,
19                             Net::DBus::Callback->new(method => sub {
20                                my $fd = shift;
21                                ...read some data...
22                             }, args => [$fd]);
23
24          $reactor->add_write($fd,
25                              Net::DBus::Callback->new(method => sub {
26                                 my $fd = shift;
27                                 ...write some data...
28                              }, args => [$fd]);
29
30       Temporarily (dis⎪en)able a handle
31
32          # Disable
33          $reactor->toggle_read($fd, 0);
34          # Enable
35          $reactor->toggle_read($fd, 1);
36
37       Permanently remove a handle
38
39          $reactor->remove_read($fd);
40
41       Manage a regular timeout every 100 milliseconds
42
43          my $timer = $reactor->add_timeout(100,
44                                            Net::DBus::Callback->new(
45                     method => sub {
46                        ...process the alarm...
47                     }));
48
49       Temporarily (dis⎪en)able a timer
50
51          # Disable
52          $reactor->toggle_timeout($timer, 0);
53          # Enable
54          $reactor->toggle_timeout($timer, 1);
55
56       Permanently remove a timer
57
58          $reactor->remove_timeout($timer);
59
60       Add a post-dispatch hook
61
62          my $hook = $reactor->add_hook(Net::DBus::Callback->new(
63                method => sub {
64                   ... do some work...
65                }));
66
67       Remove a hook
68
69          $reactor->remove_hook($hook);
70

DESCRIPTION

72       This class provides a general purpose event loop for the purposes of
73       multiplexing I/O events and timeouts in a single process. The underly‐
74       ing implementation is done using the select system call. File handles
75       can be registered for monitoring on read, write and exception
76       (out-of-band data) events. Timers can be registered to expire with a
77       periodic frequency. These are implemented using the timeout parameter
78       of the select system call.  Since this parameter merely represents an
79       upper bound on the amount of time the select system call is allowed to
80       sleep, the actual period of the timers may vary. Under normal load this
81       variance is typically 10 milliseconds.  Finally, hooks may be regis‐
82       tered which will be invoked on each iteration of the event loop (ie
83       after processing the file events, or timeouts indicated by the select
84       system call returning).
85

METHODS

87       my $reactor = Net::DBus::Reactor->new();
88           Creates a new event loop ready for monitoring file handles, or gen‐
89           erating timeouts. Except in very unsual circumstances (examples of
90           which I can't think up) it is not neccessary or desriable to
91           explicitly create new reactor instances. Instead call the main
92           method to get a handle to the singleton instance.
93
94       $reactor = Net::DBus::Reactor->main;
95           Return a handle to the singleton instance of the reactor. This is
96           the recommended way of getting hold of a reactor, since it removes
97           the need for modules to pass around handles to their privately cre‐
98           ated reactors.
99
100       $reactor->manage($connection);
101       $reactor->manage($server);
102           Registers a "Net::DBus::Connection" or "Net::DBus::Server" object
103           for management by the event loop. This basically involves hooking
104           up the watch & timeout callbacks to the event loop.  For connec‐
105           tions it will also register a hook to invoke the "dispatch" method
106           periodically.
107
108       $reactor->run();
109           Starts the event loop monitoring any registered file handles and
110           timeouts. At least one file handle, or timer must have been regis‐
111           tered prior to running the reactor, otherwise it will immediately
112           exit. The reactor will run until all registered file handles, or
113           timeouts have been removed, or disabled. The reactor can be explic‐
114           itly stopped by calling the "shutdown" method.
115
116       $reactor->shutdown();
117           Explicitly shutdown the reactor after pending events have been pro‐
118           cessed.
119
120       $reactor->step();
121           Perform one iteration of the event loop, going to sleep until an
122           event occurs on a registered file handle, or a timeout occurrs.
123           This method is generally not required in day-to-day use.
124
125       $reactor->add_read($fd, $callback[, $status]);
126           Registers a file handle for monitoring of read events. The $call‐
127           back parameter specifies an instance of the "Net::DBus::Callback"
128           object to invoke each time an event occurs. The optional $status
129           parameter is a boolean value to specify whether the watch is ini‐
130           tially enabled.
131
132       $reactor->add_write($fd, $callback[, $status]);
133           Registers a file handle for monitoring of write events. The $call‐
134           back parameter specifies an instance of the "Net::DBus::Callback"
135           object to invoke each time an event occurs. The optional $status
136           parameter is a boolean value to specify whether the watch is ini‐
137           tially enabled.
138
139       $reactor->add_exception($fd, $callback[, $status]);
140           Registers a file handle for monitoring of exception events. The
141           $callback parameter specifies an instance of the "Net::DBus::Call‐
142           back" object to invoke each time an event occurs. The optional
143           $status parameter is a boolean value to specify whether the watch
144           is initially enabled.
145
146       my $id = $reactor->add_timeout($interval, $callback, $status);
147           Registers a new timeout to expire every $interval milliseconds. The
148           $callback parameter specifies an instance of the "Net::DBus::Call‐
149           back" object to invoke each time the timeout expires. The optional
150           $status parameter is a boolean value to specify whether the timeout
151           is initially enabled. The return parameter is a unique identifier
152           which can be used to later remove or disable the timeout.
153
154       $reactor->remove_timeout($id);
155           Removes a previously registered timeout specified by the $id param‐
156           eter.
157
158       $reactor->toggle_timeout($id, $status[, $interval]);
159           Updates the state of a previously registered timeout specifed by
160           the $id parameter. The $status parameter specifies whether the
161           timeout is to be enabled or disabled, while the optional $interval
162           parameter can be used to change the period of the timeout.
163
164       my $id = $reactor->add_hook($callback[, $status]);
165           Registers a new hook to be fired on each iteration of the event
166           loop. The $callback parameter specifies an instance of the
167           "Net::DBus::Callback" class to invoke. The $status parameter deter‐
168           mines whether the hook is initially enabled, or disabled.  The
169           return parameter is a unique id which should be used to later
170           remove, or disable the hook.
171
172       $reactor->remove_hook($id)
173           Removes the previously registered hook identified by $id.
174
175       $reactor->toggle_hook($id[, $status])
176           Updates the status of the previously registered hook identified by
177           $id. The $status parameter determines whether the hook is to be
178           enabled or disabled.
179
180       $reactor->remove_read($fd);
181       $reactor->remove_write($fd);
182       $reactor->remove_exception($fd);
183           Removes a watch on the file handle $fd.
184
185       $reactor->toggle_read($fd, $status);
186       $reactor->toggle_write($fd, $status);
187       $reactor->toggle_exception($fd, $status);
188           Updates the status of a watch on the file handle $fd.  The $status
189           parameter species whether the watch is to be enabled or disabled.
190

SEE ALSO

192       Net::DBus::Callback, Net::DBus::Connection, Net::DBus::Server
193

AUTHOR

195       Daniel Berrange <dan@berrange.com>
196
198       Copyright 2004 by Daniel Berrange
199
200
201
202perl v5.8.8                       2008-02-20             Net::DBus::Reactor(3)
Impressum