use strict;
use POSIX;
use IPC::Shareable;
use Net::DNS;
use Data::Dumper;
$|=1;
my $glue = 'data';
my %options = (
create => 'yes',
destroy => 'yes',
);
my %mxs;
my $knot = tie %mxs, 'IPC::Shareable', $glue, { %options } or
die "server: tie failed\n";
my @urls = <>;
my %hash;
for (@urls) {
chomp;
my ($username, $domain) = split (/\@/);
push (@{$hash{$domain}}, $_);
};
my $PREFORK = 25; # number of children to maintain
my @doms = keys %hash;
####
# define the anon arrays here instead of in the child
foreach(@doms)
{
$mxs{$_} = [];
}
for( 1..$PREFORK )
{
last unless @doms > 0;
my $url = shift @doms;
child( $url ) if !fork();
}
wait(); # wait till one dies;
my $kid;
{
if( @doms > 0 )
{
my $url = shift @doms;
child( $url ) if !fork();
}
$kid = wait();
redo unless $kid == -1;
}
print Data::Dumper->Dump([\%mxs]);
exit;
####
sub child
{
my $url = shift;
my $glue = 'data';
my %options = (
create => 'no',
destroy => 'no',
);
my %mxs;
my $knot = tie %mxs, 'IPC::Shareable', $glue, { %options } or
die "client: tie failed\n";
$knot->shlock;
push( @{$mxs{$url}}, map { $_->exchange } mx($url));
$knot->shunlock;
exit;
}
####
use strict;
use POSIX;
use IPC::Shareable;
use Net::DNS;
use Data::Dumper;
$|=1;
my $glue = 'data';
my %options = (
create => 'yes',
destroy => 'yes',
);
my %mxs;
my $knot = tie %mxs, 'IPC::Shareable', $glue, { %options } or
die "server: tie failed\n";
my @urls = <>;
my %hash;
for (@urls) {
chomp;
my ($username, $domain) = split (/\@/);
push (@{$hash{$domain}}, $_);
};
my $PREFORK = 25; # number of children to maintain
my @doms = keys %hash;
# define the anon arrays here instead of in the child
foreach(@doms)
{
$mxs{$_} = [];
}
for( 1..$PREFORK )
{
last unless @doms > 0;
my $url = shift @doms;
child( $url ) if !fork();
}
wait(); # wait till one dies;
my $kid;
{
if( @doms > 0 )
{
my $url = shift @doms;
child( $url ) if !fork();
}
$kid = wait();
redo unless $kid == -1;
}
print Data::Dumper->Dump([\%mxs]);
exit;
sub child
{
my $url = shift;
my $glue = 'data';
my %options = (
create => 'no',
destroy => 'no',
);
my %mxs;
my $knot = tie %mxs, 'IPC::Shareable', $glue, { %options } or
die "client: tie failed\n";
$knot->shlock;
push( @{$mxs{$url}}, map { $_->exchange } mx($url));
$knot->shunlock;
exit;
}