--- googlecode.com/svn/trunk/Meteor/Connection.pm 2008/02/04 21:06:42 47 +++ googlecode.com/svn/trunk/Meteor/Connection.pm 2009/01/19 11:19:41 64 @@ -52,7 +52,6 @@ my $rVecRef=shift; my $wVecRef=shift; my $eVecRef=shift; - my @cons=@Connections; map {$_->addHandleBits($rVecRef,$wVecRef,$eVecRef) if(defined($_)) } @cons; } @@ -78,6 +77,82 @@ map { $_->close(); } @cons; } +sub listConnections { + my $class=shift; + my $list=''; + foreach my $conn (@Connections) { + $list .= $conn->{'socketFN'}.' '.$conn->{'ip'}.' '.$conn->{'type'}; + if (exists($conn->{'subscriberID'})) { + $list .= ' '.$conn->{'subscriberID'}; + } + $list .= "$::CRLF"; + } + $list; +} + +sub describeConnWithFileNum { + my $class=shift; + my $filenum=shift; + foreach my $conn (@Connections) { + if ($conn->{'socketFN'}==$filenum) { + my $ret = ""; + if (exists($conn->{'socketFN'})) { + $ret .= "socketFN: ".$conn->{'socketFN'}."$::CRLF"; + } + if (exists($conn->{'connectionStart'})) { + $ret .= "connectionStart: ".$conn->{'connectionStart'}."$::CRLF"; + } + if (exists($conn->{'writeBuffer'})) { + $ret .= "writeBuffer: ".$conn->{'writeBuffer'}."$::CRLF"; + } + if (exists($conn->{'readBuffer'})) { + $ret .= "readBuffer: ".$conn->{'readBuffer'}."$::CRLF"; + } + if (exists($conn->{'bytesWritten'})) { + $ret .= "bytesWritten: ".$conn->{'bytesWritten'}."$::CRLF"; + } + if (exists($conn->{'type'})) { + $ret .= "type: ".$conn->{'type'}."$::CRLF"; + } + if (exists($conn->{'mode'})) { + $ret .= "mode: ".$conn->{'mode'}."$::CRLF"; + } + if (exists($conn->{'ip'})) { + $ret .= "ip: ".$conn->{'ip'}."$::CRLF"; + } + if (exists($conn->{'headerBuffer'})) { + $ret .= "headerBuffer: ".$conn->{'headerBuffer'}."$::CRLF"; + } + if (exists($conn->{'messageCount'})) { + $ret .= "messageCount: ".$conn->{'messageCount'}."$::CRLF"; + } + if (exists($conn->{'connectionStart'})) { + $ret .= "age: ".(time-$conn->{'connectionStart'})."$::CRLF"; + } + if (exists($conn->{'connectionTimeLimit'})) { + $ret .= "connectionTimeLimit: ".$conn->{'connectionTimeLimit'}."$::CRLF"; + } + if (exists($conn->{'useragent'})) { + $ret .= "useragent: ".$conn->{'useragent'}."$::CRLF"; + } + if (exists($conn->{'subscriberID'})) { + $ret .= "subscriberID: ".$conn->{'subscriberID'}."$::CRLF"; + } + return $ret; + } + } + return -1; +} + +sub destroyBadRequests { + foreach my $conn (@Connections) { + if (time-$conn->{'connectionStart'} > 30 && !$conn->{'autoClose'} && !exists($conn->{'subscriberID'}) && $conn->{'type'} eq 'Meteor::Subscriber') { + &::syslog('debug',"Closing misbehaving subscriber %s",$conn->{'socketFN'}); + $conn->close(); + } + } +} + ############################################################################### # Factory methods ############################################################################### @@ -105,17 +180,19 @@ $self->{'socket'}=$socket; $self->{'socketFN'}=$socket->fileno(); + $self->{'connectionStart'}=time; $socket->setNonBlocking(); $self->{'writeBuffer'}=''; $self->{'readBuffer'}=''; - $self->{'bytesWritten'}=0; + $self->{'type'}=ref($self); + $self->{'ip'}=$socket->{'connection'}->{'remoteIP'}; push(@Connections,$self); - &::syslog('debug',"New %s for %s",ref($self),$socket->{'connection'}->{'remoteIP'}); + &::syslog('debug',"New %s for %s using file number %s",ref($self),$self->{'ip'},$self->{'socketFN'}); $self; } @@ -197,7 +274,7 @@ { # Connection closed $self->{'remoteClosed'}=1; - $self->close(); + $self->close(1, 'remoteClosed'); return; } @@ -207,7 +284,7 @@ { &::syslog('notice',"Connection closed: $!"); $self->{'remoteClosed'}=1; - $self->close(); + $self->close(1, 'remoteClosed'); return; } @@ -231,7 +308,7 @@ if(length($self->{'writeBuffer'})==0) { delete($self->{'writeBufferTimestamp'}); - $self->close() if(exists($self->{'autoClose'})); + $self->close(1) if(exists($self->{'autoClose'})); } else { @@ -244,7 +321,7 @@ { &::syslog('notice',"Connection closed: $!"); $self->{'remoteClosed'}=1; - $self->close(); + $self->close(1, 'remoteClosed'); return; } @@ -285,7 +362,8 @@ # Remove connection from list of connections # my $idx=undef; - for(my $i=0;$i