diff --git a/logger.pm b/logger.pm index 7a24af1..b30bd65 100644 --- a/logger.pm +++ b/logger.pm @@ -282,6 +282,7 @@ sub joinChannels { } our @connections :shared; +our $running :shared = 1; sub connectionWorker { my $aHost = $_[0]; @@ -289,48 +290,50 @@ sub connectionWorker { my $aServerName = $_[2]; my $aChannels = $_[3]; - my %logFiles; - my $stream = connectToServer($aHost, $aPort, $aServerName); - my $streamSelect = IO::Select->new($stream); my $buffer = ""; my @actionQueue :shared; my @connection :shared = ($aServerName, \@actionQueue); push(@connections, \@connection); - while(!eof($stream)) { - if(scalar(@actionQueue)>0) { - given($actionQueue[0]) { - when("JOIN") { - joinChannel($stream, $actionQueue[1]); + my %logFiles; + while($running) { + my $stream = connectToServer($aHost, $aPort, $aServerName); + my $streamSelect = IO::Select->new($stream); + while(!eof($stream)) { + if(scalar(@actionQueue)>0) { + given($actionQueue[0]) { + when("JOIN") { + joinChannel($stream, $actionQueue[1]); + } + } + @actionQueue = (); } - } - @actionQueue = (); - } - my @canRead = $streamSelect->can_read(0); - if(scalar(@canRead)==0) { - 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 + my @canRead = $streamSelect->can_read(0); + if(scalar(@canRead)==0) { + next; } - ($line, $remaining) = readLineFromBuffer($buffer); + 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); + $buffer = $remaining; + } } + close($stream); } - close($stream); } sub createLogger {