[Mimedefang] Minor patch (some small speedup and new command)

Martin Blapp mb at imp.ch
Fri Aug 17 10:52:29 EDT 2007


Hi David,

Would be great if you could add this patch.

Changes:

-----------------------------------------------------------------

- Add 'queued' command to get the length of the queue
   For example:

# telnet /var/spool/MIMEDefang/mimedefang-multiplexor.sock
Trying /var/spool/MIMEDefang/mimedefang-multiplexor.sock...
Connected to /var/spool/MIMEDefang/mimedefang-multiplexor.sock.
Escape character is '^]'.
queued
57
Connection closed by foreign host.

Similar like the already existing 'free':

# telnet /var/spool/MIMEDefang/mimedefang-multiplexor.sock
Trying /var/spool/MIMEDefang/mimedefang-multiplexor.sock...
Connected to /var/spool/MIMEDefang/mimedefang-multiplexor.sock.
Escape character is '^]'.
free
21
Connection closed by foreign host.

-----------------------------------------------------------------

- Use switch statement to only process the commands with
   the same lenght at once. Only a small improvement but
   saves some few CPU cycles. We call the 'queued' statement
   rather often.

-----------------------------------------------------------------

--- mimedefang-multiplexor.c	Fri Aug 17 15:27:06 2007
+++ mimedefang-multiplexor.c	Fri Aug 17 15:26:43 2007
@@ -1542,94 +1542,116 @@
  	len--;
  	buf[len] = 0;
      }
-    if (len == 4 && !strcmp(buf, "help")) {
-	if (data) {
-	    doHelp(es, fd, 1);
-	} else {
-	    doHelp(es, fd, 0);
-	}
-	return;
-    }

-    if (len == 4 && !strcmp(buf, "free")) {
-	snprintf(answer, sizeof(answer), "%d\n",
-		 NUM_FREE_SLAVES);
-	reply_to_mimedefang(es, fd, answer);
-	return;
-    }
-
-    /* "tick" command must ONLY be internally-generated to guarantee
-       that two tick handlers won't be running simultaneously */
-    if (len == 4 && !strcmp(buf, "tick")) {
-	snprintf(answer, sizeof(answer), "error: External agents may not invoke 'tick'\n");
-	reply_to_mimedefang(es, fd, answer);
-	return;
-    }
-
-    if (len == 6 && !strcmp(buf, "status")) {
-	doStatus(es, fd);
-	return;
-    }
-
-    if (len == 6 && !strcmp(buf, "slaves")) {
-	doSlaveReport(es, fd, 0);
-	return;
-    }
-
-    if (len == 10 && !strcmp(buf, "busyslaves")) {
-	doSlaveReport(es, fd, 1);
-	return;
-    }
-
-    if (len == 4 && !strcmp(buf, "load")) {
-	doLoad(es, fd, SCAN_CMD);
-	return;
-    }
-
-    if (len == 12 && !strcmp(buf, "load-relayok")) {
-	doLoad(es, fd, RELAYOK_CMD);
-	return;
-    }
-
-    if (len == 13 && !strcmp(buf, "load-senderok")) {
-	doLoad(es, fd, SENDEROK_CMD);
-	return;
-    }
-
-    if (len == 12 && !strcmp(buf, "load-recipok")) {
-	doLoad(es, fd, RECIPOK_CMD);
-	return;
-    }
-
-    if (len == 5 && !strcmp(buf, "hload")) {
-	doHourlyLoad(es, fd, SCAN_CMD);
-	return;
-    }
-
-    if (len == 13 && !strcmp(buf, "hload-relayok")) {
-	doHourlyLoad(es, fd, RELAYOK_CMD);
-	return;
-    }
-
-    if (len == 14 && !strcmp(buf, "hload-senderok")) {
-	doHourlyLoad(es, fd, SENDEROK_CMD);
-	return;
-    }
-
-    if (len == 13 && !strcmp(buf, "hload-recipok")) {
-	doHourlyLoad(es, fd, RECIPOK_CMD);
-	return;
-    }
-
-    if (len == 5 && !strcmp(buf, "histo")) {
-      doHistogram(es, fd);
-      return;
-    }
-
-    if (len == 4 && !strcmp(buf, "msgs")) {
-	snprintf(answer, sizeof(answer), "%d\n", NumMsgsProcessed);
-	reply_to_mimedefang(es, fd, answer);
-	return;
+    switch(len) {
+	    case 4:
+		    if (!strcmp(buf, "help")) {
+			if (data) {
+			    doHelp(es, fd, 1);
+			} else {
+			    doHelp(es, fd, 0);
+			}
+			return;
+		    }
+
+		    if (!strcmp(buf, "free")) {
+			snprintf(answer, sizeof(answer), "%d\n",
+				 NUM_FREE_SLAVES);
+			reply_to_mimedefang(es, fd, answer);
+			return;
+		    }
+
+		    /* "tick" command must ONLY be internally-generated to guarantee
+		       that two tick handlers won't be running simultaneously */
+		    if (!strcmp(buf, "tick")) {
+			snprintf(answer, sizeof(answer), "error: External agents may not invoke 'tick'\n");
+			reply_to_mimedefang(es, fd, answer);
+			return;
+		    }
+
+		    if (!strcmp(buf, "msgs")) {
+			snprintf(answer, sizeof(answer), "%d\n", NumMsgsProcessed);
+			reply_to_mimedefang(es, fd, answer);
+			return;
+		    }
+
+		    if (!strcmp(buf, "load")) {
+			doLoad(es, fd, SCAN_CMD);
+			return;
+		    }
+		    break;
+	    case 5:
+		    if (!strcmp(buf, "hload")) {
+			doHourlyLoad(es, fd, SCAN_CMD);
+			return;
+		    }
+
+		    if (!strcmp(buf, "histo")) {
+		      doHistogram(es, fd);
+		      return;
+		    }
+		    break;
+	    case 6:
+
+		    if (!strcmp(buf, "queued")) {
+			snprintf(answer, sizeof(answer), "%d\n",
+				 NumQueuedRequests);
+			reply_to_mimedefang(es, fd, answer);
+			return;
+		    }
+		    if (!strcmp(buf, "status")) {
+			doStatus(es, fd);
+			return;
+		    }
+
+		    if (!strcmp(buf, "slaves")) {
+			doSlaveReport(es, fd, 0);
+			return;
+		    }
+		    break;
+	   case 10:
+
+		    if (!strcmp(buf, "busyslaves")) {
+			doSlaveReport(es, fd, 1);
+			return;
+		    }
+		    break;
+	   case 12:
+
+		    if (!strcmp(buf, "load-relayok")) {
+			doLoad(es, fd, RELAYOK_CMD);
+			return;
+		    }
+
+		    if (!strcmp(buf, "load-recipok")) {
+			doLoad(es, fd, RECIPOK_CMD);
+			return;
+		    }
+		    break;
+	   case 13:
+
+		    if (!strcmp(buf, "load-senderok")) {
+			doLoad(es, fd, SENDEROK_CMD);
+			return;
+		    }
+
+		    if (!strcmp(buf, "hload-relayok")) {
+			doHourlyLoad(es, fd, RELAYOK_CMD);
+			return;
+		    }
+
+		    if (!strcmp(buf, "hload-recipok")) {
+			doHourlyLoad(es, fd, RECIPOK_CMD);
+			return;
+		    }
+		    break;
+	   case 14:
+
+		    if (!strcmp(buf, "hload-senderok")) {
+			doHourlyLoad(es, fd, SENDEROK_CMD);
+			return;
+		    }
+		    break;
      }

      if (len > 10 && !strncmp(buf, "slaveinfo ", 10)) {
@@ -3457,6 +3479,7 @@
  	"load-senderok    -- Display load (senderok requests)\n"
  	"rawload-senderok -- Computer-readable load (senderok requests)\n"
  	"load-recipok     -- Display load (recipok requests)\n"
+	"queued           -- Display number of queued requests\n"
  	"rawload-recipok  -- Computer-readable load (recipok requests)\n"
  	"histo            -- Display histogram of busy slaves\n"
  	"msgs             -- Display number of messages processed since startup\n"

Martin Blapp, <mb at imp.ch> <mbr at FreeBSD.org>
------------------------------------------------------------------
ImproWare AG, UNIXSP & ISP, Zurlindenstrasse 29, 4133 Pratteln, CH
Phone: +41 61 826 93 00 Fax: +41 61 826 93 01
PGP: <finger -l mbr at freebsd.org>
PGP Fingerprint: B434 53FC C87C FE7B 0A18 B84C 8686 EF22 D300 551E
------------------------------------------------------------------




More information about the MIMEDefang mailing list