Find a listenable TCP port
use Web::Transport::FindPort; warn find_listenable_port;
Web::Transport::FindPort module provides methods to obtain a TCP port number that can be listened by a new server process.
This module is primary intended for use within test scripts where relevant servers need to be executed using random unused ports.
A function is exported by default:
$port = find_listenable_port
$port = Web::Transport::FindPort::find_listenable_port
Returns a listenable TCP port number. If no port is available, the method dies.
Please note that use of this function is, strictly speaking, racy. The returned port might not be really available for listening by the server process, if the port is listened by another process after the testing of this method.
This module was originally released as Net::TCP::FindPort version 1.0 (2010-08-05).
Copyright 2010 Hatena
Copyright 2020 Wakaba <email@example.com>.
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.