four-argument version of select

C. Abney cabney at cyberpass.net
Mon Jun 12 12:39:58 CDT 2000


~sdpm~
On Sun, 11 Jun 2000, John R. Comeau wrote:

> However I did get the simple case to timeout as
> expected:
> 
> 	select undef, undef, undef, 4.75;

I'm going to make an assumption, so please flame me as an ass if I'm
wrong. <g>

Are you sure you want to use 'vec' and 'select'???  That's a lot of
junk just to read a hello, world pipe.  Are you using vec because you
thought it was related to a 4 argument select in some way?

I don't really understand what they're doing: maybe you do.

I get this from perlipc:

       Signal handling is also used for timeouts in Unix,   While
       safely protected within an eval{} block, you set a signal
       handler to trap alarm signals and then schedule to have
       one delivered to you in some number of seconds.  Then try
       your blocking operation, clearing the alarm when it's done
       but not before you've exited your eval{} block.  If it
       goes off, you'll use die() to jump out of the block, much
       as you might using longjmp() or throw() in other
       languages.

And a warning in perlfunc "alarm":

       If you want to use alarm() to time out a system
       call you need to use an eval()/die() pair.  You
       can't rely on the alarm causing the system call to
       fail with $! set to EINTR because Perl sets up
       signal handlers to restart system calls on some
       systems.

Yeah right, whatever.

I got this code to do what (I think) you want:

->8-------------------------------------------
#! /usr/bin/perl -w

use strict;
my ( $rin, $time );

$time = 4;

eval {
        local $SIG{ALRM} = sub { die "no output from FIFO in $time seconds"; };
	# I'm making another assumption, here:
        local $/ = 'asdfakjdfajhdflkajhdflkafhlakf;afja';

        alarm $time;
        open FIFO, "< fifo" or die "ugh: $!";
        $rin = <FIFO>;
        close FIFO;
        alarm 0;
}; 
if ($@ and $@ =~ /no output from FIFO/) { die }

print STDOUT "Got:>>" . $rin . "<<\n";
->8-------------------------------------------

TEST1:
	tty1:$ ./select.plx

	tty0:$ cat hello
	milk
	tty0:$ cat hello > fifo

	(tty1)
	tty1:$ ./select.plx
	Got:>>milk
	<<
	tty1:$ 

TEST2:
	tty1:$ ./select.plx
	no output from FIFO in 4 seconds at ./select.plx line 9.
	        ...propagated at ./select.plx line 18
	tty1:$

HTH, Take Care,

CA
-- 
Einstein himself said that God doesn't roll dice. But he was wrong. And
in fact, anyone who has played role-playing games knows that God
probably had to roll quite a few dice to come up with a character like
Einstein.  -- Larry Wall                                     C. Abney

~sdpm~

The posting address is: san-diego-pm-list at hfb.pm.org

List requests should be sent to: majordomo at hfb.pm.org

If you ever want to remove yourself from this mailing list,
you can send mail to <majordomo at happyfunball.pm.org> with the following
command in the body of your email message:

    unsubscribe san-diego-pm-list

If you ever need to get in contact with the owner of the list,
(if you have trouble unsubscribing, or have questions about the
list itself) send email to <owner-san-diego-pm-list at happyfunball.pm.org> .
This is the general rule for most mailing lists when you need
to contact a human.




More information about the San-Diego-pm mailing list