3 use Test::More tests => 8;
5 use autodie qw(socketpair);
7 # All of this code is based around recv returning an empty
8 # string when it gets data from a local machine (using AF_UNIX),
9 # but returning an undefined value on error. Fatal/autodie
10 # should be able to tell the difference.
12 $SIG{PIPE} = 'IGNORE';
15 socketpair($sock1, $sock2, AF_UNIX, SOCK_STREAM, PF_UNSPEC);
18 send($sock1, "xyz", 0);
19 my $ret = recv($sock2, $buffer, 2, 0);
25 skip('recv() never returns empty string with socketpair emulation',4)
28 is($buffer,'xy',"recv() operational without autodie");
30 # Read the last byte from the socket.
31 eval { $ret = recv($sock2, $buffer, 1, 0); };
33 is($@, "", "recv should not die on returning an emtpy string.");
35 is($buffer,"z","recv() operational with autodie");
36 is($ret,"","recv returns undying empty string for local sockets");
41 # STDIN isn't a socket, so this should fail.
42 recv(STDIN,$buffer,1,0);
45 ok($@,'recv dies on returning undef');
46 isa_ok($@,'autodie::exception');
48 $buffer = "# Not an empty string\n";
50 # Terminate writing for $sock1
55 # Writing to a socket terminated for writing should fail.
56 send($sock1,$buffer,0);
59 ok($@,'send dies on returning undef');
60 isa_ok($@,'autodie::exception');