mirror of
https://github.com/pragma-/pbot.git
synced 2024-11-19 10:29:30 +01:00
Add remove_reader() to SelectHandler and remove unnecessary foreground check from StdinReader's initialize()
This commit is contained in:
parent
edd507b2e0
commit
e728276aca
@ -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");
|
||||
|
@ -28,7 +28,6 @@ sub initialize {
|
||||
# used to check whether process is in background or foreground, for stdin reading
|
||||
open TTY, "</dev/tty" or die $!;
|
||||
$self->{tty_fd} = fileno(TTY);
|
||||
$self->{foreground} = (tcgetpgrp($self->{tty_fd}) == getpgrp()) ? 1 : 0;
|
||||
|
||||
$self->{pbot}->{select_handler}->add_reader(\*STDIN, sub { $self->stdin_reader(@_) });
|
||||
}
|
||||
|
@ -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",
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user