Dear.all;
This is a followup of my earlier thread "Async HTTP download...", which wasn't resolved.
It turns out that the problem is both deeper and easier to reproduce than I've thought: Glib::IO watchers themselves seem to be broken on Windows.
The following test program (which is adapted from a test from AnyEvent's test suite, just converted to plain Glib) runs as expected on Linux while it hangs on Windows:
###############################
#!/usr/bin/perl
use strict;
use warnings;
use Socket;
use Glib;
$| = 1;
my $mainloop = Glib::MainContext->default;
print "ok 1\n";
socketpair(my $s1, my $s2, AF_UNIX, SOCK_STREAM, 0);
print $s1 && $s2 ? "" : "not ", "ok 2 # $s1,$s2\n";
my ($wb, $rb, $wa, $ra);
$rb = Glib::IO->add_watch(fileno($s2), ['in', 'hup'], sub {
print "ok 6\n";
my $len = sysread $s2, my $buf, 1;
print "ok 7 $len '$buf'\n";
$wb = Glib::IO->add_watch(fileno($s2), ['out', 'hup'], sub {
print "ok 8\n";
Glib::Source->remove($wb);
undef $wb;
syswrite $s2, "1";
return 1;
});
return 1;
});
print "ok 3\n";
my $timer; $timer = Glib::Timeout->add(1000, sub {
Glib::Source->remove($timer);
undef $timer;
1;
});
$mainloop->iteration(1) while defined $timer;
print "ok 4\n";
$wa = Glib::IO->add_watch(fileno($s1), ['out', 'hup'], sub {
syswrite $s1, "0";
Glib::Source->remove($wa);
undef $wa;
print "ok 5\n";
return 1;
});
my $alive = 1;
$ra = Glib::IO->add_watch(fileno($s1), ['in', 'hup'], sub {
my $len = sysread $s1, my $buf, 1;
print "ok 9 $len '$buf'\n";
$alive = 0;
return 1;
});
$mainloop->iteration(1) while $alive;
#############################
On Linux, it creates a socketpair, tries writing from both directions, writes ok 1..9 in the proecess, then exists.