I'm quite sure this is something very dumb, but one of my small programs just exits when the other end of a TCP connection is terminated. Let's have a look parts of the code:
my $sock = eval { IO::Socket::INET->new( PeerAddr => $host, PeerPort => $port, Proto => 'tcp', ) or die $@; }; # ... my $lw = syswrite($sock, $$data); #line 91 die $! unless defined $lw and $lw == length($$data);
This are two snippets, each is also burried in a couple of eval()s. As a target I connect to "nc -l -p 1234". As soon as I kill the nc (ctrl-c), the next syswrite() will exit the program without any message. I even ran a trace:
... 1122277564.69174 main /root/iosrv.pl 91 1122277564.69182 main /root/iosrv.pl 92 1122277564.69185 main /root/iosrv.pl 93 1122277564.69188 main /root/iosrv.pl 95 1122277564.6919 main /root/iosrv.pl 100 1122277564.69193 main /root/iosrv.pl 39 1122277574.70139 main /root/iosrv.pl 36 1122277574.70156 main /root/iosrv.pl 37 1122277574.70159 main /root/iosrv.pl 38 1122277574.70162 main /root/iosrv.pl 85 1122277574.70165 main /root/iosrv.pl 86 1122277574.70167 main /root/iosrv.pl 88 1122277574.7017 main /root/iosrv.pl 89 1122277574.70172 main /root/iosrv.pl 90 1122277574.70174 main /root/iosrv.pl 91
Exactly what I'd expect, exept that the program just ends there. (line 91 is the syswrite())

I also tried to use print() instead of syswrite(), same problem. I tried with "v5.8.4 built for i686-linux" (self compiled) and "v5.6.1 built for i386-linux" (debian woody).

Any idea what the problem might be?


Search, Ask, Know

In reply to unexpected program abort on write on closed handle by Beechbone

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.