Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re: select($rin,undef,undef,undef) only blocking once

by Tanalis (Curate)
on Jul 26, 2005 at 10:14 UTC ( [id://478131]=note: print w/replies, xml ) Need Help??


in reply to select($rin,undef,undef,undef) only blocking once

The select function makes use of the C select(2) system call.

As the docs for select(2) state, file descriptors "will be watched to see if characters become available for reading (more precisely, to see if a read will not block ... a file descriptor is also ready on end-of-file)"

Once you've read data from the pipe once, the file pointer will be pointing at EOF, and hence the select call will always return ready.

In a situation like this, I would consider using a blocking read over blocking on file readiness; alternatively, look into the use of seek or sysseek to try to clear the file's EOF condition (which may not be possible - I can't test it here).

Hope that helps.

-- Foxcub
#include www.liquidfusion.org.uk

Update: rabbit7 indicates that sysseek doesn't work with a fifo. Updated to reflect this.

Replies are listed 'Best First'.
Re^2: select($rin,undef,undef,undef) only blocking once
by rabbit7 (Initiate) on Jul 26, 2005 at 11:30 UTC
    sysseek() does not work on a FIFO it seems.
    would it be a solution to reopen the FIFO before the select statement ?
    it works, but i dont think that is the proper way....
      It'd seem to be.

      I still favour a blocking read over blocking using select, though - you're using two system calls (which are relatively expensive) to do the job of one (unless there's something I'm missing).

      Paraphrasing the Cookbook a little, replacing your loop with

      for( ;; ) { open FIFO; "<", $fifofile or die $!; my $buf = <FIFO>; # blocks next unless defined $buf; chomp $buf; print $buf; close FIFO; }
      would seem to work as expected.

      Just as a final point, I'm not 100% sure what you're trying to achieve with your calls to index and substr - all you seem to be doing there is stripping the newline, which you can achieve using chomp.

      Hope that helps.

        the code i posted is just an example to demonstrate my problem with fifos. i am using select() because sometimes i want to return from waiting for input.

        select($rin,undef,undef,$timeout)
        i am not using $buf = <FH> because i thought your not supposed to use it when you use select()

Log In?
Username:
Password:

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

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

    No recent polls found