unexpected behavior with GIOChannels?
- From: <nega exmachinae net>
- To: gtk-perl-list gnome org
- Subject: unexpected behavior with GIOChannels?
- Date: Sun, 8 Jun 2003 16:56:41 -0400
Maybe it's unexpected, maybe I'm misinterpreting things.
First, a little bit of code.
#!/usr/bin/perl -w
use Data::Dumper;
use strict;
use IO::Socket;
use Gtk2;
Gtk2->init;
my $host;
my $port;
my $sock;
## setup the socket
$sock = new IO::Socket::INET(PeerAddr => $host,
PeerPort => $port,
Proto => 'tcp')
or die "Can't open socket: $!";
$sock->autoflush(1);
## setup handlers
my $io_id = Glib::IO->add_watch($sock->fileno, 'G_IO_IN', \&io_handler);#, $data);
Glib::IO->add_watch($sock->fileno, 'G_IO_HUP', sub {Glib::Source->remove($io_id)});#, $data);
sub io_handler {
shift; ## get rid of our CIOChannel source
my ($cond, $data) = @_;
print Dumper(\$cond);
}
__END__
If I connect that to something like netcat (nc -l $host -p $port),
then kill netcat, I'd expect a HUP since the socket is broken. Instead
i get an endless loop of:
$VAR1 = \[
'in'
];
Which seems odd since if there's no socket, how can there be data
waiting to be read?
Basicly my goal is to recognize when the other side has broken the
socket, so that perl can clean up its half. Am I even going about this
the right way?
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]