If a client pipelined commands, process_read_buf would rush right through
all of them (ignoring disable_read), forcing the later commands to (try to)
execute even through we're waiting for a continuation.
I'm not sure whether this patch is the best way to fix this, but it
does seem to work.
Is {can_read_mode} useful anymore?
Brian--- lib/Danga/Client.pm 2005-06-22 15:39:34.000000000 -0600
+++ lib/Danga/Client.pm 2005-06-23 01:46:33.000000000 -0600
@@ -90,7 +114,7 @@
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,9 +124,20 @@
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 {
my Danga::Client $self = shift;
$self->{disable_read}++;
--- lib/Danga/Socket.pm 2005-06-22 15:39:34.000000000 -0600
+++ lib/Danga/Socket.pm 2005-06-23 01:46:09.000000000 -0600
@@ -636,6 +639,17 @@
$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.