1) The listener connects to a TCP or UNIX-domain socket.
2) The listener informs mimedefang-multiplexor of the message types it is interested in.
3) The listener loops, reading messages from the socket and reacting to them.
Two special messages are "*OK" followed by a newline, which is issued when a listener first connects, and "*ERR" followed by some text and a newline, which is issued when an error occurs.
The normal messages are:
?RF
A listener interested in every possible message type should send:
?*
Once a listener has expressed interest, it may receive messages at any time, and should monitor the socket for messages.
Note that a listener always receives the special messages "*OK" and "*ERR", even if it has not expressed interest in them.
The following Perl script implements a listener that, on Linux, rejects new SMTP connections if all slaves are busy, and accepts them again once a slave is free. Existing SMTP connections are not shut down; the system merely refuses new connections if all the slaves are busy.
This script assumes that you have used the -O inet:4567 option to mimedefang-multiplexor.
#!/usr/bin/perl -w
#
# On Linux, prepare to use this script like this:
# /sbin/iptables -N smtp_connect
# /sbin/iptables -A INPUT --proto tcp --dport 25 --syn -j smtp_connect
# Then run the script as root.
use IO::Socket::INET;
sub no_free_slaves {
print STDERR "No free slaves!\n";
system("/sbin/iptables -A smtp_connect -j REJECT");
}
sub some_free_slaves {
print STDERR "Some free slaves.\n";
system("/sbin/iptables -F smtp_connect");
}
sub main {
my $sock;
$sock = IO::Socket::INET->new(PeerAddr => '127.0.0.1',
PeerPort => '4567',
Proto => 'tcp');
# We are only interested in Y and Z messages
print $sock "?YZ\n";
$sock->flush();
while(<$sock>) {
if (/^Z/) {
no_free_slaves();
}
if (/^Y/) {
some_free_slaves();
}
}
# EOF from multiplexor?? Better undo firewalling
system("/sbin/iptables -F smtp_connect");
}
main();