open($L,">>$log");
print $L join(' ',@_)."\n";
close($L);
}
### /client
###########################################################
O_daemon:
$URL=shift(@ARGV)||$URL;
&daemon(@ARGV);
sub parsehost{
my ($h,@hh)=@_;
$h=~s/^(.*?)\:\/\//$hh[0]=lc($1);''/se;
$h=~s/^(.*?)(\/.*$)/$hh[3]=$2;$1/se;
$h=~s/^(.*?)(\:.*$)/$hh[2]=substr($2,1);$1/se;
$hh[4]=sockaddr_in($hh[2],$hh[5]=inet_aton($hh[1])) if($preresolve);
$hh[1]=$h;
@hh
}
sub cgi_proxy{do $cgi_proxy}
sub timeouts{
setsockopt($_[0],SOL_SOCKET,SO_RCVTIMEO,pack('LL',$_[1],0))&&
setsockopt($_[0],SOL_SOCKET,SO_SNDTIMEO,pack('LL',$_[2],0))
}
sub CNT{
defined($LIM[$_[0]])||return;
my $x;
(print($CLW wrx(($_[0]<<1)+($_[1]>0))) &&
defined($x=rdx($CLR[($_[1]>0)+0])))
||($_[1]<0 && exit);
$x
}
sub ex{
for(0..$_[0]){CNT($_,-1)}
for($MR,$CLW,@MW,@CLR){close($_)}
exit
}
sub daemon{
$SIG{CHLD}='IGNORE';
my $s;
my $xsz=length(wrx(0));
open($F,"<$cgi_proxy")||die("Preloading \"$cgi_proxy\"");
eval("*cgi_proxy=sub\{".ffread($F)."\n\};");
close($F);
if($#_!=-1){
fork&&exit;
print "$$\n";
close(STDOUT);close(STDIN);close(STDERR);
}
pipe($MR,$CLW);select($CLW);$|=1;
for(0,1){pipe($CLR[$_],$MW[$_]);select($MW[$_]);$|=1}
select(STDOUT);
my $i;
my @prox=$proxy?parsehost($proxy,'http','127.0.0.1','3128'):();
$prox[0]=lc($prox[0]);
my $hprox=$prox[0] eq 'http'?"\nCache-Control: no-cache\nPragma: no-cache":'';
my @ad=my @h=parsehost($URL,'http','127.0.0.1','80','/');
if($proxy){
@ad=@prox;
$h[3]=$url if($prox[0] eq "http");
}
$LIM[0]=0;
for(0..$#_){$_&&($LIM[$_]=$_[$_])}
while(1){
if(!$CNT[0]){$CNT[0]++;fork||goto CONN}
my $w=$MW[my $x=($i=rdx($MR))&1];
$i>>=1;
if($x){
$CNT[$i]++;
$x=$LIM&&$CNT[$i]>$LIM[$i];
}else{
$CNT[$i]&&$CNT[$i]--;
if($x=!$CNT[$i]){
for(0..$#LIM){if($LIM[$_]&&$CNT[$_]>=$LIM[$_]){$x=0;last}}
if($x){$CNT[0]++;fork||goto CONN}
}
}
print $w wrx($x+0);
}
CONN:
$pid=0;
my ($header,$content,$IN,$part,$SO,$len,$WR,$WW,$wpid);
if($duplex){
pipe($WR,$WW);
select($WW);$|=1;select(STDOUT);
}
CONN1:
if($wpid){
=3= |