In the high_perf branch, check_earlytalker doesn't work for me.

This patch makes check_earlytalker work in high_perf.

There are two parts to this patch.  The first patch, to
plugins/check_earlytalker, makes check_earlytalker work when there are
other connections generating events.  (For testing, use: while true; do
echo quit | nc localhost 25; sleep 1; done)

When combined with the second patch, to lib/Danga/Socket.pm,
check_earlytalker will work even without other connections generating
events.


I haven't tried this in a production environment, but it works well in my
contrived tests.

Matt, will the patch to Danga::Socket have any bad side effects?  I haven't
been around Danga::Socket enough to know.

Brian
--- plugins/check_earlytalker  (revision 953)
+++ plugins/check_earlytalker  (local)
@@ -44,7 +44,7 @@
 
 =cut
 
-use IO::Select;
+use Time::HiRes ();
 
 use warnings;
 use strict;
@@ -70,8 +70,16 @@
 
 sub connect_handler {
   my ($self, $transaction) = @_;
+  my $qp = $self->qp;
+  my $end = Time::HiRes::time + $self->{_args}->{'wait'} ;
+  my $time;
+  for( $time = Time::HiRes::time; $time < $end && !length($qp->{line}) ; $time 
= Time::HiRes::time ) {
+    $qp->can_read($end-$time);
+    }
+  my $earlytalker = 0;
+  $earlytalker = 1 if $time < $end ;
 
-  if ($self->qp->can_read($self->{_args}->{'wait'})) {
+  if ($earlytalker) {
     $self->log(LOGNOTICE, 'remote host started talking before we said hello');
     if ($self->{_args}->{'defer-reject'}) {
        $self->connection->notes('earlytalker', 1);
--- lib/Danga/Socket.pm  (revision 953)
+++ lib/Danga/Socket.pm  (local)
@@ -282,6 +282,7 @@
                 $sock->ticker;
             }
         }
+        return unless PostEventLoop();
 
         print STDERR "Event loop ending; restarting.\n";
     }

Reply via email to