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

Hi I did read the documentation and did some tests but I got no success. Can someone give me a example of code of a simple client using socket to connect to any port and calling read to get data, but using select() to wait for example only 10 seconds before stop the read and continue the normal flow of the code? When we use select to timeout a read operation it is completely stooped? Or it's putted in a kind of background operation? Thank you
  • Comment on Example of Socket + Read with Select as timeout?

Replies are listed 'Best First'.
Re: Example of Socket + Read with Select as timeout?
by ikegami (Patriarch) on May 11, 2010 at 01:35 UTC

    The only thing missing from the example in the documentation is reading if $nfound isn't zero.

    Note that IO::Select is a thin layer around select that makes it easy to use.

    When we use select to timeout a read operation it is completely stooped?

    That makes no sense. "The select() system call examines the I/O descriptor sets whose addresses are passed in readfds, writefds, and exceptfds to see if some of their descriptors are ready for reading, are ready for writing, or have an exceptional condition pending, respectively." It blocks until it finds a descriptor that's ready or until time runs out. select does not cause other operations to timeout.

Re: Example of Socket + Read with Select as timeout?
by Anonymous Monk on May 11, 2010 at 01:24 UTC