How to block until something is ready to read ????? 
Author Message
 How to block until something is ready to read ?????

        Would the following piece of code work, if I want to read
        when there is something on the pipe :

        ---------------------------------------------------
        pipe (MY_PIPE_READ, MY_PIPE_WRITE);
        sub my_read{
            $rin = $win = $ein = '';
            vec($rin, fileno(MY_PIPE_READ), 1) = 1;
            vec($win, fileno(MY_PIPE_WRITE), 1) = 1;
            $ein = $rin | $win;

            ## Wait 20 seconds and abort
            ($nfound, $timeleft) = select($rout=$rin,
                                          $wout=$win,
                                          $eout=$ein,
                                          $timeout);

           ## Check if timed out
           if (????????)
           {
                return;
           }
           else
           { ## There is something on the pipe to read
                sysread(MY_READ_PIPE, $buf, 256);
           }
      } # End of subroutine

      -------------------------------------------------------------
        Since $timeleft is not always set correctly (According to
        Camel book P.178), how can I check wether or not I received
        something on the pipe in the ($timeout)  interval?




Mon, 28 Apr 1997 22:29:48 GMT  
 How to block until something is ready to read ?????

Quote:
>        Would the following piece of code work, if I want to read
>        when there is something on the pipe :
>        ---------------------------------------------------
>        pipe (MY_PIPE_READ, MY_PIPE_WRITE);
>        sub my_read{
>            $rin = $win = $ein = '';
>            vec($rin, fileno(MY_PIPE_READ), 1) = 1;
>            vec($win, fileno(MY_PIPE_WRITE), 1) = 1;
>            $ein = $rin | $win;
>            ## Wait 20 seconds and abort
>            ($nfound, $timeleft) = select($rout=$rin,
>                                          $wout=$win,
>                                          $eout=$ein,
>                                          $timeout);

That will return immediately, since the pipe is always ready for something.
Sometimes it's ready for reading, sometimes for writing, sometimes for both.

If you're interested in the read end of the pipe only, you'd use:

        ($nfound, $timeleft) = select($rout=$rin, undef, undef, $timeout);

Quote:
>           ## Check if timed out
>           if (????????)
                !$nfound        
>           {

--
Hope this helps,

HansM



Wed, 30 Apr 1997 02:12:03 GMT  
 How to block until something is ready to read ?????

Quote:

>            vec($rin, fileno(MY_PIPE_READ), 1) = 1;
>            vec($win, fileno(MY_PIPE_WRITE), 1) = 1;
>            $ein = $rin | $win;
>            ($nfound, $timeleft) = select($rout=$rin,
>                                          $wout=$win,
>                                          $eout=$ein,
>                                          $timeout);
>      -------------------------------------------------------------
>        Since $timeleft is not always set correctly (According to
>        Camel book P.178), how can I check wether or not I received
>        something on the pipe in the ($timeout)  interval?

You just need to use the vec() to check your file descriptor:

        ... select($rout=$rin, ....
        if (vec($rout, fileno(MY_PIPE_READ),1)) {
                # There's data ready to be read, read it.
        }

Also, if $nfound is 0 then there isn't anything to be read.  The
converse is not necessarily true.

-Dave



Wed, 30 Apr 1997 17:27:07 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Why do non-blocking reads block?

2. Am I doing something wrong here ....

3. Am I doing something stupid here?

4. cgi.pm cookie function - am I missing something?

5. Sorting question: I think I am missing something obvious

6. Am I looking for something thats not there?

7. AM I missing something..

8. Problem with Pack/Unpack - I hope I am missing something here

9. Am I missing something???

10. grid() problem - am I missing something obvious?

11. Read this file from the end until...

12. help for reading something special in a file

 

 
Powered by phpBB® Forum Software