[svn:qpsmtpd] rev 425 - branches/high_perf/lib/Danga

[email protected] 23 May 2005 13:06:09 -0000
Newsgroups perl.cvs.qpsmtpd
Message-ID <[email protected]>
Author: msergeant
Date: Mon May 23 06:06:08 2005
New Revision: 425

Modified:
   branches/high_perf/lib/Danga/Client.pm
Log:
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.



Modified: branches/high_perf/lib/Danga/Client.pm
==============================================================================
--- branches/high_perf/lib/Danga/Client.pm	(original)
+++ branches/high_perf/lib/Danga/Client.pm	Mon May 23 06:06:08 2005
@@ -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");