perl 异步超时 打印错误

#!/usr/bin/perl

use AnyEvent;
use AnyEvent::HTTP;


my $cv = AnyEvent->condvar;

sub doit{
    my $url = shift ;
    return if not defined $url;

    $cv->begin;
    http_get( "$url",timeout => 20, sub { done( $url, @_ ) } );
    print "1111111111111111\n";
}

sub done {
    my ($url, $content, $hdr) = @_;

    $cv->end();
    print "Search: $url\tStatus: ", $hdr->{Status}, "\n";
    if ($hdr->{Status}==200)
             {
             print "\$content is $content\n";
             }elsif
            ($hdr->{Status}==596){
             print "time out\n";
            }}


&doit('http://120.55.118.6:3000/api/env?ip=192.168.32.101');
    print "222222222222222222\n";
    print "3333333333333333333\n";
$cv->recv();
~              

posted @ 2016-07-01 16:08  czcb  阅读(128)  评论(0编辑  收藏  举报