/[meteor]/googlecode.com/svn/trunk/Meteor/Subscriber.pm
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /googlecode.com/svn/trunk/Meteor/Subscriber.pm

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 49 by knops.gerd, Mon Feb 4 22:30:35 2008 UTC revision 50 by andrew.betts, Wed Feb 27 13:55:35 2008 UTC
# Line 80  sub deleteSubscriberWithID { Line 80  sub deleteSubscriberWithID {
80                    
81          if(exists($PersistentConnections{$id}))          if(exists($PersistentConnections{$id}))
82          {          {
83                  $PersistentConnections{$id}->close();                  $PersistentConnections{$id}->close(0,'newSubscriberWithSameID');
84          }          }
85  }  }
86    
# Line 136  sub processLine { Line 136  sub processLine {
136                  #                  #
137                  if($self->{'headerBuffer'}=~/GET\s+$::CONF{'SubscriberDynamicPageAddress'}\/([0-9a-z]+)\/([0-9a-z]+)\/(\S+)/i)                  if($self->{'headerBuffer'}=~/GET\s+$::CONF{'SubscriberDynamicPageAddress'}\/([0-9a-z]+)\/([0-9a-z]+)\/(\S+)/i)
138                  {                  {
139                          my $subscriberID=$1;                          $self->{'subscriberID'}=$1;
140                          $self->{'mode'}=$2;                          $self->{'mode'}=$2;
141                          my $persist=$self->getConf('Persist');                          my $persist=$self->getConf('Persist');
                           
142                          my $maxTime=$self->getConf('MaxTime');                          my $maxTime=$self->getConf('MaxTime');
143                          if($maxTime>0)                          $self->{'ConnectionTimeLimit'} = ($self->{'ConnectionStart'}+$maxTime) if ($maxTime>0);
                         {  
                                 $self->{'ConnectionTimeLimit'}=$self->{'ConnectionStart'}+$maxTime;  
                         }  
144                                                    
145                          my @channelData=split('/',$3);                          my @channelData=split('/',$3);
146                          my $channels={};                          my $channels={};
# Line 162  sub processLine { Line 158  sub processLine {
158                                          }                                          }
159                                  }                                  }
160                          }                          }
161                            my $useragent = ($self->{'headerBuffer'}=~/User-Agent: (.+)/i) ? $1 : "-";
162                                                    
163                          delete($self->{'headerBuffer'});                          delete($self->{'headerBuffer'});
164                                                    
165                          if($persist)                          if ($persist) {
166                          {                                  $self->deleteSubscriberWithID($self->{'subscriberID'});
167                                  $self->{'subscriberID'}=$subscriberID;                                  $PersistentConnections{$self->{'subscriberID'}}=$self;
                                 $self->deleteSubscriberWithID($subscriberID);  
                                 $PersistentConnections{$subscriberID}=$self;  
168                          }                          }
169                                                    
170                          if(scalar(keys %{$channels}))                          if(scalar(keys %{$channels}))
171                          {                          {
172                                  $self->emitOKHeader();                                  $self->emitOKHeader();
173                                  $self->setChannels($channels,$persist,$self->{'mode'},'');                                  $self->setChannels($channels,$persist,$self->{'mode'},$useragent);
174                                  $self->close(1) unless($persist);                                  $self->close(1, 'responseComplete') unless($persist);
175                                  return;                                  return;
176                          }                          }
177                  }                  }
# Line 184  sub processLine { Line 179  sub processLine {
179                  {                  {
180                          $self->deleteSubscriberWithID($1);                          $self->deleteSubscriberWithID($1);
181                          $self->emitOKHeader();                          $self->emitOKHeader();
182                          $self->close(1);                          $self->close(1, 'disconnectRequested');
183                          return;                          return;
184                  }                  }
185                  elsif($self->{'headerBuffer'}=~/GET\s+([^\s\?]+)/)                  elsif($self->{'headerBuffer'}=~/GET\s+([^\s\?]+)/)
186                  {                  {
187                          Meteor::Document->serveFileToClient($1,$self);                          Meteor::Document->serveFileToClient($1,$self);
188                          $self->close(1);                          $self->close(1, 'responseComplete');
189                          return;                          return;
190                  }                  }
191                                    
# Line 233  sub emitErrorHeader { Line 228  sub emitErrorHeader {
228          $::Statistics->{'errors_served'}++;          $::Statistics->{'errors_served'}++;
229                    
230          # close up shop here!          # close up shop here!
231          $self->close();          $self->close(0, 'error');
232  }  }
233    
234  sub emitHeader {  sub emitHeader {
# Line 276  sub sendMessages { Line 271  sub sendMessages {
271          my $self=shift;          my $self=shift;
272                    
273          my $numMessages=0;          my $numMessages=0;
274          my $msgTemplate=$self->getConf('Messagetemplate');          my $msgTemplate=$self->getConf('MessageTemplate');
275          my $msgData='';          my $msgData='';
276                    
277          foreach my $message (@_)          foreach my $message (@_)
# Line 298  sub sendMessages { Line 293  sub sendMessages {
293          my $maxMsg=$self->getConf('MaxMessages');          my $maxMsg=$self->getConf('MaxMessages');
294          if(defined($maxMsg) && $maxMsg>0 && $msgCount>=$maxMsg)          if(defined($maxMsg) && $maxMsg>0 && $msgCount>=$maxMsg)
295          {          {
296                  $self->close(1);                  $self->close(1, 'maxMessageCountReached');
297          }          }
298                    
299          if($self->{'MaxMessageCount'}>0 && $msgCount>=$self->{'MaxMessageCount'})          if($self->{'MaxMessageCount'}>0 && $msgCount>=$self->{'MaxMessageCount'})
300          {          {
301                  $self->close(1);                  $self->close(1, 'maxMessageCountReached');
302          }          }
303                    
304  }  }
# Line 326  sub closeChannel { Line 321  sub closeChannel {
321                    
322          delete($self->{'channels'}->{$channelName});          delete($self->{'channels'}->{$channelName});
323                    
324          $self->close(0,'channelsClosed') if(scalar(keys %{$self->{'channels'}})==0);          $self->close(0,'channelClose') if(scalar(keys %{$self->{'channels'}})==0);
325  }  }
326    
327  sub close {  sub close {
328          my $self=shift;          my $self=shift;
329          my $noShutdownMsg=shift;          my $noShutdownMsg=shift;
330            my $reason=shift;
331                    
332          foreach my $channelName (keys %{$self->{'channels'}})          foreach my $channelName (keys %{$self->{'channels'}})
333          {          {
334                  my $channel=$self->{'channels'}->{$channelName};                  my $channel=$self->{'channels'}->{$channelName};
335                  $channel->removeSubscriber($self,'subscriberClose');                  $channel->removeSubscriber($self,$reason);
336          }          }
337          delete($self->{'channels'});          delete($self->{'channels'});
338                    
339          if(exists($self->{'subscriberID'}))          # If this connection is in the PersistentConnections array, delete it, then anonymise
340          {          # it so that if we have to wait for the write buffer to empty before close, it's only
341            # removed once.
342            if(exists($self->{'subscriberID'})) {
343                  delete($PersistentConnections{$self->{'subscriberID'}});                  delete($PersistentConnections{$self->{'subscriberID'}});
344                    delete($self->{'subscriberID'});
345          }          }
346                    
         #  
347          # Send shutdown message unless remote closed or          # Send shutdown message unless remote closed or
348          # connection not yet established          # connection not yet established
         #  
349          unless($noShutdownMsg || $self->{'remoteClosed'} || exists($self->{'headerBuffer'}))          unless($noShutdownMsg || $self->{'remoteClosed'} || exists($self->{'headerBuffer'}))
350          {          {
351                  my $msg=$self->getConf('SubscriberShutdownMsg');                  my $msg=$self->getConf('SubscriberShutdownMsg');
# Line 370  sub checkForMaxTime { Line 367  sub checkForMaxTime {
367          my $self=shift;          my $self=shift;
368          my $time=shift;          my $time=shift;
369                    
370          $self->close(1) if(exists($self->{'ConnectionTimeLimit'}) && $self->{'ConnectionTimeLimit'}<$time);          $self->close(1,'maxTime') if(exists($self->{'ConnectionTimeLimit'}) && $self->{'ConnectionTimeLimit'}<$time);
371  }  }
372    
373  sub getConf {  sub getConf {
# Line 379  sub getConf { Line 376  sub getConf {
376                    
377          if(exists($self->{'mode'}) && $self->{'mode'} ne '')          if(exists($self->{'mode'}) && $self->{'mode'} ne '')
378          {          {
379                  my $k=$key.'.'.$self->{'mode'};                  my $k=$key.$self->{'mode'};
380                                    
381                  return $::CONF{$k} if(exists($::CONF{$k}));                  if(exists($::CONF{$k})) {
382                            return $::CONF{$k};
383                    }
384          }          }
385                    
386          $::CONF{$key};          $::CONF{$key};

Legend:
Removed from v.49  
changed lines
  Added in v.50

  ViewVC Help
Powered by ViewVC 1.1.26