1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
|
#!/usr/bin/perl
use strict;
use warnings;
use Test::More;
use IO::Socket::IP;
use Errno qw( EACCES );
use Socket qw( SOL_SOCKET SO_REUSEADDR SO_REUSEPORT SO_BROADCAST );
TODO: {
local $TODO = "SO_REUSEADDR doesn't appear to work on cygwin smokers" if $^O eq "cygwin";
# I honestly have no idea why this fails, and people don't seem to be able
# to reproduce it on a development box. I'll mark it TODO for now until we
# can gain any more insight into it.
my $sock = IO::Socket::IP->new(
LocalHost => "127.0.0.1",
Type => SOCK_STREAM,
Listen => 1,
ReuseAddr => 1,
) or die "Cannot socket() - $@";
ok( $sock->getsockopt( SOL_SOCKET, SO_REUSEADDR ), 'SO_REUSEADDR set' );
}
SKIP: {
# Some OSes don't implement SO_REUSEPORT
skip "No SO_REUSEPORT constant", 1 unless defined eval { SO_REUSEPORT };
skip "No support for SO_REUSEPORT", 1 unless defined eval {
my $s;
socket( $s, Socket::PF_INET, Socket::SOCK_STREAM, 0 ) and
setsockopt( $s, SOL_SOCKET, SO_REUSEPORT, 1 ) };
my $sock = IO::Socket::IP->new(
LocalHost => "127.0.0.1",
Type => SOCK_STREAM,
Listen => 1,
ReusePort => 1,
) or die "Cannot socket() - $@";
ok( $sock->getsockopt( SOL_SOCKET, SO_REUSEPORT ), 'SO_REUSEPORT set' );
}
SKIP: {
# Some OSes need special privileges to set SO_BROADCAST
$! = 0;
my $sock = IO::Socket::IP->new(
LocalHost => "127.0.0.1",
Type => SOCK_DGRAM,
Broadcast => 1,
);
skip "Privileges required to set broadcast on datagram socket", 1 if !$sock and $! == EACCES;
die "Cannot socket() - $@" unless $sock;
ok( $sock->getsockopt( SOL_SOCKET, SO_BROADCAST ), 'SO_BROADCAST set' );
}
done_testing;
|