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

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

From:
Hank Barta
Date:
November 29, 2000 14:05
Subject:
IO::Socket::INET::send unexpected exit
Message ID:
Pine.NEB.3.96.1001129153803.63472A-100000@shell-3.enteract.com

    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 ./sender.pl 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 server.pl with mo arguments

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

    3. Wait several seconds to allow sender.pl to establish connection.

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

    5. Wait several seconds for 'sender.pl' 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.)

    thanks,
    hank

-----------------------------server.pl
#!/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');
while(1)
{
    my $connect = $sock->accept();
    print "got connection\n";
    my $buf;
    until($connect->recv($buf, 1024))
    {;}
    print "lost connection\n";
}



----------------------------sender.pl
#!/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');

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




Hank Barta                            White Oak Software Inc.
hbarta@enteract.com                   Predictable Systems by Design.(tm)
		Beautiful Sunny Winfield, Illinois




nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About