52 |
my $rVecRef=shift; |
my $rVecRef=shift; |
53 |
my $wVecRef=shift; |
my $wVecRef=shift; |
54 |
my $eVecRef=shift; |
my $eVecRef=shift; |
55 |
|
my @cons=@Connections; |
56 |
map {$_->addHandleBits($rVecRef,$wVecRef,$eVecRef)} @Connections; |
map {$_->addHandleBits($rVecRef,$wVecRef,$eVecRef) if(defined($_)) } @cons; |
57 |
} |
} |
58 |
|
|
59 |
sub checkAllHandleBits { |
sub checkAllHandleBits { |
63 |
my $wVec=shift; |
my $wVec=shift; |
64 |
my $eVec=shift; |
my $eVec=shift; |
65 |
|
|
66 |
map {$_->checkHandleBits($rVec,$wVec,$eVec)} @Connections; |
my @cons=@Connections; |
67 |
|
map {$_->checkHandleBits($rVec,$wVec,$eVec) if(defined($_)) } @cons; |
68 |
} |
} |
69 |
|
|
70 |
sub connectionCount { |
sub connectionCount { |
77 |
map { $_->close(); } @cons; |
map { $_->close(); } @cons; |
78 |
} |
} |
79 |
|
|
80 |
|
sub listConnections { |
81 |
|
my $class=shift; |
82 |
|
my $list=''; |
83 |
|
foreach my $conn (@Connections) { |
84 |
|
$list .= $conn->{'socketFN'}.' '.$conn->{'ip'}.' '.$conn->{'type'}; |
85 |
|
if (exists($conn->{'subscriberID'})) { |
86 |
|
$list .= ' '.$conn->{'subscriberID'}; |
87 |
|
} |
88 |
|
$list .= "$::CRLF"; |
89 |
|
} |
90 |
|
$list; |
91 |
|
} |
92 |
|
|
93 |
|
sub describeConnWithFileNum { |
94 |
|
my $class=shift; |
95 |
|
my $filenum=shift; |
96 |
|
foreach my $conn (@Connections) { |
97 |
|
if ($conn->{'socketFN'}==$filenum) { |
98 |
|
my $ret = ""; |
99 |
|
if (exists($conn->{'socketFN'})) { |
100 |
|
$ret .= "socketFN: ".$conn->{'socketFN'}."$::CRLF"; |
101 |
|
} |
102 |
|
if (exists($conn->{'connectionStart'})) { |
103 |
|
$ret .= "connectionStart: ".$conn->{'connectionStart'}."$::CRLF"; |
104 |
|
} |
105 |
|
if (exists($conn->{'writeBuffer'})) { |
106 |
|
$ret .= "writeBuffer: ".$conn->{'writeBuffer'}."$::CRLF"; |
107 |
|
} |
108 |
|
if (exists($conn->{'readBuffer'})) { |
109 |
|
$ret .= "readBuffer: ".$conn->{'readBuffer'}."$::CRLF"; |
110 |
|
} |
111 |
|
if (exists($conn->{'bytesWritten'})) { |
112 |
|
$ret .= "bytesWritten: ".$conn->{'bytesWritten'}."$::CRLF"; |
113 |
|
} |
114 |
|
if (exists($conn->{'type'})) { |
115 |
|
$ret .= "type: ".$conn->{'type'}."$::CRLF"; |
116 |
|
} |
117 |
|
if (exists($conn->{'mode'})) { |
118 |
|
$ret .= "mode: ".$conn->{'mode'}."$::CRLF"; |
119 |
|
} |
120 |
|
if (exists($conn->{'ip'})) { |
121 |
|
$ret .= "ip: ".$conn->{'ip'}."$::CRLF"; |
122 |
|
} |
123 |
|
if (exists($conn->{'headerBuffer'})) { |
124 |
|
$ret .= "headerBuffer: ".$conn->{'headerBuffer'}."$::CRLF"; |
125 |
|
} |
126 |
|
if (exists($conn->{'messageCount'})) { |
127 |
|
$ret .= "messageCount: ".$conn->{'messageCount'}."$::CRLF"; |
128 |
|
} |
129 |
|
if (exists($conn->{'connectionStart'})) { |
130 |
|
$ret .= "age: ".(time-$conn->{'connectionStart'})."$::CRLF"; |
131 |
|
} |
132 |
|
if (exists($conn->{'connectionTimeLimit'})) { |
133 |
|
$ret .= "connectionTimeLimit: ".$conn->{'connectionTimeLimit'}."$::CRLF"; |
134 |
|
} |
135 |
|
if (exists($conn->{'useragent'})) { |
136 |
|
$ret .= "useragent: ".$conn->{'useragent'}."$::CRLF"; |
137 |
|
} |
138 |
|
if (exists($conn->{'subscriberID'})) { |
139 |
|
$ret .= "subscriberID: ".$conn->{'subscriberID'}."$::CRLF"; |
140 |
|
} |
141 |
|
return $ret; |
142 |
|
} |
143 |
|
} |
144 |
|
return -1; |
145 |
|
} |
146 |
|
|
147 |
|
sub destroyBadRequests { |
148 |
|
foreach my $conn (@Connections) { |
149 |
|
if (time-$conn->{'connectionStart'} > 30 && !exists($conn->{'subscriberID'}) && $conn->{'type'} eq 'Meteor::Subscriber') { |
150 |
|
&::syslog('debug',"Closing misbehaving subscriber %s",$conn->{'socketFN'}); |
151 |
|
$conn->close(); |
152 |
|
} |
153 |
|
} |
154 |
|
} |
155 |
|
|
156 |
############################################################################### |
############################################################################### |
157 |
# Factory methods |
# Factory methods |
158 |
############################################################################### |
############################################################################### |
173 |
# |
# |
174 |
my $self=shift->new(); |
my $self=shift->new(); |
175 |
|
|
176 |
|
$::Statistics->{'total_requests'}++; |
177 |
|
|
178 |
my $server=shift; |
my $server=shift; |
179 |
my $socket=$server->conSocket(); |
my $socket=$server->conSocket(); |
180 |
|
|
181 |
$self->{'socket'}=$socket; |
$self->{'socket'}=$socket; |
182 |
$self->{'socketFN'}=$socket->fileno(); |
$self->{'socketFN'}=$socket->fileno(); |
183 |
|
$self->{'connectionStart'}=time; |
184 |
|
|
185 |
$socket->setNonBlocking(); |
$socket->setNonBlocking(); |
186 |
|
|
187 |
$self->{'writeBuffer'}=''; |
$self->{'writeBuffer'}=''; |
188 |
$self->{'readBuffer'}=''; |
$self->{'readBuffer'}=''; |
189 |
|
$self->{'bytesWritten'}=0; |
190 |
|
$self->{'type'}=ref($self); |
191 |
|
$self->{'ip'}=$socket->{'connection'}->{'remoteIP'}; |
192 |
|
|
193 |
push(@Connections,$self); |
push(@Connections,$self); |
194 |
|
|
195 |
&::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'}); |
196 |
|
|
197 |
$self; |
$self; |
198 |
} |
} |
263 |
my $bytesRead=sysread($socket->{'handle'},$buffer,$MAX_READ_SIZE); |
my $bytesRead=sysread($socket->{'handle'},$buffer,$MAX_READ_SIZE); |
264 |
if(defined($bytesRead) && $bytesRead>0) |
if(defined($bytesRead) && $bytesRead>0) |
265 |
{ |
{ |
266 |
|
$::Statistics->{'total_inbound_bytes'}+=$bytesRead; |
267 |
$self->{'readBuffer'}.=$buffer; |
$self->{'readBuffer'}.=$buffer; |
268 |
while($self->{'readBuffer'}=~s/^([^\r\n]*)\r?\n//) |
while($self->{'readBuffer'}=~s/^([^\r\n]*)\r?\n//) |
269 |
{ |
{ |
274 |
{ |
{ |
275 |
# Connection closed |
# Connection closed |
276 |
$self->{'remoteClosed'}=1; |
$self->{'remoteClosed'}=1; |
277 |
$self->close(); |
$self->close(1, 'remoteClosed'); |
278 |
|
|
279 |
return; |
return; |
280 |
} |
} |
284 |
{ |
{ |
285 |
&::syslog('notice',"Connection closed: $!"); |
&::syslog('notice',"Connection closed: $!"); |
286 |
$self->{'remoteClosed'}=1; |
$self->{'remoteClosed'}=1; |
287 |
$self->close(); |
$self->close(1, 'remoteClosed'); |
288 |
|
|
289 |
return; |
return; |
290 |
} |
} |
302 |
|
|
303 |
if(defined($bytesWritten) && $bytesWritten>0) |
if(defined($bytesWritten) && $bytesWritten>0) |
304 |
{ |
{ |
305 |
|
$::Statistics->{'total_outbound_bytes'}+=$bytesWritten; |
306 |
|
$self->{'bytesWritten'}+=$bytesWritten; |
307 |
$self->{'writeBuffer'}=substr($self->{'writeBuffer'},$bytesWritten); |
$self->{'writeBuffer'}=substr($self->{'writeBuffer'},$bytesWritten); |
308 |
if(length($self->{'writeBuffer'})==0) |
if(length($self->{'writeBuffer'})==0) |
309 |
{ |
{ |
310 |
delete($self->{'writeBufferTimestamp'}); |
delete($self->{'writeBufferTimestamp'}); |
311 |
$self->close() if(exists($self->{'autoClose'})); |
$self->close(1) if(exists($self->{'autoClose'})); |
312 |
} |
} |
313 |
else |
else |
314 |
{ |
{ |
321 |
{ |
{ |
322 |
&::syslog('notice',"Connection closed: $!"); |
&::syslog('notice',"Connection closed: $!"); |
323 |
$self->{'remoteClosed'}=1; |
$self->{'remoteClosed'}=1; |
324 |
$self->close(); |
$self->close(1, 'remoteClosed'); |
325 |
|
|
326 |
return; |
return; |
327 |
} |
} |
362 |
# Remove connection from list of connections |
# Remove connection from list of connections |
363 |
# |
# |
364 |
my $idx=undef; |
my $idx=undef; |
365 |
for(my $i=0;$i<scalar(@Connections);$i++) |
my $numcon = scalar(@Connections); |
366 |
|
for(my $i=0;$i<$numcon;$i++) |
367 |
{ |
{ |
368 |
if($Connections[$i]==$self) |
if($Connections[$i]==$self) |
369 |
{ |
{ |
378 |
} |
} |
379 |
|
|
380 |
&::syslog('debug',"Closed %s for %s",ref($self),$self->{'socket'}->{'connection'}->{'remoteIP'}); |
&::syslog('debug',"Closed %s for %s",ref($self),$self->{'socket'}->{'connection'}->{'remoteIP'}); |
381 |
|
|
382 |
|
$self->didClose(); |
383 |
|
} |
384 |
|
|
385 |
|
sub didClose { |
386 |
} |
} |
387 |
|
|
388 |
1; |
1; |
|
############################################################################EOF |
|
389 |
|
############################################################################EOF |