reading from GInputStream



Hello

I'm trying to read data from GInputStream:


use strict; use warnings;
use Glib::Object::Introspection;
Glib::Object::Introspection->setup(qw'basename Gio version 2.0 package Gio');
use Gtk3; use HTTP::Soup; use Gtk3::WebKit;

my $session = Gtk3::WebKit::get_default_session;

$session->request('http://perl.org')->send_async(undef, sub {
    my ($req, $id) = @_;
    my $stream = $req->send_finish($id);
    # my $bytes = $stream->read_bytes(4096);
    # line above fails with: "GType GBytes (48024976) is not registered with gperl at.."
    my @buf = (undef)x(2**22); #4Mb max
    my ($status, $bytes) = $stream->read_all(\ buf);
    if ($status) {
        splice @buf, $bytes; # truncate
        printf "read %d bytes but defined %d\n",
               $bytes, scalar grep defined, @buf;
    }
    Gtk3->main_quit
});

Gtk3->main;


.. but got empty buffer(@buf). Is it a bug or I do it wrong?


-
best regards


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