dgaramond2 has asked for the wisdom of the Perl Monks concerning the following question:

I've been googling for 10-15 minutes but haven't found any real answer. So, anyone can tell me what's the deal with timeout in IO::Socket::INET? The timeout-related code in INET.pm has been commented probably since 5.6.x. Are we supposed to use alarm() now? It's a bit awkward since my daemon also needs to do some heavy work which I don't want to be trapped by alarm. But I want short timeout for sockets. My own protocol is chatty, so I have $blah = <$sock> sprinkled in many places, do I have to wrap each one of those with alarm? O wisdomy ones, please enlighten me.

Replies are listed 'Best First'.
Re: timeout in IO::Socket::INET
by tachyon (Chancellor) on Jul 10, 2004 at 01:35 UTC

    To the best of my memory the timout code in IO::Socket::INET only ever dealt with the time taken to get the socket connection.

    You have two basic* methods to limit the time spent waiting for real data on a socket. You can use 4 arg select to wait X seconds for a handle to have data on it for reading or you can use alarm(). Alarm is easier but is effectively unsafe (due to unsafe signals). select is the best solution. There is a tutorial on Using select and IO::Select.

    * you can also make a socket(s) non blocking and check for data in a loop.

    cheers

    tachyon