File: 19no-addrs.t

package info (click to toggle)
perl 5.20.2-3%2Bdeb8u11
  • links: PTS, VCS
  • area: main
  • in suites: jessie
  • size: 102,964 kB
  • sloc: perl: 555,553; ansic: 214,041; sh: 38,121; pascal: 8,783; cpp: 3,895; makefile: 2,393; xml: 2,325; yacc: 1,741
file content (54 lines) | stat: -rw-r--r-- 1,762 bytes parent folder | download | duplicates (8)
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
#!/usr/bin/perl

use strict;
use warnings;

use Test::More;

use IO::Socket::IP;
use Socket qw( SOCK_STREAM AF_INET );

# Compatibility test for
# IO::Socket::INET->new( Blocking => 0 ) still creates a defined filehandle

{
   my $sock = IO::Socket::IP->new( Family => AF_INET );
   my $save_exc = $@;
   ok( defined $sock, 'Constructor yields handle for Family => AF_INET' ) or
      diag( "Exception was $save_exc" );

   ok( defined $sock->fileno, '$sock->fileno for Family => AF_INET' );
   is( $sock->sockdomain, AF_INET, '$sock->sockdomain for Family => AF_INET' );
   is( $sock->socktype, SOCK_STREAM, '$sock->socktype for Family => AF_INET' );
}

SKIP: {
   my $AF_INET6 = eval { require Socket and Socket::AF_INET6() } or
      skip "No AF_INET6", 4;

   eval { IO::Socket::IP->new( LocalHost => "::1" ) } or
      skip "Unable to bind to ::1", 4;

   my $sock = IO::Socket::IP->new( Family => $AF_INET6 );
   my $save_exc = $@;
   ok( defined $sock, 'Constructor yields handle for Family => AF_INET6' ) or
      diag( "Exception was $save_exc" );

   ok( defined $sock->fileno, '$sock->fileno for Family => AF_INET6' );
   is( $sock->sockdomain, $AF_INET6, '$sock->sockdomain for Family => AF_INET6' );
   is( $sock->socktype, SOCK_STREAM, '$sock->socktype for Family => AF_INET6' );
}

# Lack of even a Family hint - _a_ socket is created but we don't guarantee
# what family
{
   my $sock = IO::Socket::IP->new( Type => SOCK_STREAM );
   my $save_exc = $@;
   ok( defined $sock, 'Constructor yields handle for Type => SOCK_STREAM' ) or
      diag( "Exception was $save_exc" );

   ok( defined $sock->fileno, '$sock->fileno for Type => SOCK_STREAM' );
   is( $sock->socktype, SOCK_STREAM, '$sock->socktype for Type => SOCK_STREAM' );
}

done_testing;