Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
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 7777and 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
|
|---|