Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Waiting and waiting?

by Gorby (Monk)
on Mar 04, 2003 at 04:05 UTC ( [id://240231]=perlquestion: print w/replies, xml ) Need Help??

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

Hello wise monks. In my short program are these lines:
for($xcounter=0; $xcounter<5; $xcounter=$xcounter+1) { @handles = $selector->can_read; }
Would the can_read function cause the program to wait indefinitely until a handle is available for reading, or would these lines simply execute 5 times regardless of whether a handle is available for reading? Thanks in advance for your wisdom.

Replies are listed 'Best First'.
Re: Waiting and waiting?
by dug (Chaplain) on Mar 04, 2003 at 04:35 UTC
    I assume that you left out the fact that you had the line use IO::Select in your code. Its documentation tells us:
           can_read ( "[ TIMEOUT ]" )
               Return an array of handles that are ready for reading. "TIMEOUT" is
               the maximum amount of time to wait before returning an empty list,
               in seconds, possibly fractional. If "TIMEOUT" is not given and any
               handles are registered then the call will block.
    

    So, yes, it will block the way you call it. If you want it to not block, pass it a timeout. Just like the documentation says.

    -- dug
Re: Waiting and waiting?
by heezy (Monk) on Mar 04, 2003 at 04:49 UTC

    I think dug pretty much covered everything, if you don't pass it a timeout value and you can't read, it will block indefinitly.

    M

    Edited 2003-03-03 by mirod: removed link to copyrighted material

      Please don't share links to copyrighted material distributed without the copyright holder's permission. If you really can't afford a Perl book and find the copious documentation distributed freely with Perl and available in many places on the Internet insufficient, contact me privately and I'll send you a book or two for free.

      If you share my book with a friend or two, or make a copy of a page (or the whole thing) for yourself, that's fine. I'm cool with that. Please don't republish it though. That's really pushing fair use, and it's not fair to everyone who worked on the book.

      Thanks.

      As merlyn pointed out earlier in the week on comp.lang.perl.misc (and probably many other times):
      "Please report those when you find them to <infringement@oreilly.com>.
      
      Otherwise, O'Reilly doesn't make their money, and I don't make my
      money, and I don't get to write more books."
      While I don't think you had malicious intent, you should be aware that the people hosting this site are are thieves.

      -- dug

      Wow, sorry about that! It was one of the top links that appeared on google when I searched about the "can_read" method! The page had graphics similar in style, or maybe that even were from, the O'Reilly site, I didn't think for a second that the material was stolen!

      I had no mallicious intent when posting that link, just trying to help someone out who hadn't come across "can_read" before.

      I am a great supporter of books and find them far easier to learn from than the majority of the content on the web (although there are some very good Perl tutorial sites). I especially support the O'Reilly series of books of which I have the Camel, and DBI Cheetah books.

      Appologies to chromatic for the misuse.

      I will be more careful in future

      M

      I came in late to this discussion and while I'm supportive of removing links to infringing sites ... was there any value in the link? I mean were you pointing out a particular book/page that helps with the original problem? If so, can we please have that citation (and with the isbn linkage)? If there was no value in the link, can you annotate the editing to "removed spurious/unhelpful link to copyrighted material."

      -derby

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://240231]
Approved by tye
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (6)
As of 2024-04-19 16:04 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found