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 © 2023 My linux world - by Marc RABAHI
Design by Marc RABAHI and encelades.

Fork me on GitHub