> -----Original Message-----
> From: Chas Owens [mailto:[EMAIL PROTECTED] 
> Sent: Thursday, June 14, 2007 12:10 PM
> To: Bob McConnell
> Cc: beginners@perl.org
> Subject: Re: Having trouble porting an application to MS-Windows
> 
> On 6/14/07, Chas Owens <[EMAIL PROTECTED]> wrote:
> > On 6/14/07, Bob McConnell <[EMAIL PROTECTED]> wrote:
> > > In "perlport - Writing portable Perl" in the Alphabetic 
> list of Perl
> > > Functions:
> > >
> > > alarm SECONDS
> > > alarm
> > >     Not implemented. (Win32)
> > >
> > > I couldn't find anything in the ActiveState release notes that
> > > contradicted that.
> > snip
> > > > the latest version of ActiveState Perl on Windows XP works.
> > snip
> >
> > Are you using the latest version of ActiveState Perl?  I 
> installed the
> > latest version this morning to test the code I sent and when I run
> >
> > perldoc -T perlport | find /i alarm
> >
> > I get not output.  The first three functions listed are -X, 
> atan2, and binmode.
> >
> 
> In fact, the reference to alarm drops out of perlport in version 5.8.3
> (released in 2004).
> 
> from Perl 5.8.3's Changes file
>              [ 21895]
>              alarm() is now implemented on Win32.
> 

I still can't get it to work, even without the fork. I am now running
ActivePerl 5.8.8.820 on Win2K SP4. Here are the code snippets after
pasting in the recommended alarm handling:

-----------------------------------
$port = 'COM4' unless $port;

$SIG{'INT'} = 'dokill';         # this allows me to kill it with
CTRL-Break
sub dokill {
    kill 9,$child if $child;
}

sysopen( PORT, "$port", O_RDWR ) or die "Can't sysopen $port: $!";
binmode(PORT);

LINE: while (<IN>) {        # Input records from input file.
        chomp;
        # loop on NAK or timeout with two retries
        $done = 0;
        $tries = 0;
        do {
                syswrite PORT, $_, length;

                $timeout = 3;

                eval {
                        local $SIG{ALRM} = sub { die "alarm\n" }; # NB:
\n required
                        alarm $timeout;
                        $nread = sysread PORT, $line, 1;
                        alarm 0;
                };
                if ($@) {
                        die unless $@ eq "alarm\n";   # propagate
unexpected errors
                        # timed out
                        print STDOUT " t/o";
                }
                else {
                        fprint STDOUT "sysread returned %d.\n", $nread;
                        if (ord $line == 21) {
                                print STDOUT " NAK";
                        }
                        if (ord $line == 6) {
                                print STDOUT " ACK";
                                $done = 1;
                        }
                }
        } while ($done == 0 && ++$tries < 3);
        print STDOUT "\n";
        if ($done == 0) {
                next LINE;
        }
        #send response and wait for ACK/NAK here

}
-----------------------------------

This transmits the packet, but never comes out of the eval() if it
doesn't receive a character. Is there anything obvious that I missed?

Even if this does work, can I set simultaneous alarms in multiple
threads?

Thank you,

Bob McConnell

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to