This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
NetBSD, Darwin, Cygwin don't appear to support SO_PROTOCOL
authorTony Cook <tony@develop-help.com>
Tue, 21 Jan 2020 04:17:30 +0000 (15:17 +1100)
committerTony Cook <tony@develop-help.com>
Tue, 28 Jan 2020 22:58:18 +0000 (09:58 +1100)
at least on AF_UNIX sockets.

We supply zero for protocol when creating AF_UNIX sockets, and
we no longer cache that incorrect value.  On systems such as NetBSD
that don't implement SO_PROTOCOL this means we can't fetch
the protocol and the protocol() method will hence return undef.

The same applies to Darwin and Cygwin.

dist/IO/t/cachepropagate-unix.t

index 9ec42b0..8427e9f 100644 (file)
@@ -40,7 +40,19 @@ my $listener = IO::Socket::UNIX->new(Type => SOCK_STREAM,
 ok(defined($listener), 'stream socket created');
 
 my $p = $listener->protocol();
-ok(defined($p), 'protocol defined');
+{
+    # the value of protocol isn't well defined for AF_UNIX, when we
+    # create the socket we supply 0, which leaves it up to the implementation
+    # to select a protocol, so we (now) don't save a 0 protocol during socket
+    # creation.  This test then breaks if the implementation doesn't support
+    # SO_SOCKET (at least on AF_UNIX).
+    # This specifically includes NetBSD, Darwin and cygwin.
+    # This is a TODO instead of a skip so if these ever implement SO_PROTOCOL
+    # we'll be notified about the passing TODO so the test can be updated.
+    local $TODO = "$^O doesn't support SO_PROTOCOL on AF_UNIX"
+        if $^O =~ /^(netbsd|darwin|cygwin)$/;
+    ok(defined($p), 'protocol defined');
+}
 my $d = $listener->sockdomain();
 ok(defined($d), 'domain defined');
 my $s = $listener->socktype();
@@ -90,7 +102,12 @@ SKIP: {
     ok(defined($listener), 'datagram socket created');
 
     $p = $listener->protocol();
-    ok(defined($p), 'protocol defined');
+    {
+        # see comment above
+        local $TODO = "$^O doesn't support SO_PROTOCOL on AF_UNIX"
+            if $^O =~ /^(netbsd|darwin|cygwin)$/;
+        ok(defined($p), 'protocol defined');
+    }
     $d = $listener->sockdomain();
     ok(defined($d), 'domain defined');
     $s = $listener->socktype();