1#!/usr/bin/perl 2use strict; 3use warnings qw(all); 4use lib 'inc'; 5 6use Test::More; 7use Test::HTTP::Server; 8 9use Net::Curl::Easy qw(/^CURL_WAIT_/); 10use Net::Curl::Multi; 11 12 13plan skip_all => "curl_multi_wait() is implemented since libcurl/7.28.0" 14 if Net::Curl::LIBCURL_VERSION_NUM() < 0x071C00; 15 16my $multi = Net::Curl::Multi->new() 17 or die "I forgot how to curl\n"; 18 19pipe my $fh_read, my $fh_write; 20 21my $ev_write = { 22 fd => fileno $fh_write, 23 events => CURL_WAIT_POLLOUT(), 24}; 25my $ev_read = { 26 fd => fileno $fh_read, 27 events => CURL_WAIT_POLLIN(), 28}; 29 30alarm 2; 31 32my $ret = $multi->wait( [ $ev_read ], 100 ); 33 34is( $ret, 0, "Expect nothing" ); 35 36ok( (not $ev_read->{revents}), "No events here" ); 37 38$ret = $multi->wait( [ $ev_read, $ev_write ], 500 ); 39 40is( $ret, 1, "One handle ready" ); 41 42ok( (not $ev_read->{revents}), "No events to read" ); 43is( $ev_write->{revents}, CURL_WAIT_POLLOUT(), "Ready to write" ); 44 45print $fh_write "Hello!\n"; 46$fh_write->flush(); 47 48$ret = $multi->wait( [ $ev_read ], 500 ); 49is( $ret, 1, "One handle ready" ); 50is( $ev_read->{revents}, CURL_WAIT_POLLIN(), "Ready to read" ); 51 52$ev_read->{revents} = 0; 53$ret = $multi->wait( [ $ev_read ], 500 ); 54is( $ret, 1, "One handle ready" ); 55is( $ev_read->{revents}, CURL_WAIT_POLLIN(), "Ready to read" ); 56 57my $line = <$fh_read>; 58 59$ret = $multi->wait( [ $ev_read ], 100 ); 60is( $ret, 0, "Nothing ready" ); 61is( $ev_read->{revents}, CURL_WAIT_POLLIN(), "Ready to read, because we did not reset" ); 62 63$ev_read->{revents} = 0; 64$ret = $multi->wait( [ $ev_read ], 100 ); 65is( $ret, 0, "Nothing ready" ); 66ok( !$ev_read->{revents}, "No events here" ); 67 68done_testing(13); 69