r3831 - trunk/Docs/server/rcon2irc
DONOTREPLY at icculus.org
DONOTREPLY at icculus.org
Tue Jul 15 05:06:25 EDT 2008
Author: div0
Date: 2008-07-15 05:06:17 -0400 (Tue, 15 Jul 2008)
New Revision: 3831
Modified:
trunk/Docs/server/rcon2irc/rcon2irc.pl
Log:
try to handle read errors
Modified: trunk/Docs/server/rcon2irc/rcon2irc.pl
===================================================================
--- trunk/Docs/server/rcon2irc/rcon2irc.pl 2008-07-15 08:52:15 UTC (rev 3830)
+++ trunk/Docs/server/rcon2irc/rcon2irc.pl 2008-07-15 09:06:17 UTC (rev 3831)
@@ -122,8 +122,18 @@
{
my ($self) = @_;
my $data = "";
- $self->{sock}->recv($data, 32768, 0);
- return $data;
+ if(defined $self->{sock}->recv($data, 32768, 0))
+ {
+ return $data;
+ }
+ elsif($!{EAGAIN})
+ {
+ return "";
+ }
+ else
+ {
+ return undef;
+ }
}
# $sock->fds() returns the socket file descriptor.
@@ -245,7 +255,10 @@
my ($self) = @_;
for(;;)
{
- length(my $s = $self->{connector}->recv())
+ my $s = $self->{connector}->recv();
+ die "read error\n"
+ if not defined $s;
+ length $s
or last;
next
if $s !~ /^\377\377\377\377n(.*)$/s;
@@ -352,7 +365,10 @@
my ($self) = @_;
for(;;)
{
- length(my $s = $self->{connector}->recv())
+ my $s = $self->{connector}->recv()
+ die "read error\n"
+ if not defined $s;
+ length $s
or last;
$self->{recvbuf} .= $s;
}
@@ -1306,37 +1322,52 @@
}
}
- for my $line($chan->recv())
+ eval
{
- # found one! Check if it matches the regular expression of one of
- # our handlers...
- my $handled = 0;
- for my $h(@handlers)
+ for my $line($chan->recv())
{
- my ($chanstr_wanted, $re, $sub) = @$h;
- next
- if $chanstr_wanted ne $chanstr;
- use re 'eval';
- my @matches = ($line =~ /^$re$/s);
- no re 'eval';
- next
- unless @matches;
- # and if it is a match, handle it.
- ++$handled;
- my $result = $sub->(@matches);
- last
- if $result;
+ # found one! Check if it matches the regular expression of one of
+ # our handlers...
+ my $handled = 0;
+ for my $h(@handlers)
+ {
+ my ($chanstr_wanted, $re, $sub) = @$h;
+ next
+ if $chanstr_wanted ne $chanstr;
+ use re 'eval';
+ my @matches = ($line =~ /^$re$/s);
+ no re 'eval';
+ next
+ unless @matches;
+ # and if it is a match, handle it.
+ ++$handled;
+ my $result = $sub->(@matches);
+ last
+ if $result;
+ }
+ # print the message, together with info on whether it has been handled or not
+ if($handled)
+ {
+ print " $chanstr >> $line\n";
+ }
+ else
+ {
+ print "unhandled: $chanstr >> $line\n";
+ }
}
- # print the message, together with info on whether it has been handled or not
- if($handled)
+ 1;
+ } or do {
+ if($@ eq "read error\n")
{
- print " $chanstr >> $line\n";
+ $channels{system}->send("error $chanstr", 0);
+ next CHANNEL;
}
else
{
- print "unhandled: $chanstr >> $line\n";
+ # re-throw
+ die $@;
}
- }
+ };
}
# handle scheduled tasks...
More information about the nexuiz-commits
mailing list