commit - ccf6cafd5702b1123984566174106667c39070a5
commit + dbcfa451afea4a8bf56933462988cf943d663490
blob - 4d781faffcc83a3c1633897dcefa253b36804743
blob + 734a85eefab6b29d75ab92eba7bd36311a6cd2fc
--- mata_bot.pl
+++ mata_bot.pl
my ($level, $msg) = @_;
if ($msg) {
- syswrite(STDERR, $msg . "\n") if $loglevel >= $level
+ say STDERR $msg if $loglevel >= $level
} else {
$loglevel = $level;
}
else { logger(LOG_WARN, "sock not ready to write") }
return 0;
}
- syswrite($sock, $msg . "\r\n");
+ print $sock $msg . "\r\n";
logger(LOG_DEBUG, "<- " . $msg);
return 1;
}
my $s = shift;
while(1) {
- my ($chunk, $sock);
+ my ($line, $sock);
$_ = $buf;
if (not length) {
logger(LOG_ERROR, 'recieved a malformed message');
return undef;
}
- # read a chunk
+ # read a line
$! = 0;
unless (($sock) = $s->can_read($SOCK_TIMEOUT)) {
if ($!) {
}
return '';
}
- unless (sysread($sock, $chunk, 1)) {
+ unless ($line = <$sock>) {
if ($!) { logger(LOG_ERROR, $!) }
else { logger(LOG_WARN, 'recieved an empty message') }
return undef;
}
- $buf .= $chunk;
+ $buf .= $line;
}
}
}
sub usage {
- syswrite(STDERR, "usage: ${0} [-d|-v] [-t] [-b path] [-e path] [-h host] [-j join] [-p port] [-q path]\n");
+ say STDERR "usage: ${0} [-d|-v] [-t] [-b path] [-e path] [-h host] [-j join] [-p port] [-q path]";
exit 1;
}