Hi monks,

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.


In reply to IO::Socket::UNIX unexpected death by lom

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.