I have written a server application in Perl, using the IO::Socket API, and my app crashes when the remote client (for instance, "telnet") is killed with a signal.

I create a listening socket, select() upon it for new logins, accept() them, and later loop calling select() on the new client socket.

Meanwhile, in client land, I invoke something like

telnet my_host 7777 
and after establishing the connection, from another shell on the same machine as the telnet process, I invoke:
    ps -aef | grep telnet
    kill -INT PID_of_that_telnet
The telnet process dies, and my server reports having read a few bytes (always the same bytes), and staggers on with a socket in a closed state.
DEBUG: Read 5 bytes from client 1
       from host '10.0.0.13' port '33008'.
       r_buf='ÿôÿý'
(The last byte seems to be \r or \b or somesuch.)

My problem is that, in Perl 5.005 my server would terminate, with error messages I wanted to paste in here, but cannot reproduce with Perl 5.6.0 now. :-(
These error messages appeared to be from a die() in socket.pm or somesuch, and I figured it to be a bug in socket or IO::Socket.

And under Perl 5.6.0, my code to handle client dropout is not catching the "killed by signal" case.

(I will admit that not getting a die() from within socket code, as I saw under Perl 5.005, is handier. Perhaps now this case can be tested for and handled.)

So, what I would like to know is:

1) How to trap this error like I do for ordinary logout (such as when I issue Control-], "quit", ENTER in telnet). In that case I get 0 bytes read from sysread(), and do socket close() and cleanup activities.

2) Can this be made to work under Perl 5.005? Or has a bug been fixed since then that I should know of?

Server code bits:
-----------------

### Create the listening socket: $listen_socket = IO::Socket::INET-> new('Listen' => 5, 'LocalAddr' => $server_host, 'LocalPort' => $listen_port, 'Proto' => "TCP", ); # ... ### Handle login attempts: my $listen_bit = $listen_socket->fileno(); if (vec($r_vec, $listen_bit, 1) == 1) { print "Login attempt on listening socket...\n"; my $socket = $listen_socket->accept(); # ... } # ... ### Handle reading, and possible client dropout: $bytes_read = $socket->sysread($r_buf, _POSIX_PIPE_BUF, 0); # ... elsif ($bytes_read == 0) { do_socket_close_and_cleaup(); } # ...
----------------

Thanks for any advice,

--Sam <sglasby@penguinhosting.net>

Edit kudra, 2001-10-03 Took txt out of pre


In reply to Bug in IO::Socket::Inet in Perl 5.005 ??? by Anonymous Monk

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.