A good idea. In shorthand: #-------------------Connect to IRC Server-------------------
sub connecting {
# Connect to the IRC server.
$sock = new IO::Socket::INET(
PeerAddr => $irc,
PeerPort => 6667,
Proto => 'tcp',
) or die "Can't connect\n";
print $sock "NICK $nick\r\n";
print $sock "USER $login 8 * :CoCoNUE Member $nick\r\n";
$sel->add($sock);
#################################################
#Timeout
my $timer_chat = Glib::Timeout->add(1, \&incoming_data);
#################################################\
return 1;
}
#-------------------Watch for IRC Inputs-------------------
sub incoming_data {
if ($sel->can_read(1)){
my $input = <$sock>;
$input =~ s/\r\n//g;
my $hashref = $parser->parse( $input );
SWITCH: {
my $type = lc $hashref->{command};
my @args;
push @args, $hashref->{prefix} if $hashref->{prefix};
push @args, @{ $hashref->{params} };
if ( defined $dispatch{$type} ) {
$dispatch{$type}->(@args);
last SWITCH;
}
print STDOUT join( ' ', "irc_$type:", @args ), "\n";
}
}
return 1;
}
Now the only problem is that the GTK2 window stops responding. I think its caused by the my $input = <$sock> having nothing to read and it just makes the GTK2 program angry. Is there a way to avoid this other than adding a watch or any other crazy GTK2 dispatcher? Thanks for the help everyone. Update: should IO::Select be used? I have been barking up that tree with not much success either. I added the IO::Select to the loop and the program is now responding but it is very sluggish which is bad. any ideas? |