in reply to Making IO::Socket::UNIX client time out

Nothing in the documentation for IO::Socket::UNIX says it takes a Timeout option; IO::Socket::INET does, but not the unix domain flavour nor its parent IO::Socket. That it doesn't produce some sort of warning on unsupported / unexpected arguments is . . . unexpected.

Update: Aaah, that's because (after RTFS) despite not being documented IO::Socket does handle Timeout. Hrmm, never mind me.

The cake is a lie.
The cake is a lie.
The cake is a lie.

Replies are listed 'Best First'.
Re^2: Making IO::Socket::UNIX client time out
by kroach (Pilgrim) on Oct 02, 2019 at 13:25 UTC
    IO::Socket does handle Timeout, what's more, it actually works in the server part of IO::Socket::UNIX. This server will stop if it doesn't receive a connection within 2 seconds:
    #!/usr/bin/perl use strict; use warnings; use IO::Socket::UNIX; use constant SOCKET => 'test_socket.sock'; my $mode = shift or die "Specify a mode\n"; if ($mode eq 'server') { my $server = IO::Socket::UNIX->new( Type => SOCK_STREAM, Local => SOCKET, Listen => 1, Timeout => 2, ) or die $!; while (my $conn = $server->accept()) { my $name = <$conn>; print {$conn} "Hello $name"; close $conn; } print 'Timed out', "\n"; } elsif ($mode eq 'client') { my $client = IO::Socket::UNIX->new( Type => SOCK_STREAM, Peer => SOCKET, ) or die $!; print {$client} 'John', "\n"; print "Got reponse: ", scalar <$client>; close $client; } else { die "Unsupported mode: $mode\n"; }