My linux world » Perl – Time Out Operation

Perl - Time Out Operation


        eval {
            local $SIG{ALRM} = sub { die "alarm\n" }; # NB: \n required
            alarm $timeout;
            my $nread = sysread $socket, $buffer, $size;
            alarm 0;
        };
        if ($@) {
            die unless $@ eq "alarm\n";   # propagate unexpected errors
            # timed out
        }
        else {
            # didn't
        }

Copyright © 2024 My linux world - by Marc RABAHI
Design by Marc RABAHI and encelades.