in reply to Timeouts when reading from socket Filehandles?

Read up on select() and have a look at IO::Select. In particular, have a look at the IO::Select's can_read() method. It will do what you want. You just have to specify a timeout.

-sauoq
"My two cents aren't worth a dime.";
  • Comment on Re: Timeouts when reading from socket Filehandles?

Replies are listed 'Best First'.
Re: Timeouts when reading from socket Filehandles?
by Helter (Chaplain) on Aug 27, 2002 at 11:17 UTC
    If that does not offer exactly what you are looking for, what I have always done (in other languages, never had to do sockets with perl) was create a thread to handle the information. Attach a buffer and every now and again read the buffer to see what is in it from your main loop. This assumes you have thread support compiled into your version of perl (My Admin at work is doing this very thing right now to solve a similar problem)
      Although threads are fun, using a thread to manage a socket is overkill. You can do just fine using IO::Select and a single process. UNIX people have been writing single-process socket handling applications for years, and they work very well.

      The problem with introducing threads is that you have to make sure your code is thread safe. As soon as you put two trains on the metaphorical track of your program, you're going to have to make sure you're not setting yourself up for disaster.