Re: gtk_input_add - code
- From: "Bhaskar S. Manda" <bhaskar cacmnet com>
- To: gtk-perl-list gnome org
- Subject: Re: gtk_input_add - code
- Date: Fri, 05 Apr 2002 14:21:39 -0600
In app_run() - initialization routine generated by Glade:
# Open some socket (or pipe with some command like `tail -f interesting_file`)
$interesting_socket = IO::Socket::INET->new(
Proto => 'tcp',
PeerAddr => $some_address,
PeerPort => $some_permitted_port );
if(!$interesting_socket){
carp "ERROR *** Could not open $some_address:$some_permitted_port!\n";
# return(-1);
}
else{
# Look, I can write to interesting_socket.
$interesting_socket->syswrite("0 I have connected.\n");
}
# Tell input_add to watch this file handle
$retval = Gtk::Gdk->input_add($interesting_socket->fileno, ['read'],
\&socket_handler, $interesting_socket);
Sub to call when there is something to read from handle:
sub socket_handler{
my ($fd_ptr, $fd, $widget) = @_;
# Read at most 1k bytes from socket, the rest stays there till our next
# read.
$length = $fd_ptr->sysread($in_str, 1024);
if(!$len){
carp "Remote end appears to have disconnected!\n";
# return(-2);
}
# Do something with the message - split at newlines, etc.
return 0;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]