use strict; use IO::Socket; use IO::Select; #Just opens the configuration file and stuffs all the values into the %config hash my %config = get_config($ARGV[0] ? $ARGV[0] : "/etc/MailScanManager/MailScanManager.conf"); my $sel = new IO::Select; #$config{connections} is an array of hashes containing information about each listening socket #the server should create foreach my $connection (@{$config{connections}}) { if($connection->{socket_type} & IP_SOCKET) { if(!$connection->{socket_address}) { $connection->{socket_address} = INADDR_ANY; } if(!$connection->{socket_port}) { $connection->{socket_port} = 7000; } $connection->{socket} = new IO::Socket::INET(Listen => 1, LocalPort => $connection->{socket_port}, LocalAddr => $connection->{socket_address}) || die("Could not create socket $!");; $sel->add($connection->{socket}); } if($connection->{socket_type} & UNIX_SOCKET) { if(!$connection->{address}) { $connection->{address} = "/var/run/MailScanManager/msm.sock"; } unlink($connection->{address}); $connection->{socket} = new IO::Socket::UNIX(Type => SOCK_STREAM, Listen => 5, Local => $connection->{address}) || die("Could not create socket $!"); chmod 777, $connection->{address}; $sel->add($connection->{socket}); } } while(my @ready = $sel->can_read) { foreach my $fh (@ready) { #Determine if it's a connection attempt or data sent by a client and act appropriately } }