Commits

Shlomi Fish committed 1b6d668

Add the stale_checkpoints feature.

  • Participants
  • Parent commits 622da03

Comments (0)

Files changed (1)

File App-ManiacDownloader/lib/App/ManiacDownloader/_BytesDownloaded.pm

 has ['_bytes_dled', '_bytes_dled_last_timer'] =>
     (isa => 'Int', is => 'rw', default => sub { return 0;});
 
+has '_stale_checkpoints_count' => (isa => 'Int', is => 'rw',
+    default => sub { return 0;});
+
 sub _add
 {
     my ($self, $num_written) = @_;
     return $self->_bytes_dled;
 }
 
+sub _were_stale_checkpoints_exceeded
+{
+    my ($self, $MAX_COUNT) = @_;
+
+    return ($self->_stale_checkpoints_count >= $MAX_COUNT);
+}
+
 sub _flush_and_report
 {
     my $self = shift;
 
     my $difference = $self->_bytes_dled - $self->_bytes_dled_last_timer;
 
+    if ($difference > 0)
+    {
+        $self->_stale_checkpoints_count(0);
+    }
+    else
+    {
+        $self->_stale_checkpoints_count($self->_stale_checkpoints_count + 1);
+    }
+
     $self->_bytes_dled_last_timer($self->_bytes_dled);
 
     return ($difference, $self->_bytes_dled);