Re: async IO and gtk




On Nov 7, 2004, at 9:54 AM, Ross McFarland wrote:

On Sun, 2004-11-07 at 01:15, Eric Mangold wrote:
I would like to know the correct way to use asyncronous sockets with gtk-perl. From my reading of the docs it appears that GIOChannel's are used to handle sockets, but they are not wrapped by gtk-perl.

sure they are:

more precisely, what you need to use GIOChannel is wrapped; at this point, that's just Glib::IO::add_watch(). perl already provides native support for generic file handles and sockets, so the bindings don't include GIOChannel (where the functionality of perl and GLib overlap, we choose perl's version).


Is there a way to create a socket with perl and have gtk do the select()-ing on it and call my code when interesting things happen?

$socket->fileno should give you the fd you need to pass to add watch. you may have to "use Socket" for that to work, i can't remember.

fileno() is a builtin. IO::Socket::fileno() is the OO wrapper that you get if $socket was created by IO::Socket.


fileno() gets the underlying OS file descriptor from a perl file handle. as Glib::IO::add_watch() is selecting on the file descriptor and doesn't know about perl's I/O buffers, you want to use sysread() and syswrite() instead of print() and the <> operator.


--
Examples really shouldn't include unexploded ordnance.
  -- Joe Smith, referring to an example program i wrote.




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