From e728276acaa5f011d2dbfa1f688ca07e1509669c Mon Sep 17 00:00:00 2001 From: Pragmatic Software Date: Sun, 16 Mar 2014 01:47:16 +0000 Subject: [PATCH] Add remove_reader() to SelectHandler and remove unnecessary foreground check from StdinReader's initialize() --- PBot/SelectHandler.pm | 16 +++++++++------- PBot/StdinReader.pm | 1 - PBot/VERSION.pm | 2 +- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/PBot/SelectHandler.pm b/PBot/SelectHandler.pm index f6287270..a3404238 100644 --- a/PBot/SelectHandler.pm +++ b/PBot/SelectHandler.pm @@ -35,28 +35,30 @@ sub add_reader { $self->{readers}->{$handle} = $sub; } +sub remove_reader { + my ($self, $handle) = @_; + $self->{select}->remove($handle); + delete $self->{readers}->{$handle}; +} + sub do_select { my ($self) = @_; my @ready = $self->{select}->can_read(.5); foreach my $fh (@ready) { - my $ret = sysread($fh, my $buf, 4096); + my $ret = sysread($fh, my $buf, 8192); if(not defined $ret) { $self->{pbot}->logger->log("Error with $fh: $!\n"); - $self->{select}->remove($fh); - delete $self->{readers}->{$fh}; + $self->remove_reader($fh); next; } if($ret == 0) { - $self->{pbot}->logger->log("done with $fh\n"); - $self->{select}->remove($fh); - delete $self->{readers}->{$fh}; + $self->remove_reader($fh); next; } chomp $buf; - $self->{pbot}->logger->log("read from $fh: [$buf]\n"); if(not exists $self->{readers}->{$fh}) { $self->{pbot}->logger->log("Error: no reader for $fh\n"); diff --git a/PBot/StdinReader.pm b/PBot/StdinReader.pm index aaf9da3b..795cdc22 100644 --- a/PBot/StdinReader.pm +++ b/PBot/StdinReader.pm @@ -28,7 +28,6 @@ sub initialize { # used to check whether process is in background or foreground, for stdin reading open TTY, "{tty_fd} = fileno(TTY); - $self->{foreground} = (tcgetpgrp($self->{tty_fd}) == getpgrp()) ? 1 : 0; $self->{pbot}->{select_handler}->add_reader(\*STDIN, sub { $self->stdin_reader(@_) }); } diff --git a/PBot/VERSION.pm b/PBot/VERSION.pm index d129d1fa..f6b61158 100644 --- a/PBot/VERSION.pm +++ b/PBot/VERSION.pm @@ -13,7 +13,7 @@ use warnings; # These are set automatically by the build/commit script use constant { BUILD_NAME => "PBot", - BUILD_REVISION => 528, + BUILD_REVISION => 529, BUILD_DATE => "2014-03-15", };