Re: GPerlClosure and GIOChannel [patch and RFC]
- From: James Curbo <hannibal adtrw org>
- To: gtk-perl list <gtk-perl-list gnome org>
- Subject: Re: GPerlClosure and GIOChannel [patch and RFC]
- Date: Sat, 09 Aug 2003 18:28:33 -0500
muppet wrote:
> now, a new question is: should the GIOChannel be wrapped as a proper
perl file handle (and how would you do that?) or is it okay to leave it
as a fileno? and even more important, am i correct that we can just
ignore the GIOChannel at the perl level and use only the file
descriptor? is there any GIOChannel functionality that perl doesn't
already provide?
Well, personally, in the one program I have written in C using
GIOChannels, I didn't use them for unified IO access, I used them
because you have to integrate your IO source (for me, sockets) into the
event loop somehow.
So it goes like this, in C:
Create a socket (or another fd type) -> socket()
create a GIOChannel and tie the socket into it -> g_io_channel_unix_new
add the channel to the event loop -> g_io_add_watch
respond to events on the socket -> GIOFunc
read and write to the socket -> g_io_channel_read, g_io_channel_write
In the Perl case, I think it would be pretty cool to have the channel
wrapped as a proper file handle, so that you could use all your normal
Perl operations (from inside your IO callback, I assume).
So in perl you have:
create socket -> $sock = IO::Socket->new();
(no need for creationing a GIOChannel and tying it in...)
add channel to event loop ->
Gtk2::Helper->add_watch($sock, 'in', \&GIOFunc, $data);
respond to events on the socket -> sub GIOFunc (from above)
read and write to the socket ->
print $sock "hello world"; # for writing
<> or read or sysread etc # for reading
(instead of some $giochannel->read() stuff which is decidedly
non-perlish)
Looking over the GIOChannel docs, I don't see anything that isn't
provided by Perl already (Reading and writing by line and character,
seeking, flushing, shutting down a channel, setting and unsetting
buffering, getting/setting encoding (?), closing)
please try out the patch and let me know what you think.
I'll try and play around with it this weekend sometime.
--
muppet <scott at asofyet dot org>
James
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]