|
From: <jgr...@us...> - 2003-02-17 22:18:35
|
Update of /cvsroot/popfile/engine/Proxy
In directory sc8-pr-cvs1:/tmp/cvs-serv1781/Proxy
Modified Files:
POP3.pm
Log Message:
New pipready() helper subroutine in popfile.pl to test in a platform independent way whether a pipe is ready since Windows and non-Windows differ; new Proxy::POP3::flush_child_data routine used to move data out of the child pipes; flush_child_data now called in service and the reaper for POP3 so that we handle pipe data all the time and not just when a child dies; this fixes bug 685032 where when you downloaded a large amount of mail the counter would get messed up because of the pipe seeming to get full; also set autoflush on the pipe writer
Index: POP3.pm
===================================================================
RCS file: /cvsroot/popfile/engine/Proxy/POP3.pm,v
retrieving revision 1.31
retrieving revision 1.32
diff -C2 -d -r1.31 -r1.32
*** POP3.pm 13 Feb 2003 21:24:17 -0000 1.31
--- POP3.pm 17 Feb 2003 22:18:28 -0000 1.32
***************
*** 175,178 ****
--- 175,226 ----
# ---------------------------------------------------------------------------------------------
#
+ # flush_child_data
+ #
+ # Called to flush data from the pipe of each child as we go, I did this because there
+ # appears to be a problem on Windows where the pipe gets a lot of read data in it and
+ # then causes the child not to be terminated even though we are done. Also this is nice
+ # because we deal with the statistics as we go
+ #
+ # $kid PID of a child of POP3.pm
+ #
+ # ---------------------------------------------------------------------------------------------
+ sub flush_child_data
+ {
+ my ( $self, $kid ) = @_;
+
+ my $stats_changed = 0;
+ my $handle = $self->{children}{$kid};
+
+ while ( &{$self->{pipeready}}($handle) )
+ {
+ my $class = <$handle>;
+
+ if ( defined( $class ) ) {
+ $class =~ s/[\r\n]//g;
+
+ $self->{classifier}->{parameters}{$class}{count} += 1;
+ $self->{configuration}->{configuration}{mcount} += 1;
+ $stats_changed = 1;
+
+ debug( $self, "Incrementing $class for $kid" );
+ } else {
+
+ # This is here so that we get in errorneous position where the pipready
+ # function is returning that there's data, but there is none, in fact the
+ # pipe is dead then we break the cycle here. This was happening to me when
+ # I tested POPFile running under cygwin.
+
+ last;
+ }
+ }
+
+ if ( $stats_changed ) {
+ $self->{configuration}->save_configuration();
+ $self->{classifier}->write_parameters();
+ }
+ }
+
+ # ---------------------------------------------------------------------------------------------
+ #
# reaper
#
***************
*** 192,223 ****
if ( $#kids >= 0 ) {
- my $stats_changed = 0;
-
for my $kid (@kids) {
if ( waitpid( $kid, &WNOHANG ) == $kid ) {
! my $handle = $self->{children}{$kid};
!
! while ( <$handle> ) {
! my $class = $_;
! $class =~ s/[\r\n]//g;
!
! $self->{classifier}->{parameters}{$class}{count} += 1;
! $self->{configuration}->{configuration}{mcount} += 1;
! $stats_changed = 1;
!
! debug( $self, "Incrementing $_" );
! }
!
! debug( $self, "Done with $kid handle $handle" );
!
close $self->{children}{$kid};
delete $self->{children}{$kid};
}
}
-
- if ( $stats_changed ) {
- $self->{configuration}->save_configuration();
- $self->{classifier}->write_parameters();
- }
}
}
--- 240,252 ----
if ( $#kids >= 0 ) {
for my $kid (@kids) {
if ( waitpid( $kid, &WNOHANG ) == $kid ) {
! $self->flush_child_data( $kid );
close $self->{children}{$kid};
delete $self->{children}{$kid};
+
+ debug( $self, "Done with $kid" );
}
}
}
}
***************
*** 233,236 ****
--- 262,272 ----
{
my ( $self ) = @_;
+
+ # See if any of the children have passed up statistics data through their
+ # pipes and deal with it now
+
+ for my $kid (keys %{$self->{children}}) {
+ $self->flush_child_data( $kid );
+ }
# Accept a connection from a client trying to use us as the mail server. We service one client at a time
|