TT#24097 Rework perl code flow

- Avoid comma-separated statements.
- Avoid mixed boolean operators, and use proper code flow keywords.

Change-Id: Iec4c85a3d39fe94ba7b9f293dc158892ae7d9577
changes/16/16716/4
Guillem Jover 8 years ago
parent cff9d296fd
commit 0bdc116387

@ -596,17 +596,17 @@ sub stun_handler_binding_success {
sub check_to_nominate {
my ($self) = @_;
$self->{controlling} or return;
$self->{start_nominating} && time() < $self->{start_nominating} and return;
$self->{nominate} and return;
@{$self->{triggered_checks}} and return;
return unless $self->{controlling};
return if $self->{start_nominating} && time() < $self->{start_nominating};
return if $self->{nominate};
return if @{$self->{triggered_checks}};
my @succeeded;
for my $pair (values(%{$self->{candidate_pairs}})) {
my @comps = @{$pair->{components}};
my @succeeded_comps = grep {$_->{state} eq 'succeeded'} @comps;
@succeeded_comps < $self->{components} and next;
next if @succeeded_comps < $self->{components};
$self->debug("got fully succeeded pair $pair->{foundation}\n");
push(@succeeded, $pair);
}
@ -753,7 +753,8 @@ sub timer {
# run checks
defined($self->{other_ufrag}) && defined($self->{other_pwd}) or return; # not enough info
# not enough info
return if !defined($self->{other_ufrag}) || !defined($self->{other_pwd});
if (my $pair = shift(@{$self->{triggered_checks}})) {
$pair->debug("running triggered check\n");

@ -62,7 +62,10 @@ sub send_rcv {
recv($recvfd, $inc, length($pkt), 0);
alarm(0);
}
$inc eq $pkt or print("NOT received packed ok\n"), return;
if ($inc ne $pkt) {
print("NOT received packed ok\n");
return;
}
print("received packet ok\n");
}

@ -65,7 +65,10 @@ sub send_rcv {
$addr = recv($recvfd, $inc, length($pkt), 0);
alarm(0);
}
$inc eq $pkt or print("did NOT receive packet\n"), return;
if ($inc ne $pkt) {
print("did NOT receive packet\n");
return;
}
my ($port, $ip) = sockaddr_in($addr);
$laddr = getsockname($recvfd);
($lport, $lip) = sockaddr_in($laddr);

@ -50,7 +50,7 @@ local $SIG{ALRM} = sub { print "alarm!\n"; };
setrlimit(RLIMIT_NOFILE, 8000, 8000);
$PROTOS and $PROTOS = [split(/\s*[,;:]+\s*/, $PROTOS)];
$PROTOS && @$PROTOS == 1 and $$PROTOS[1] = $$PROTOS[0];
$$PROTOS[1] = $$PROTOS[0] if $PROTOS && @$PROTOS == 1;
$DEST and $DEST = [$DEST =~ /^(?:([a-z.-]+)(?::(\d+))?|([\d.]+)(?::(\d+))?|([\da-f:]+)|\[([\da-f:]+)\]:(\d+))$/si];
my $dest_host = $$DEST[0] || $$DEST[2] || $$DEST[4] || $$DEST[5] || 'localhost';
my $dest_port = $$DEST[1] || $$DEST[3] || $$DEST[6] || 2223;
@ -86,8 +86,14 @@ sub msg {
my @dests = getaddrinfo($dest_host, $dest_port, AF_UNSPEC, SOCK_DGRAM);
while (@dests >= 5) {
my ($fam, $type, $prot, $addr, $canon, @dests) = @dests;
socket($fd, $fam, $type, $prot) or undef($fd), next;
connect($fd, $addr) or undef($fd), next;
if (!socket($fd, $fam, $type, $prot)) {
undef($fd);
next;
}
if (!connect($fd, $addr)) {
undef($fd);
next;
}
last;
}
$fd or die($!);
@ -106,7 +112,7 @@ sub send_receive {
alarm(1);
recv($receive_fd, $x, 0xffff, 0) or $err = "$!";
alarm(0);
$err && $err !~ /interrupt/i and die $err;
die $err if $err && $err !~ /interrupt/i;
return $x;
}
@ -403,7 +409,7 @@ sub do_rtp {
$KEEPGOING or undef($c);
}
$NOENC and $repl = $expect;
!$repl && $KEEPGOING and next;
next if !$repl && $KEEPGOING;
$repl eq $expect or die hexdump($repl, $expect) . " $$trans{name} > $$trans_o{name}, $$c{callid}, RTP port $$outputs[$j][0]";
$rtcp or next;
@ -421,7 +427,7 @@ sub do_rtp {
$dst = $$pr{sockaddr}($dstport, $addr);
$repl = send_receive($sendfd, $expfd, $payload, $dst);
$NOENC and $repl = $expect;
!$repl && $KEEPGOING and next;
next if !$repl && $KEEPGOING;
$repl eq $expect or die hexdump($repl, $expect) . " $$trans{name} > $$trans_o{name}, $$c{callid}, RTCP";
}
}
@ -614,12 +620,12 @@ c=IN $$pr{family_str} $$ips_t[0]
t=0 0
SDP
my $ul = $$A{num_streams};
$op eq 'answer' && $$A{streams_seen} < $$A{num_streams}
and $ul = $$A{streams_seen};
$ul = $$A{streams_seen} if $op eq 'answer' && $$A{streams_seen} < $$A{num_streams};
$$A{want_bundle} && $op eq 'offer' and
$$A{bundle} = 1,
if ($$A{want_bundle} && $op eq 'offer') {
$$A{bundle} = 1;
$sdp .= "a=group:BUNDLE " . join(' ', (0 .. $ul)) . "\n";
}
for my $i (0 .. $ul) {
my $bi = $i;
@ -628,8 +634,7 @@ SDP
my $p = $$ports_t[$bi];
my $cp = $p + 1;
$$A{bundle} && $$A{want_rtcpmux} && $op eq 'offer'
and $cp = $p;
$cp = $p if $$A{bundle} && $$A{want_rtcpmux} && $op eq 'offer';
$sdp .= <<"SDP";
m=audio $p $$tr{name} 0 8 111
@ -749,7 +754,10 @@ sub answer {
}
for my $iter (1 .. $NUM) {
($iter % 10 == 0) and print("$iter calls established\n"), do_rtp();
if ($iter % 10 == 0) {
print("$iter calls established\n");
do_rtp();
}
my $c = {};
offer($c, 0, 1);

@ -75,7 +75,7 @@ sub do_rtp {
alarm(1);
recv($$fds[$b], $x, 0xffff, 0) or $err = "$!";
alarm(0);
$err && $err !~ /interrupt/i and die $err;
die $err if $err && $err !~ /interrupt/i;
if (($x || '') ne $payload) {
warn("no rtp reply received, ports $$outputs[$b][0] and $$outputs[$a][0]");
$KEEPGOING or undef($c);
@ -162,7 +162,10 @@ sub update_lookup {
}
for my $iter (1 .. $NUM) {
($iter % 10 == 0) and print("$iter\n"), do_rtp();
if ($iter % 10 == 0) {
print("$iter\n");
do_rtp();
}
my $c = [];
update_lookup($c, 0);
@ -200,7 +203,7 @@ if (!$NODEL) {
for my $c (@calls) {
$c or next;
my ($tags, $callid) = @$c[3,5];
$BRANCHES && rand() < .3 and $callid =~ s/;.*//;
$callid =~ s/;.*// if $BRANCHES && rand() < .3;
msg("D $callid $$tags[0] $$tags[1]");
}
}

@ -13,8 +13,14 @@ my $fd;
my @dests = getaddrinfo($ip, $port, AF_UNSPEC, SOCK_DGRAM);
while (@dests >= 5) {
my ($fam, $type, $prot, $addr, $canon, @dests) = @dests;
socket($fd, $fam, $type, $prot) or undef($fd), next;
connect($fd, $addr) or undef($fd), next;
if (!socket($fd, $fam, $type, $prot)) {
undef($fd);
next;
}
if (!connect($fd, $addr)) {
undef($fd);
next;
}
last;
}
$fd or die($!);

@ -54,14 +54,29 @@ while (1) {
}
next;
}
$cmd == 1 or print("not stun request\n"), next;
length($attrs) == $len or print("length mismatch\n"), next;
if ($cmd != 1) {
print("not stun request\n")
next;
}
if (length($attrs) != $len) {
print("length mismatch\n")
next;
}
my ($list, $hash) = unpack_attrs($attrs);
$$list[$#$list]{name} eq 'fingerprint' or print("last attr not fingerprint\n"), next;
$$list[$#$list-1]{name} eq 'message-integrity' or print("last but one attr not MI\n"), next;
$$hash{username} or print("no username\n"), next;
if ($$list[$#$list]{name} ne 'fingerprint') {
print("last attr not fingerprint\n");
next;
}
if ($$list[$#$list-1]{name} ne 'message-integrity') {
print("last but one attr not MI\n")
next;
}
unless ($$hash{username}) {
print("no username\n")
next;
}
$$hash{controlling} and print("is controlling\n");
$$hash{controlled} and print("is controlled\n");

@ -62,8 +62,8 @@ for my $x (split(/,/, 'origin,session connection')) {
defined($options{'replace-' . $x}) and push(@{$packet{replace}}, $x);
}
for my $x (split(/,/, 'rtcp-mux,SDES')) {
defined($options{$x}) && ref($options{$x}) eq 'ARRAY'
and $packet{$x} = $options{$x};
$packet{$x} = $options{$x}
if defined($options{$x}) && ref($options{$x}) eq 'ARRAY';
}
if (defined($options{direction})) {
$options{direction} =~ /(.*),(.*)/ or die;

Loading…
Cancel
Save