Author: msergeant
Date: Thu Jun 23 14:11:54 2005
New Revision: 451

Modified:
   branches/high_perf/lib/Danga/Client.pm
   branches/high_perf/lib/Danga/Socket.pm
Log:
Fix for when pipelining occurs we need to shift the pre-read data back onto
the socket and let the socket loop come back to this socket's data later.


Modified: branches/high_perf/lib/Danga/Client.pm
==============================================================================
--- branches/high_perf/lib/Danga/Client.pm      (original)
+++ branches/high_perf/lib/Danga/Client.pm      Thu Jun 23 14:11:54 2005
@@ -90,7 +90,7 @@ sub process_read_buf {
     my Danga::Client $self = shift;
     my $bref = shift;
     $self->{line} .= $$bref;
-    return if $self->{can_read_mode};
+    return if ! $self->readable();
     return if $::LineMode;
     
     while ($self->{line} =~ s/^(.*?\n)//) {
@@ -100,7 +100,18 @@ sub process_read_buf {
         if ($::DEBUG > 1 and $resp) { print "$$:".($self+0)."S: $_\n" for 
split(/\n/, $resp) }
         $self->write($resp) if $resp;
         $self->watch_read(0) if $self->{disable_read};
+        last if ! $self->readable();
     }
+    if($self->have_line) {
+        $self->shift_back_read($self->{line});
+        $self->{line} = '';
+    }
+}
+
+sub readable {
+    my Danga::Client $self = shift;
+    return 0 if $self->{disable_read} > 0;
+    return 1;
 }
 
 sub disable_read {

Modified: branches/high_perf/lib/Danga/Socket.pm
==============================================================================
--- branches/high_perf/lib/Danga/Socket.pm      (original)
+++ branches/high_perf/lib/Danga/Socket.pm      Thu Jun 23 14:11:54 2005
@@ -636,6 +636,17 @@ sub push_back_read {
     $PushBackSet{$self->{fd}} = $self;
 }
 
+### METHOD: shift_back_read( $buf )
+### Shift back I<buf> (a scalar or scalarref) into the read stream
+### Use this instead of push_back_read() when you need to unread
+### something you just read.
+sub shift_back_read {
+    my Danga::Socket $self = shift;
+    my $buf = shift;
+    unshift @{$self->{read_push_back}}, ref $buf ? $buf : \$buf;
+    $PushBackSet{$self->{fd}} = $self;
+}
+
 ### METHOD: read( $bytecount )
 ### Read at most I<bytecount> bytes from the underlying handle; returns scalar
 ### ref on read, or undef on connection closed.

Reply via email to