/[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 45 by knops.gerd, Mon Feb 4 19:02:49 2008 UTC revision 51 by andrew.betts, Wed Feb 27 14:05:59 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');
                           
                         if ($self->{'mode'} eq "xhrinteractive" || $self->{'mode'} eq "iframe" || $self->{'mode'} eq "serversent" || $self->{'mode'} eq "longpoll") {  
                                 $persist=1;  
                                 $self->{'MaxMessageCount'}=1 unless(!($self->{'mode'} eq "longpoll"));  
                         }  
                         if ($self->{'mode'} eq "iframe") {  
                                 $self->{'HeaderTemplateNumber'}=1;  
                         } else {  
                                 $self->{'HeaderTemplateNumber'}=2;  
                         }  
                           
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={};
147                          my $channelName;                          my $channelName;
148                          my $offset;                          my $offset;
149                          foreach my $chandef (@channelData) {                          foreach my $chandef (@channelData) {
150                                  if($chandef=~/^([a-z0-9]+)(.(r|b|h)([0-9]*))?$/i) {                                  if($chandef=~/^([a-z0-9_\-\%]+)(.(r|b|h)([0-9]*))?$/i) {
151                                          $channelName = $1;                                          $channelName = $1;
152                                          $channels->{$channelName}->{'startIndex'} = undef;                                          $channels->{$channelName}->{'startIndex'} = undef;
153                                          if ($3) {                                          if ($3) {
# Line 172  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->setChannels($channels,$persist,$self->{'mode'},$useragent);
174                                  $self->close(1) unless($persist);                                  $self->close(1, 'responseComplete') unless($persist);
175                                  return;                                  return;
176                          }                          }
177                  }                  }
# Line 194  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 215  sub setChannels { Line 200  sub setChannels {
200          my $self=shift;          my $self=shift;
201          my $channels=shift;          my $channels=shift;
202          my $persist=shift;          my $persist=shift;
203            my $mode=shift || '';
204            my $userAgent=shift || '';
205                    
206          foreach my $channelName (keys %{$channels})          foreach my $channelName (keys %{$channels})
207          {          {
# Line 224  sub setChannels { Line 211  sub setChannels {
211                                    
212                  $self->{'channels'}->{$channelName}=$channel if($persist);                  $self->{'channels'}->{$channelName}=$channel if($persist);
213                                    
214                  $channel->addSubscriber($self,$startIndex,$persist);                  $channel->addSubscriber($self,$startIndex,$persist,$mode,$userAgent);
215          }          }
216  }  }
217    
# Line 241  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 {
235          my $self=shift;          my $self=shift;
236          my $status=shift;          my $status=shift;
237                    
238          my $header=undef;          my $header=$self->getConf('HeaderTemplate');
         if(exists($self->{'HeaderTemplateNumber'}))  
         {  
                 my $hn='HeaderTemplate'.$self->{'HeaderTemplateNumber'};  
                   
                 $header=$self->getConf($hn);  
         }  
         $header=$self->getConf('HeaderTemplate') unless(defined($header));  
239                    
240          $header=~s/~([^~]*)~/          $header=~s/~([^~]*)~/
241                  if(!defined($1) || $1 eq '')                  if(!defined($1) || $1 eq '')
# Line 291  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 313  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 337  sub closeChannel { Line 317  sub closeChannel {
317          return unless(exists($self->{'channels'}->{$channelName}));          return unless(exists($self->{'channels'}->{$channelName}));
318                    
319          my $channel=$self->{'channels'}->{$channelName};          my $channel=$self->{'channels'}->{$channelName};
320          $channel->removeSubscriber($self);          $channel->removeSubscriber($self,'channelClose');
321                    
322          delete($self->{'channels'}->{$channelName});          delete($self->{'channels'}->{$channelName});
323                    
324          $self->close() 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);                  $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 385  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 394  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.45  
changed lines
  Added in v.51

  ViewVC Help
Powered by ViewVC 1.1.26