X-Git-Url: https://git.exim.org/users/heiko/exim.git/blobdiff_plain/1f187290089991b306083d9418a6cacb6a400f6b..b1227303735a346c79fd0734c9efb5d13609ad55:/test/lib/Exim/Runtest.pm?ds=sidebyside diff --git a/test/lib/Exim/Runtest.pm b/test/lib/Exim/Runtest.pm index 2ac9a61ee..845388b8b 100644 --- a/test/lib/Exim/Runtest.pm +++ b/test/lib/Exim/Runtest.pm @@ -1,16 +1,29 @@ package Exim::Runtest; use strict; use warnings; +use IO::Socket::INET; use Carp; use List::Util qw'shuffle'; +=head1 NAME + +Exim::Runtest - helper functions for the runtest script + +=head1 SYNOPSIS + + use Exim::Runtest; + my $foo = Exim::Runtest::foo('foo'); + +=head1 DESCRIPTION + +The B module provides some simple functions +for the F script. No functions are exported yet. + +=cut -# find a group name, preferrable 'mail', but -# use some other random name if 'mail' isn't a valid group -# name sub mailgroup { - my $group = shift; + my $group = shift // croak "Need a default group name."; croak "Need a group *name*, not a numeric group id." if $group =~ /^\d+$/; @@ -22,7 +35,39 @@ sub mailgroup { push @groups, $_ while defined($_ = getgrent); endgrent; return (shuffle @groups)[0]; -}; +} +sub dynamic_socket { + my $socket; + for (my $port = 1024; $port < 65000; $port++) { + $socket = IO::Socket::INET->new( + LocalHost => '127.0.0.1', + LocalPort => $port, + Listen => 10, + ReuseAddr => 1, + ) and return $socket; + } + croak 'Can not allocate a free port.'; +} 1; + +__END__ + +=head1 FUNCTIONS + +=over + +=item B(I<$default>) + +Check if the mailgroup I<$default> exists. Return the checked +group name or some other random but existing group. + +=item B() + +Return a dynamically allocated listener socket in the range +between 1024 and 65534; + +=back + +=cut