3
0
mirror of https://github.com/pragma-/pbot.git synced 2024-11-20 02:49:49 +01:00

IRC/Connection: sl() now dispatches pbot.output_queue_flushed pacing time gets reset

This commit is contained in:
Pragmatic Software 2021-07-03 23:12:34 -07:00
parent d41b91fb3e
commit abaf0a29f0
2 changed files with 20 additions and 11 deletions

View File

@ -54,6 +54,7 @@ my %autoloaded = (
'hostname' => undef, 'hostname' => undef,
'pacing' => undef, 'pacing' => undef,
'utf8' => undef, 'utf8' => undef,
'pbot' => undef,
'ssl' => undef, 'ssl' => undef,
'ssl_ca_path' => undef, 'ssl_ca_path' => undef,
'ssl_ca_file' => undef, 'ssl_ca_file' => undef,
@ -89,6 +90,7 @@ sub new {
_ssl_ca_file => undef, _ssl_ca_file => undef,
_utf8 => 0, _utf8 => 0,
_format => {'default' => "[%f:%t] %m <%d>",}, _format => {'default' => "[%f:%t] %m <%d>",},
_pbot => undef,
}; };
bless $self, $proto; bless $self, $proto;
@ -232,6 +234,7 @@ sub connect {
$self->pacing($arg{'Pacing'}) if exists $arg{'Pacing'}; $self->pacing($arg{'Pacing'}) if exists $arg{'Pacing'};
$self->debug($arg{'Debug'}) if exists $arg{'Debug'}; $self->debug($arg{'Debug'}) if exists $arg{'Debug'};
$self->utf8($arg{'UTF8'}) if exists $arg{'UTF8'}; $self->utf8($arg{'UTF8'}) if exists $arg{'UTF8'};
$self->pbot($arg{'PBot'}) if exists $arg{'PBot'};
$self->ssl($arg{'SSL'}) if exists $arg{'SSL'}; $self->ssl($arg{'SSL'}) if exists $arg{'SSL'};
$self->ssl_ca_path($arg{'SSL_ca_path'}) if exists $arg{'SSL_ca_path'}; $self->ssl_ca_path($arg{'SSL_ca_path'}) if exists $arg{'SSL_ca_path'};
$self->ssl_ca_file($arg{'SSL_ca_file'}) if exists $arg{'SSL_ca_file'}; $self->ssl_ca_file($arg{'SSL_ca_file'}) if exists $arg{'SSL_ca_file'};
@ -1357,9 +1360,11 @@ sub sl {
unless (@_) { croak "Not enough arguments to sl()"; } unless (@_) { croak "Not enough arguments to sl()"; }
if (!$self->pacing) { return $self->sl_real($line); } if (!$self->pacing) {
return $self->sl_real($line);
}
if ($self->{_slcount} < 14) { if ($self->{_slcount} < 10) {
$self->{_slcount}++; $self->{_slcount}++;
$self->{_lastsl} = time; $self->{_lastsl} = time;
return $self->schedule_output_event(0, \&sl_real, $line); return $self->schedule_output_event(0, \&sl_real, $line);
@ -1367,12 +1372,18 @@ sub sl {
# calculate how long to wait before sending this line # calculate how long to wait before sending this line
my $time = time; my $time = time;
if ($time - $self->{_lastsl} > $self->pacing) { $self->{_lastsl} = $time; } if ($time - $self->{_lastsl} > $self->pacing) {
else { $self->{_lastsl} += $self->pacing; } $self->{_lastsl} = $time;
} else {
$self->{_lastsl} += $self->pacing;
}
my $seconds = $self->{_lastsl} - $time; my $seconds = $self->{_lastsl} - $time;
if ($seconds == 0) { $self->{_slcount} = 0; } if ($seconds == 0) {
$self->{_slcount} = 0;
$self->pbot->{event_dispatcher}->dispatch_event('pbot.output_queue_flushed');
}
### DEBUG DEBUG DEBUG ### DEBUG DEBUG DEBUG
if ($self->{_debug}) { print STDERR "S-> $seconds $line\n"; } if ($self->{_debug}) { print STDERR "S-> $seconds $line\n"; }

View File

@ -61,9 +61,6 @@ use PBot::Users;
use PBot::Utils::ParseDate; use PBot::Utils::ParseDate;
use PBot::WebPaste; use PBot::WebPaste;
# unbuffer stdout stream
STDOUT->autoflush(1);
# set standard output streams to encode as utf8 # set standard output streams to encode as utf8
binmode(STDOUT, ":utf8"); binmode(STDOUT, ":utf8");
binmode(STDERR, ":utf8"); binmode(STDERR, ":utf8");
@ -258,6 +255,7 @@ sub connect {
SSL_ca_file => $self->{registry}->get_value('irc', 'ssl_ca_file'), SSL_ca_file => $self->{registry}->get_value('irc', 'ssl_ca_file'),
SSL_ca_path => $self->{registry}->get_value('irc', 'ssl_ca_path'), SSL_ca_path => $self->{registry}->get_value('irc', 'ssl_ca_path'),
Debug => $self->{registry}->get_value('irc', 'debug'), Debug => $self->{registry}->get_value('irc', 'debug'),
PBot => $self,
) )
) )
{ {