Glib IO watchers don't work on Windows



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.

On Windows,
with perl >= 5.18, it goes as far as "ok 6" then hangs (with 0% CPU),
with perl <= 5.16, it goes only to "ok 4", then hangs (with 100% CPU).

No AnyEvent here, no obsolete Gtk2, no fancy stuff, just plain Gib. (Glib version 1.305, libglib version 2.28)

If this is a known and expected state of affairs, then it would have been good if it were documented somewhere.

Thanks,
Peter Juhasz



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]