Re: piping from external program not working..
- From: muppet <scott asofyet org>
- To: gtk-perl list <gtk-perl-list gnome org>
- Subject: Re: piping from external program not working..
- Date: Sat, 5 Jun 2004 07:57:33 -0400
On Saturday, June 5, 2004, at 06:30 AM, Jan Hudec wrote:
On Fri, Jun 04, 2004 at 16:38:03 -0400, muppet wrote:
On Friday, June 4, 2004, at 03:18 PM, Jan Hudec wrote:
I really wish perl IO descriptors had a 'buffer' method. It would
return the internal buffer as a (read-only) string.
there is one, at the C level --- PerlIO_get_base(). see perlapio.
Then we could have Glib::IO watchers properly generating 'in' event
when the perlio descriptor (not the underlying file) have some data
to read!
how would you have it work? while the buffer is non-empty, keep firing
the 'in' condition? (that is, multiple 'in' dispatches for a single
file descriptor read.) or return the new data to the sub?
even if we see how many bytes are actually available, it's up the the
handler to decide if and how to read them, so the handler will still
have to do filehandle io carefully. also, how would you handle the
output situation? (e.g., the 'out' condition, when it's safe to write
to the socket.)
the old gtk-perl used some interesting MAGIC vtable tricks to allow
subs to be called whenever a scalar is changed. perhaps we should
modify Glib::IO::add_watch() to use a similar mechanism?
The vtable MAGIC was about the scalars. The interface to glib is not
magic at all. And for watching perlio objects, you don't need the
vtable magic.
On the glib side, it means to implement an object based on GSource
structure. It has a "vtable" GSourceFuncs with four functions --
prepare, check, dispatch and finalize.
yeah, i understand all of that. what i was referring to was in
Gtk-Perl/Gtk/xs/Gtk.xs, the implementation of Gtk::watch_add(), which
creates a GSource containing functions that watch magical SVs. this
caused the main loop to wake up whenever anything happened to that
scalar.
i forgot that the old version of Glib::IO::add_watch() was
Gtk::Gdk::input_add(); for some reason i thought that the magical
scalar implementation of watch_add would handle io events as well.
note that the old version (input_add()) used plain file descriptors, as
well.
prepare is called before poll. It must look whether there are data in
the buffer. This is actualy the hardest part, at least for me, since I
don't understand internals of perlio. prepare returns true if the
source is ready (buffer not empty).
there's a macro to get the number of bytes in the buffer,
PerlIO_get_cnt().
--
"Ghostbusters" is the best movie of this decade.
-- Neal, circa 1996, referring to a movie released in 1984.
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]