The manakai project

Web::Transport::FindPort

Find a listenable TCP port

SYNOPSIS

  use Web::Transport::FindPort;
  warn find_listenable_port;

DESCRIPTION

The 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.

FUNCTION

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.

HISTORY

This module was originally released as Net::TCP::FindPort version 1.0 (2010-08-05).

AUTHOR

Wakaba <wakaba@suikawiki.org>.

LICENSE

Copyright 2010 Hatena <http://www.hatena.ne.jp/>

Copyright 2020 Wakaba <wakaba@suikawiki.org>.

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.