Hi;

On 31 August 2015 at 14:01, vividsnow <vivids...@gmail.com> wrote:
> 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');

You could use Glib::IO, but it needs to be released on CPAN at some point.

> 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;

read_all() returns an opaque pointer, thus the introspection machinery
has no idea how to pack it safely into a Perl value.

The proper solution is to use the read_bytes() variant, but GBytes is
not part of the perl-Glib type machinery, as you have noticed.

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

It's a missing feature — i.e. an enhancement.

Ciao,
 Emmanuele.

-- 
https://www.bassi.io
[@] ebassi [@gmail.com]
_______________________________________________
gtk-perl-list mailing list
gtk-perl-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-perl-list

Reply via email to