develooper Front page | perl.perl5.porters | Postings from November 2000

IO::Socket::INET::send unexpected exit

Hank Barta
November 29, 2000 14:05
IO::Socket::INET::send unexpected exit
Message ID:

    When I have connected using stream sockets and the 'other' end of the
    connection exits, send() exits with the messagea rather than
    returning an 'undef' valueD:

send: Cannot determine peer address at ./ line 14

    Or similar. I have duplicated this with version 1.16 of IO::Sockets on
    Solaris and Linux and with 1.20 on Linux.

    I have included below two scripts that can be used to demonstrate
    the problem by:

    1. Start with mo arguments

    2. Start " <hostname>" where <hostname> is the host on
       which '' is running.

    3. Wait several seconds to allow to establish connection.

    4. Kill '' with <ctrl>C at console.

    5. Wait several seconds for '' to send. It will exit
       with the indicated diagnostic message.

    While I am reluctant to call this a bug, it is certainly not
    the behavior that I expected.

    I would appreciate suggestions for the simplest work around to
    this difficulty if one is known. (I need to recover gracefully
    from this condition rather than exiting.)

#!/usr/local/bin/perl5 -w
require 5.002;
use strict;
use IO::Socket;

my $sock = IO::Socket::INET->new(Listen    => 5,
				 LocalPort => 15006,
				 Proto     => 'tcp');
    my $connect = $sock->accept();
    print "got connection\n";
    my $buf;
    until($connect->recv($buf, 1024))
    print "lost connection\n";
#!/usr/local/bin/perl5 -w
require 5.002;
use strict;
use IO::Socket;

my $s = new IO::Socket::INET( PeerAddr => shift,
			      PeerPort => 15006,
			      Proto    => 'tcp');

	unless defined $s->send(" this is a test\n");
    sleep 5;
print "send() returned an undefined value";

Hank Barta                            White Oak Software Inc.                   Predictable Systems by Design.(tm)
		Beautiful Sunny Winfield, Illinois Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About