Logger: Reconnect after connection lost

This commit is contained in:
mrkubax10 2023-09-16 21:08:42 +02:00
parent 57365db9d8
commit b0fc9ff2a5

View File

@ -282,6 +282,7 @@ sub joinChannels {
} }
our @connections :shared; our @connections :shared;
our $running :shared = 1;
sub connectionWorker { sub connectionWorker {
my $aHost = $_[0]; my $aHost = $_[0];
@ -289,48 +290,50 @@ sub connectionWorker {
my $aServerName = $_[2]; my $aServerName = $_[2];
my $aChannels = $_[3]; my $aChannels = $_[3];
my %logFiles;
my $stream = connectToServer($aHost, $aPort, $aServerName);
my $streamSelect = IO::Select->new($stream);
my $buffer = ""; my $buffer = "";
my @actionQueue :shared; my @actionQueue :shared;
my @connection :shared = ($aServerName, \@actionQueue); my @connection :shared = ($aServerName, \@actionQueue);
push(@connections, \@connection); push(@connections, \@connection);
while(!eof($stream)) { my %logFiles;
if(scalar(@actionQueue)>0) { while($running) {
given($actionQueue[0]) { my $stream = connectToServer($aHost, $aPort, $aServerName);
when("JOIN") { my $streamSelect = IO::Select->new($stream);
joinChannel($stream, $actionQueue[1]); while(!eof($stream)) {
if(scalar(@actionQueue)>0) {
given($actionQueue[0]) {
when("JOIN") {
joinChannel($stream, $actionQueue[1]);
}
}
@actionQueue = ();
} }
}
@actionQueue = ();
}
my @canRead = $streamSelect->can_read(0); my @canRead = $streamSelect->can_read(0);
if(scalar(@canRead)==0) { if(scalar(@canRead)==0) {
next; next;
}
my $tempBuffer;
$stream->recv($tempBuffer, 512);
$buffer.=$tempBuffer;
my ($line, $remaining) = readLineFromBuffer($buffer);
$buffer = $remaining;
while(length($line)>0) {
my @command = parseIRCCommand($line);
#printf(":: Server -> %s\n", $line);
given($command[0]) {
when("PING") { handlePing($stream, \@command); }
when("PRIVMSG") { handlePrivMsg($stream, \@command, $aServerName, $aChannels, \%logFiles); }
when("JOIN") { handleJoin(\@command, $aServerName, \%logFiles); }
when("QUIT") { handleQuit(\@command, $aServerName, $aChannels, \%logFiles); }
when("PART") { handlePart(\@command, $aServerName, \%logFiles); }
when("376") { joinChannels($stream, $aChannels); } # end of MOTD
} }
($line, $remaining) = readLineFromBuffer($buffer); my $tempBuffer;
$stream->recv($tempBuffer, 512);
$buffer.=$tempBuffer;
my ($line, $remaining) = readLineFromBuffer($buffer);
$buffer = $remaining; $buffer = $remaining;
while(length($line)>0) {
my @command = parseIRCCommand($line);
#printf(":: Server -> %s\n", $line);
given($command[0]) {
when("PING") { handlePing($stream, \@command); }
when("PRIVMSG") { handlePrivMsg($stream, \@command, $aServerName, $aChannels, \%logFiles); }
when("JOIN") { handleJoin(\@command, $aServerName, \%logFiles); }
when("QUIT") { handleQuit(\@command, $aServerName, $aChannels, \%logFiles); }
when("PART") { handlePart(\@command, $aServerName, \%logFiles); }
when("376") { joinChannels($stream, $aChannels); } # end of MOTD
}
($line, $remaining) = readLineFromBuffer($buffer);
$buffer = $remaining;
}
} }
close($stream);
} }
close($stream);
} }
sub createLogger { sub createLogger {