Hi, all! I'm learning about dealing with sockets in Perl, and I've got a
question about some unexpected behaviour exhibited by the following test
script.

In the case where I open a connection and then close it before
$socket->accept() is called, I'd except $socket->accept() to return undef,
but it never does. Will someone kindly tell me why this is?

Thanks in advance!



#!/usr/bin/perl

use strict;
use warnings;

use IO::Select;
use IO::Socket;

my $socket = IO::Socket::INET->new(
        "Proto" => "tcp",
        "LocalPort" => "31337",
        "Listen" => SOMAXCONN,
        "Blocking" => 0) or die "Ah! Bugger!\n";
$socket->autoflush(1);

my $select = IO::Select->new();
$select->add($socket);

while (1) {
        # Accept new connections. Won't bother to process more than one
        # per loop iteration.
        my @can_read = $select->can_read(0);
        if (scalar @can_read > 0) {
                print "Connection found...\n";
                print "  Sleeping five seconds.\n";
                sleep 5;
                my $client = $socket->accept();
                if (not defined $client) {
                        print "  Didn't work out!";
                        next;
                }
                print "  Accepted!\n";
        }
}

-- 
 Mason Loring Bliss         [EMAIL PROTECTED]        http://blisses.org/  
"I am a brother of jackals, and a companion of ostriches."  (Job 30 : 29)

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to