Search code examples
perlsip

Stop loop if sip register has response


Stop loop if sip register has response

can i stop this loop

if i get and response 404 403 or any .

How can I extract the server response to my registration attempt

$response = $ua->register(expires => 40000 , cb_final => sub {
    my ($what,%args)  = @_;
});
$ua->loop(5);

Solution

  • This should be doable by checking the code and using a stopvar, i.e. something like this:

    my $stopvar;
    $response = $ua->register(expires => 40000 , cb_final => sub {
        my ($what,%args)  = @_;
        # maybe check $args{code} in case of $what eq 'FAIL'
        $stopvar = 1;
    });
    $ua->loop(5, \$stopvar);