unexpected behavior with GIOChannels?

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;


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: $!";

## 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);


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 = \[

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]