ProbePort.pm 622 B

12345678910111213141516171819202122232425262728293031323334
  1. package Selenium::CanStartBinary::ProbePort;
  2. use IO::Socket::INET;
  3. use Selenium::Waiter qw/wait_until/;
  4. require Exporter;
  5. our @ISA = qw/Exporter/;
  6. our @EXPORT_OK = qw/find_open_port_above probe_port/;
  7. sub find_open_port_above {
  8. my ($port) = @_;
  9. my $free_port = wait_until {
  10. if ( probe_port($port) ) {
  11. $port++;
  12. return 0;
  13. }
  14. else {
  15. return $port;
  16. }
  17. };
  18. return $free_port;
  19. }
  20. sub probe_port {
  21. my ($port) = @_;
  22. return IO::Socket::INET->new(
  23. PeerAddr => '127.0.0.1',
  24. PeerPort => $port,
  25. Timeout => 3
  26. );
  27. }