lom has asked for the wisdom of the Perl Monks concerning the following question:
I am struggling with IO::Socket::Unix. My issue can be summarized as follow:
I can accept that the writer can not write any more on the socket once it has been closed by the reader (although I would have guessed it should not matter), but I have not found a way in the writer to check if the socket is still usable. Is there something I can use for this purpose?
Here are my test scripts, trimmed down to the bare minimum showing this behavior:
Reader:
#!/usr/bin/perl use strict; use warnings; use IO::Socket::UNIX; my $SOCK = '/home/lomig/dev/imliner/run/tst.sock'; unlink $SOCK if -e $SOCK; my $read = IO::Socket::UNIX ->new ( Local => $SOCK, Listen=> SOMAXCONN, Type => SOCK_STREAM, Reuse =>1, ); $read || die "No read socket: $!\n"; print 'Read inode = ', (stat($read->hostpath()))[1], "\n"; my $client = $read->accept(); while (<$client>) { print "read: $_"; last if $_ =~ /2/; #exit after 3rd message } $client->close(); $read->close(); exec $0; # restart itself
Writer:
#!/usr/bin/perl use strict; use warnings; use IO::Socket::UNIX; my $write = IO::Socket::UNIX ->new( Peer => '/home/lomig/dev/imliner/run/tst.sock', Type => SOCK_STREAM, ) ; $write || die "No write socket: $!\n"; for (0..2) { print 'Write connected? ', $write->connected() ? 'yes' : 'no', "\n"; print 'Write opened? ' , $write->opened() ? 'yes' : 'no', "\n"; print 'Write errored? ' , $write->error() ? 'yes' : 'no', "\n"; print 'Write peerpath: ' , $write->peerpath(), "\n"; print'inode : ' , (stat($write->peerpath()))[1], "\n"; foreach my $i (0..2) { eval {print $write "Hi $i\n";}; if ($@) {print "Write issue: $@\n";} # *never* reached } print "Go to sleep while the reader restarts itself, then loop again +\n"; sleep 2; } $write->close();
Writer's output:
Write connected? yes Write opened? yes Write errored? no Write peerpath: /home/lomig/dev/imliner/run/tst.sock inode : 1517896 Go to sleep while the reader restarts itself Write connected? yes Write opened? yes Write errored? no Write peerpath: /home/lomig/dev/imliner/run/tst.sock inode : 1517896
And that's it, not segfault, exception, nothing.
I am using perl 5.10.0-23 on debian unstable, up to date.
Thank you very much for any help or pointer to help me understand this.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: IO::Socket::UNIX unexpected death
by targetsmart (Curate) on Jun 30, 2009 at 11:09 UTC | |
by lom (Sexton) on Jun 30, 2009 at 11:37 UTC | |
|
Re: IO::Socket::UNIX unexpected death
by tprocter (Sexton) on Jun 30, 2009 at 11:40 UTC | |
by lom (Sexton) on Jun 30, 2009 at 11:57 UTC |