All pastes #10889 Raw Edit

Stuff

public text v1 · immutable
#10889 ·published 2005-05-04 11:13 UTC
rendered paste body
sub gotOK
{
        #Return 1 if $sock, the argument, contains a OK, else false
        if(@_ != 1)
        {
                warn "Calling function gotOK without right parameter count, aborting\n";
                return 0;
        }
        my $READ_TIMEOUT = 10;
        my $sock = $_[0];
        my $getline;
        eval
        {
        local $SIG{ALRM} = sub { die "alarm\n" }; # NB: \n required
        alarm $READ_TIMEOUT;
                $getline = <$sock>;
                alarm 0;
        };
        if ($@) #timed out during connecting to server...
        {
        die unless $@ eq "alarm\n";
                warn "Timeout during read from server...\n";
                return 0;
        }
        warn "this should not happen!\n" unless($getline);
        if($getline =~ /^OK\s*$/)
        {
                return 1;
        }
        return 0;
}