Re: reading from GInputStream



May I suggest this sort of code example be rewritten just a little bit, and sent to the list, in the format of a *.t file that uses Test::More?

Then it could be incorporated (if it's not based on a mistaken assumption) into the codebase to permanently constrain the code to work with that?

Automated testing for the win!

Ed

-----Original Message----- From: vividsnow
Sent: Monday, August 31, 2015 2:01 PM
To: gtk-perl-list gnome org
Subject: 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
_______________________________________________
gtk-perl-list mailing list
gtk-perl-list gnome org
https://mail.gnome.org/mailman/listinfo/gtk-perl-list

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