Someone showed me how to do timeouts with the alarm() function on UNIX, as in the following code, which would timeout if the connect() function did not succeed after $timeout seconds (although I couldn't tell from reading the code, how it worked):

eval {
        local $SIG{ALRM} = sub { die "alarm clock restart" };
        alarm $timeout;
        $result = connect(SOCK, $paddr);
        if (!$result)
        {
                $socketerror = $!;
        }
        alarm 0;
};
if ($@ =~ /alarm clock restart/)
{
        # timeout was reached
}

However, I'm trying to do something similar in ActivePerl (v5.8.3 build 809) but the ActivePerl-Winfaq5.html file says that the alarm() function is not implemented in ActivePerl. So is there a way in ActivePerl to force a block of code to time out after a certain number of seconds? This is the code that I'm trying to make time out:

my $server = IO::Socket::INET->new( Proto     => 'tcp',
                                 LocalPort => $PORT,
                                  Listen    => SOMAXCONN,
                                  Reuse     => 1);
$server->accept();

I tried seeing if the accept() function had its own timeout that I could use -- this is what the documentation says:

>>>
accept([PKG])

perform the system call accept on the socket and return a new object. The new object will be created in the same class as the listen socket, unless PKG is specified. This object can be used to communicate with the client that was trying to connect.
In a scalar context the new socket is returned, or undef upon failure. In a list context a two-element array is returned containing the new socket and the peer address; the list will be empty upon failure.


The timeout in the [PKG] can be specified as zero to effect a ``poll'', but you shouldn't do that because a new IO::Select object will be created behind the scenes just to do the single poll. This is horrendously inefficient. Use rather true select() with a zero timeout on the handle, or non-blocking IO.
>>>


but I have no idea how to specify an argument to pass in place of [PKG] to specify a timeout.

        -Bennett

[EMAIL PROTECTED]     http://www.peacefire.org
(425) 497 9002

_______________________________________________
Perl-Win32-Users mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to