Actually, I think I've tracked it down quite a bit further.  It's
something in IO::Socket to do with it's Timeout argument.  If "Timeout"
is not passed as an argument to IO::Socket, there is no error or crash. 
If it is specified (which Net::SNPP does internally), the crash occurs.

New test script is attached.

Commenting out line 46 of IO/Socket.pm in perl 5.8.2 gets rid of the
error for everything that uses IO::Socket at the expense of not having
_any_ timeouts for anything using IO::Socket.

-Al

On Fri, 2003-12-19 at 15:42, Elizabeth Mattijsen wrote:
> At 15:30 -0500 12/19/03, Al Tobey wrote:
> >  > Why are you doing:
> >>
> >>     threads->self->yield;
> >>
> >>  in make_client?  Does the problem occur when you remove this, or 
> >>replace it by:
> >>
> >>     threads->yield;
> >
> >Mistake, but removing it entirely does not change the result of the
> >test.  It's irrelevant and probably stupid - I just put it there to make
> >sure that the server could get ready in time.
> 
> Have you tried replacing it with a "sleep 5" or something like that? 
> That would at least rule out that.

Yes.

> 
> Alternately, could you try this approach:
> 
> =====================================================
> #!/usr/local/bin/perl -w
> use strict;
> use threads;
> 
> my $server = threads->create( \&make_server );
> sleep 1;
> my $client = threads->create( \&make_client );
> 
> $client->join();
> $server->join();
> 
> exit 0;
> 
> sub make_server {
>      require Net::SNPP; Net::SNPP->import;
>      require Net::SNPP::Server; Net::SNPP::Server->import;
>      my $server = Net::SNPP::Server->new(
>          Port => 20001,
>          BindTo => 'localhost'
>      );
>      my $client = $server->client();
>      $server->handle_client( $client );
> }
> 
> sub make_client {
>      require Net::SNPP; Net::SNPP->import;
>      threads->self->yield;
>      my $client = Net::SNPP->new( 'localhost', Port=>20001 );
>      $client->send( Pager=>5555555555, Message=>"TEST" );
>      $client->quit;
> }
> =====================================================
> 
> This moves the loading of the Net::SNPP modules to run time inside 
> the thread.  If this fixes the problem, it would mean that Net::SNPP 
> isn't capable of running in different threads.

Been there, done that.  Thread::Use is cool :)

> 
> Liz



** ** **  PRIVILEGED AND CONFIDENTIAL  ** ** **
This email transmission contains privileged and confidential information 
intended only for the use of the individual or entity named above.  Any 
unauthorized review, use, disclosure or distribution is prohibited and 
may be a violation of law.  If you are not the intended recipient or a 
person responsible for delivering this message to an intended recipient, 
please delete the email and immediately notify the sender via the email 
return address or mailto:[EMAIL PROTECTED]  Thank you.

#!/usr/local/bin/perl -w
use strict;
use threads;
use IO::Socket;

my $server = threads->create( \&make_server );
sleep 1; # make sure server gets started
my $client = threads->create( \&make_client );

# changing these to "detach" changes the message,
# but an error still occurs
$client->join();
$server->join();

exit 0;

sub make_server {
    print "server thread started\n";
    my $server = IO::Socket::INET->new(
        LocalPort => 20001,
        LocalAddr => 'localhost',
        Type      => SOCK_STREAM,
        ReuseAddr => 1,
	    Listen    => SOMAXCONN,
	    Proto     => 'tcp'
    ) || die "Couldn't establish listening socket: $@";
    print "server socket ok\n";
    my $client = $server->accept();
    print "server has client connection\n";
    $client->send( "HELLO" );
    print "server sent HELLO\n";
    while ( 1 ) {
        $client->recv( my $input, 1024, 0 );
        print "server input: $input\n";
        last if ( $input =~ /QUIT/ );
    }

    $client->shutdown(2);
    $server->shutdown(2);

    print "server returning 0\n";
    return 0;
}

sub make_client {
    print "client thread started\n";
    my $client = IO::Socket::INET->new(
        PeerPort => 20001,
        PeerAddr => 'localhost',
        Timeout  => 120, # comment this line out to get rid of errors
	    Proto     => 'tcp'
    ) || die "client couldn't establish connection: $@";
    $client->recv( my $buf, 1024, 0 );
    print "client recieved\n";
    $client->send( "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" );
    print "client sent\n";
    $client->send( "QUIT" );
    print "client sent QUIT\n";

    $client->shutdown(2);
    return 0;
}

Reply via email to