summaryrefslogtreecommitdiff
path: root/t/io/socketpair.t
diff options
context:
space:
mode:
Diffstat (limited to 't/io/socketpair.t')
-rw-r--r--t/io/socketpair.t51
1 files changed, 51 insertions, 0 deletions
diff --git a/t/io/socketpair.t b/t/io/socketpair.t
new file mode 100644
index 0000000000..a80e411d7d
--- /dev/null
+++ b/t/io/socketpair.t
@@ -0,0 +1,51 @@
+#!./perl
+
+BEGIN {
+ chdir 't' if -d 't';
+ require Config; import Config;
+ require './test.pl';
+ set_up_inc('../lib');
+ skip_all_if_miniperl();
+ for my $needed (qw(d_socket)) {
+ if ($Config{$needed} ne 'define') {
+ skip_all("-- \$Config{$needed} undefined");
+ }
+ }
+ unless ($Config{extensions} =~ /\bSocket\b/) {
+ skip_all('-- Socket not available');
+ }
+}
+
+use strict;
+use IO::Handle;
+use Socket;
+
+{
+ socketpair(my $a, my $b, PF_UNIX, SOCK_STREAM, 0)
+ or skip_all("socketpair() for PF_UNIX failed ($!)");
+}
+
+plan(tests => 8);
+
+{
+ my($a, $b);
+ ok socketpair($a, $b, PF_UNIX, SOCK_STREAM, 0), "create socket pair";
+ ok($a->printflush("aa\n"), "write one way");
+ ok($b->printflush("bb\n"), "write other way");
+ is(readline($b), "aa\n", "read one way");
+ is(readline($a), "bb\n", "read other way");
+ ok(close $a, "close one end");
+ ok(close $b, "close other end");
+}
+
+SKIP: {
+ skip "no fcntl", 1 unless $Config{d_fcntl};
+ my($a, $b);
+ socketpair($a, $b, PF_UNIX, SOCK_STREAM, 0) or die "socketpair: $!";
+ my $fda = fileno($a);
+ my $fdb = fileno($b);
+ fresh_perl_is(qq(
+ print open(F, "+<&=$fda") ? 1 : 0, "\\n";
+ print open(F, "+<&=$fdb") ? 1 : 0, "\\n";
+ ), "0\n0\n", {}, "sockets not inherited across exec");
+}