Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re^2: Problem with IO::Select

by timos (Beadle)
on Mar 01, 2007 at 00:11 UTC ( [id://602625]=note: print w/replies, xml ) Need Help??


in reply to Re: Problem with IO::Select
in thread Problem with IO::Select

You are right of course. But this does not fix my problem. The results are the same with
while (length($rx_txt) > 0) { $sock->recv($rx_txt, 1024); $buff.=$rx_txt; }
But I have to admit I am a little bit ashamed of myself now. :-)

Replies are listed 'Best First'.
Re^3: Problem with IO::Select
by Thelonius (Priest) on Mar 01, 2007 at 00:36 UTC
    You still aren't reading anything. length(undef) is certainly not greater than 0.

    Also, $sock is not the right socket to be reading from anyway.

      Ah, ok. So I changed it to
      my $rx_txt = "something"; while (length($rx_txt) > 0) { $conn->recv($rx_txt, 1024); $buff.=$rx_txt; }
      But the problem stays the same.
        You probably meant to write:
        while ($rh->recv($rx_txt, 1024) > 0) { $buff .= $rx_txt; }
        But that's not good code when using 'select'. That's only okay if you're only handling one connection at a time. If you're only handling one connection at a time, don't use select.

        Also, I hope you know that adding a file handle for "~/.somefile" only makes sense if it's a fifo (named pipe).

        There are actually a lot of problems with your code. You should probably look at something somebody else has written. I recommend The Perl Cookbook, although there are a lot of free examples scattered about the internet.

        "can_read" really means "trying to read won't block", which means that end-of-file will cause can_read to keep returning "true" forever. That might be your problem.

        You need to detect end-of-file and then (probably) close the socket and stop asking if you can read from it.

        - tye        

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (4)
As of 2025-06-13 03:43 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.