1
0

ProbePort.pm 697 B

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