Net::S...entloop(3pm)
π¦ Net::SIP::Dispatcher::Eventloop π
okay bestie, welcome to the little event loop that could β¨ this page lives in the User Contributed Perl Documentation corner of the manual, and it's all about Net::SIP::Dispatcher::Eventloop β a simple event loop made for Net::SIP::Dispatcher π
πΈ NAME πΈ
Net::SIP::Dispatcher::Eventloop β a simple event loop for Net::SIP::Dispatcher. that's it, that's the whole vibe π«Ά
β¨ SYNOPSIS β¨
my $loop = Net::SIP::Dispatcher::Eventloop->new;
$loop->addFD( $fd, $callback );
$loop->add_timer( 10,$callback );
$loop->loop;
like. look at her. four lines and she's running ππ
π§ DESCRIPTION π§
so this package implements a simple event loop π« it is not optimized for speed β no cap, she's not here for the benchmarks β but she's provided as a simple implementation in case your application doesn't have an event loop yet. girl is a starter loop, a beginner loop, a "we'll figure it out" loop ππΈ
and here's the fun part: because the eventloop object can be handed straight into the constructor of Net::SIP::Dispatcher, you're lowkey allowed to bring your own alternative implementation instead π as long as it implements the methods described on this page, you're golden. main character energy, honestly.
π CONSTRUCTOR π
newβ creates a new event loop and returns the created object. brand new loop, fresh out the box π
π METHODS π
π addFD (HANDLE, RW, CALLBACK, [NAME])
adds the file handle HANDLE to the event loop, so that CALLBACK gets triggered if HANDLE is readable (RW is 0) or writeable (RW is 1) π¦
instead of 0 and 1 you can also use the exported constants EV_READ and EV_WRITE β same thing, cuter names π
CALLBACK is a callback accepted by invoke_callback in Net::SIP::Util. and bestie, heads up: the callback will be invoked with HANDLE as an additional argument β¨
NAME can be used to aid debugging β it'll be shown in the debug messages once the FD gets ready π
if there was already a callback for HANDLE, it gets replaced by the new one. no drama, just a swap π
β οΈ IMPORTANT NOTE: CALLBACK gets triggered if HANDLE is readable inside the loop, not if HANDLE gets readable. unlike withEvent::Libor similar, the CALLBACK is not triggered by the edge, but by the level β likepoll(2)orselect(2). so if 2 bytes come in at the handle and you read only 1 byte in the callback, the callback gets triggered again for more data π you have to watch this if you want to integrate Net::SIP with your existing event loop. fr fr, don't get caught slipping.
π delFD (HANDLE, [RW])
if RW is 0 (EV_READ), no more checking for readability of HANDLE will be done. if RW is 1 (EV_WRITE), no more checking for writeability of HANDLE will be done πΈ
if RW is not given, it will remove HANDLE from the loop completely β i.e. for both read and write. full send, no leftovers π«Ά
π add_timer( WHEN, CALLBACK, [ REPEAT ] )
adds a timer which gets triggered at WHEN or "now + WHEN" β° depending on the value of WHEN, it gets interpreted as the number of seconds since 1970-01-01 (when it's really big) or as a relative time (when it's not that big). WHEN can be floating point for subseconds resolution β¨
CALLBACK is a callback accepted by invoke_callback in Net::SIP::Util. it gets invoked with the timer object (see later) as an additional argument, which has a method cancel for canceling the (repeating) timer π
REPEAT is the number of seconds between each invocation of the timer. if greater then 0 (subsection resolution possible), the callback will be called each REPEAT seconds, after it was called the first time at WHEN π
the method will return an object which has a method cancel which can be used to cancel the timer before it gets triggered (or gets triggered the next time in case of repeating timers) π
π looptime
returns the current loop time in subseconds resolution (using gettimeofday from Time::HiRes) β±οΈ
this is not the current time, but the time when the last event in the loop occurred β e.g. when the select(2) call returned π it's giving "last time something happened" energy, not "what time is it right now" energy.
π loop ( [ TIMEOUT, @STOPVAR ] )
the main loop, i.e. continuously checks timers and file handles for the events and calls callbacks π₯
if TIMEOUT is given, it will run the loop for at most TIMEOUT seconds, then the method will return. undefined TIMEOUT means that it will never return because of timeout, and TIMEOUT of 0 means that it will check all timers and handles only once and then return π (yes, 0 = one pass, undefined = forever. iconic, honestly.)
@STOPVAR is a list of scalar references. these scalars are expected to be changed from the callbacks, so it will check after each loop cycle β i.e. after all callbacks are called (timers and handles) β if any of these scalars is TRUE, in which case it will end the loop π
the behavior with STOPVAR cannot be found in most existing event loops. if you want to integrate Net::SIP with your own event loop you might simply wrap all callbacks given in addFD and add_timer in another callback which at the end checks the stopvars and terminates the 3rd-party loop in a loop-specific way π
π reset
this will remove any fd and timers and their associated callbacks from the loop π§Ή
this might be necessary to release ressources if the loop should be stopped and any ressources should be freed up immediately, instead of being implicitly freed up and end of program. spring cleaning, but for your event loop πΈβ¨
and that's the whole page, bestie π«Ά this one was rendered by perl v5.40.1 on 2025-12-07, in the User Contributed Perl Documentation section, filed under Net::S...entloop(3pm) β go forth and loop responsibly πππ¦
π¦ where this page comes from
- ubuntu resolute: libnet-sip-perl 0.840-1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu stonking: libnet-sip-perl 0.840-1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms