[svn:qpsmtpd] rev 415 - branches/high_perf

[email protected] 12 May 2005 12:57:06 -0000
Newsgroups perl.cvs.qpsmtpd
Message-ID <[email protected]>
Author: msergeant
Date: Thu May 12 05:57:05 2005
New Revision: 415

Modified:
   branches/high_perf/qpsmtpd
Log:
Use class logging where we can so we get proper log levels
Accept all new incoming connections not just one


Modified: branches/high_perf/qpsmtpd
==============================================================================
--- branches/high_perf/qpsmtpd	(original)
+++ branches/high_perf/qpsmtpd	Thu May 12 05:57:05 2005
@@ -251,14 +251,14 @@
             push @kids, spawn_child();
         }
         $SIG{INT} = $SIG{TERM} = sub { $SIG{CHLD} = "IGNORE"; kill 2 => @kids; exit };
-        ::log(LOGDEBUG, "Listening on $PORT with $PROCS children $POLL");
+        $plugin_loader->log(LOGDEBUG, "Listening on $PORT with $PROCS children $POLL");
         sleep while (1);
     }
     else {
         if ($LineMode) {
             $SIG{INT} = $SIG{TERM} = \&HUNTSMAN;
         }
-        ::log(LOGDEBUG, "Listening on $PORT with single process $POLL" .
+        $plugin_loader->log(LOGDEBUG, "Listening on $PORT with single process $POLL" .
             ($LineMode ? " (forking server)" : ""));
         Qpsmtpd::PollServer->OtherFds(fileno($SERVER) => \&accept_handler,
                                       fileno($CONFIG_SERVER) => \&config_handler,
@@ -274,7 +274,7 @@
 sub config_handler {
     my $csock = $CONFIG_SERVER->accept();
     if (!$csock) {
-        warn("accept failed on config server: $!");
+        # warn("accept failed on config server: $!");
         return;
     }
     binmode($csock, ':raw');
@@ -289,9 +289,15 @@
     return;
 }
 
-# Accept a new connection
+# Accept all new connections
 sub accept_handler {
-	my $running;
+    for (1..10000) {
+        last unless _accept_handler();
+    }
+}
+
+sub _accept_handler {
+    my $running;
     if( $LineMode ) {
         $running = scalar keys %childstatus;
     }
@@ -299,7 +305,7 @@
         my $descriptors = Danga::Client->DescriptorMap;
         $running = scalar keys %$descriptors;
     }
-    while ($running >= $MAXCONN) { 
+    if ($running >= $MAXCONN) { 
         ::log(LOGINFO,"Too many connections: $running >= $MAXCONN.");
         return;
     }
@@ -326,7 +332,7 @@
         if ($PAUSED) {
             $client->write("451 Sorry, this server is currently paused\r\n");
             $client->close;
-            return;
+            return 1;
         }
         
         if ($MAXCONNIP) {
@@ -344,22 +350,22 @@
             }
             
             if ($num_conn > $MAXCONNIP) {
-                ::log(LOGINFO,"Too many connections from $rem_ip: "
+                $client->log(LOGINFO,"Too many connections from $rem_ip: "
                              ."$num_conn > $MAXCONNIP. Denying connection.");
                 $client->write("451 Sorry, too many connections from $rem_ip, try again later\r\n");
                 $client->close;
-                return;
+                return 1;
             }
-            ::log(LOGINFO, "accepted connection $running/$MAXCONN ($num_conn/$MAXCONNIP) from $rem_ip");
+            $client->log(LOGINFO, "accepted connection $running/$MAXCONN ($num_conn/$MAXCONNIP) from $rem_ip");
         }
         
         my $rc = $client->start_conversation;
         if ($rc != DONE) {
             $client->close;
-            return;
+            return 1;
         }
         $client->watch_read(1);
-        return;
+        return 1;
     }
 
     # fork-per-connection mode
@@ -378,7 +384,7 @@
                          ."$num_conn > $MAXCONNIP. Denying connection.");
             print $csock "451 Sorry, too many connections from $rem_ip, try again later\r\n";
             close $csock;
-            return;
+            return 1;
         }
     }
     
@@ -408,7 +414,7 @@
         $client->watch_read(1);
     }
 
-    ::log(LOGDEBUG, "Finished with child %d.\n", fileno($csock))
+    $client->log(LOGDEBUG, "Finished with child %d.\n", fileno($csock))
         if $DEBUG;
     $client->close();