Net-DNS-Dig
view release on metacpan or search on metacpan
my $nbfound = select($rout=$rin,$wout=$win,undef,1);
if ($nbfound > 0) { # if there is work
if ($rout) {
if ($rsin = recv($remotsock,$buffer,PACKETSZ,0)) {
push @wmsglen, length($buffer);
push @wmsg, $buffer;
push @who, $rsin;
}
}
if ($wout && @wmsg) { # if there is work
unless ($woff) { # if not busy
$wmsglen = $wmsglen[0];
}
if ($wlen = send($remotsock,$wmsg[0],0,$who[0])) {
$wmsglen -= $wlen;
$woff += $wlen;
# udp messages should always be sent in one transmission
unless ($wmsglen > 0) { # if buffer empty
$woff = 0;
shift @wmsglen;
shift @wmsg;
t/tcp_rw_stream.t view on Meta::CPAN
$client = $cfileno = undef;
}
}
if ($rout && $client && vec($rout,$cfileno,1)) {
if ($rlen = sysread($client,$buffer,65535,0)) {
push @wmsglen, $rlen;
push @wmsg, $buffer;
}
}
if ($wout && @wmsg) { # if there is work
unless ($woff) { # if not busy
$wmsglen = $wmsglen[0];
}
if ($wlen = syswrite($client,$wmsg[0],$wmsglen,$woff)) {
$wmsglen -= $wlen;
$woff += $wlen;
unless ($wmsglen > 0) { # if buffer empty
$woff = 0;
shift @wmsglen;
shift @wmsg;
$client = $cfileno = undef;
}
}
if ($rout && $client && vec($rout,$cfileno,1)) {
if ($rlen = sysread($client,$buffer,65535,0)) {
push @wmsglen, $rlen;
push @wmsg, $buffer;
}
}
if ($wout && @wmsg) { # if there is work
unless ($woff) { # if not busy
$wmsglen = $wmsglen[0];
}
if ($wlen = syswrite($client,$wmsg[0],$wmsglen,$woff)) {
$wmsglen -= $wlen;
$woff += $wlen;
unless ($wmsglen > 0) { # if buffer empty
$woff = 0;
shift @wmsglen;
shift @wmsg;
( run in 0.307 second using v1.01-cache-2.11-cpan-3cd7ad12f66 )