| 1 | package Selenium::CanStartBinary::ProbePort; | ||||||||||
| 2 | 11 | $Selenium::CanStartBinary::ProbePort::VERSION = '1.50'; | |||||||||
| 3 | 11 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 11 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | |||||||||||
| 6 | # ABSTRACT: Utility functions for finding open ports to eventually bind to | ||||||||||
| 7 | |||||||||||
| 8 | 11 | ▶ | use IO::Socket::INET; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | 11 | ▶ | use Selenium::Waiter qw/wait_until/; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 10 | |||||||||||
| 11 | 11 | require Exporter; | |||||||||
| 12 | 11 | our @ISA = qw/Exporter/; | |||||||||
| 13 | 11 | our @EXPORT_OK = qw/find_open_port_above find_open_port probe_port/; | |||||||||
| 14 | |||||||||||
| 15 | |||||||||||
| 16 | 0 | ▶ | sub find_open_port_above { | ||||||||
|
Subroutine
find_open_port_above: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 17 | 0 | socket(SOCK, PF_INET, SOCK_STREAM, getprotobyname("tcp")); | |||||||||
| 18 | 0 | bind(SOCK, sockaddr_in(0, INADDR_ANY)); | |||||||||
| 19 | 0 | my $port = (sockaddr_in(getsockname(SOCK)))[0]; | |||||||||
| 20 | 0 | close(SOCK); | |||||||||
| 21 | 0 | return $port; | |||||||||
| 22 | } | ||||||||||
| 23 | |||||||||||
| 24 | 0 | ▶ | sub find_open_port { | ||||||||
|
Subroutine
find_open_port: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||
| 25 | 0 | my ($port) = @_; | |||||||||
| 26 | |||||||||||
| 27 | 0 | ▶ | probe_port($port) ? return 0 : return $port; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 28 | } | ||||||||||
| 29 | |||||||||||
| 30 | 0 | ▶ | sub probe_port { | ||||||||
|
Subroutine
probe_port: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 31 | 0 | my ($port) = @_; | |||||||||
| 32 | |||||||||||
| 33 | 0 | return IO::Socket::INET->new( | |||||||||
| 34 | PeerAddr => '127.0.0.1', | ||||||||||
| 35 | PeerPort => $port, | ||||||||||
| 36 | Timeout => 3 | ||||||||||
| 37 | ); | ||||||||||
| 38 | } | ||||||||||
| 39 | |||||||||||
| 40 | __END__ | ||||||||||