NAME
AnyEvent::SIP - Fusing together AnyEvent and Net::SIP
VERSION
version 0.001
SYNOPSIS
# regular Net::SIP syntax
use AnyEvent::SIP;
use Net::SIP::Simple;
my $stopvar;
my $ua = Net::SIP::Simple->new(...);
my $call = $uac->invite(
'you.uas@example.com',
cb_final => sub { $stopvar++ },
);
# wait for $stopvar, 5 second timeout
$ua->loop( 5, \$stopvar );
# AnyEvent-style
use AnyEvent::SIP;
use Net::SIP::Simple;
my $cv = AE::cv;
my $ua = Net::SIP::Simple->new(...);
my $call = $uac->invite(
'you.uas@example.com',
cb_final => sub { $cv->send },
);
$cv->recv;
DESCRIPTION
This module allows you to use AnyEvent as the event loop (and thus any
other supported event loop) for Net::SIP.
Net::SIP::Simple allows you to define the event loop. You can either
define it using Net::SIP::Dispatcher::AnyEvent manually or you can
simply use AnyEvent::SIP which will automatically set it for you.
# doing it automatically and globally
use AnyEvent::SIP;
use Net::SIP::Simple;
my $cv = AE::cv;
my $ua = Net::SIP::Simple->new(...);
$ua->register( cb_final => sub { $cv->send } );
$cv->recv;
# defining it for a specific object
use Net::SIP::Simple;
use Net::SIP::Dispatcher::AnyEvent;
my $cv = AE::cv;
my $ua = Net::SIP::Simple->(
...
loop => Net::SIP::Dispatcher::AnyEvent->new,
);
$ua->register;
$cv->recv;
You can also call Net::SIP's "loop" method in order to keep it as close
as possible to the original syntax. This will internally use AnyEvent,
whether you're using AnyEvent::SIP globally or
Net::SIP::Dispatcher::AnyEvent locally.
use AnyEvent::SIP;
use Net::SIP::Simple;
my $stopvar;
my $ua = Net::SIP::Simple->new(...);
$ua->register( cb_final => sub { $stopvar++ } );
# call Net::SIP's event loop runner,
# which calls AnyEvent's instead
$ua->loop( 1, \$stopvar );
WARNING
Net::SIP requires dispatchers (event loops) to check their stopvars
(condition variables) every single iteration of the loop. In my opinion,
it's a wasteful and heavy operation. When it comes to loops like EV,
they run a lot of cycles, and it's probably not very effecient. Take
that under advisement.
I would happily accept any suggestions on how to improve this.
Meanwhile, we're using AnyEvent::AggressiveIdle.
AUTHOR
Sawyer X <xsawyerx@cpan.org>
COPYRIGHT AND LICENSE
This software is copyright (c) 2013 by Sawyer X.
This is free software; you can redistribute it and/or modify it under
the same terms as the Perl 5 programming language system itself.