From 56451a722fd00420338b6258556c521eeedf0413 Mon Sep 17 00:00:00 2001 From: Matt Sergeant Date: Mon, 23 May 2005 13:06:08 +0000 Subject: [PATCH] First, since EventLoop goes off and does other things, any PostLoopCallback can signal "our" EventLoop to return. To ensure we wait the full time, we must loop around until the end condition is truly satisfied. git-svn-id: https://svn.perl.org/qpsmtpd/branches/high_perf@425 958fd67b-6ff1-0310-b445-bb7760255be9 --- lib/Danga/Client.pm | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/lib/Danga/Client.pm b/lib/Danga/Client.pm index 5fb002a..f85ef99 100644 --- a/lib/Danga/Client.pm +++ b/lib/Danga/Client.pm @@ -51,15 +51,18 @@ sub can_read { if (!length($self->{line})) { my $old = $self->watch_read(); $self->watch_read(1); - $self->SetPostLoopCallback(sub { (length($self->{line}) || - (Time::HiRes::time > $end)) ? 0 : 1 }); - #warn("get_line PRE\n"); - $self->EventLoop(); - #warn("get_line POST\n"); + # loop because any callback, not just ours, can make EventLoop return + while( !(length($self->{line}) || (Time::HiRes::time > $end)) ) { + $self->SetPostLoopCallback(sub { (length($self->{line}) || + (Time::HiRes::time > $end)) ? 0 : 1 }); + #warn("get_line PRE\n"); + $self->EventLoop(); + #warn("get_line POST\n"); + } $self->watch_read($old); } $self->{can_read_mode} = 0; - $self->SetPostLoopCallback(sub { $self->have_line ? 0 : 1 }); + $self->SetPostLoopCallback(undef); return if $self->{closing}; $self->{alive_time} = time; # warn("can_read returning for '$self->{line}'\n");