Author: msergeant
Date: Thu Mar 13 12:48:45 2008
New Revision: 852

Modified:
   trunk/lib/Danga/Client.pm

Log:
Fairness patch - prevent bad pipelining clients from hogging the event loop


Modified: trunk/lib/Danga/Client.pm
==============================================================================
--- trunk/lib/Danga/Client.pm   (original)
+++ trunk/lib/Danga/Client.pm   Thu Mar 13 12:48:45 2008
@@ -113,7 +113,7 @@
     $self->{line} .= $$bref;
     return if $self->{pause_count} || $self->{closed};
     
-    while ($self->{line} =~ s/^(.*?\n)//) {
+    if ($self->{line} =~ s/^(.*?\n)//) {
         my $line = $1;
         $self->{alive_time} = time;
         my $resp = $self->process_line($line);
@@ -121,6 +121,12 @@
         $self->write($resp) if $resp;
         # $self->watch_read(0) if $self->{pause_count};
         return if $self->{pause_count} || $self->{closed};
+        # read more in a timer, to give other clients a look in
+        $self->AddTimer(0, sub {
+            if (length($self->{line}) && !$self->paused) {
+                $self->process_read_buf(\""); # " for bad syntax highlighters
+            }
+        });
     }
 }
 

Reply via email to