* lib/Qpsmtpd/TcpServer.pm

Don't try to load the plugins if they are already loaded.

* lib/Qpsmtpd/Transaction.pm
  Get the size_threshold by inheritance.
  Extract the spooling of the body as a new sub.
  Always spool the body when calling body_filename().
  Compare the body_size to the cached size_threshold.

* lib/Qpsmtpd.pm
  Cache the size_threshold and provide an accessor method.

* qpsmtpd-forkserver
  Initialize both the spool_dir and size_threshold caches before forking.

git-svn-id: https://svn.perl.org/qpsmtpd/branches/0.31@547 958fd67b-6ff1-0310-b445-bb7760255be9
This commit is contained in:
John Peacock 2005-09-22 17:14:20 +00:00
parent 87baf0fbf1
commit 9cbf206a4a
4 changed files with 32 additions and 20 deletions

View File

@ -1,6 +1,6 @@
package Qpsmtpd; package Qpsmtpd;
use strict; use strict;
use vars qw($VERSION $Logger $TraceLevel $Spool_dir); use vars qw($VERSION $Logger $TraceLevel $Spool_dir $Size_threshold);
use Sys::Hostname; use Sys::Hostname;
use Qpsmtpd::Constants; use Qpsmtpd::Constants;
@ -415,6 +415,15 @@ sub temp_dir {
return $dirname; return $dirname;
} }
sub size_threshold {
my $self = shift;
unless ( defined $Size_threshold ) {
$Size_threshold = $self->config('memory_threshold') || 10_000;
$self->log(LOGNOTICE, "size_threshold set to $Size_threshold");
}
return $Size_threshold;
}
1; 1;
__END__ __END__

View File

@ -39,7 +39,7 @@ sub run {
my $self = shift; my $self = shift;
# should be somewhere in Qpsmtpd.pm and not here... # should be somewhere in Qpsmtpd.pm and not here...
$self->load_plugins; $self->load_plugins unless $self->{hooks};
my $rc = $self->start_conversation; my $rc = $self->start_conversation;
return if $rc != DONE; return if $rc != DONE;

View File

@ -15,9 +15,6 @@ sub start {
my %args = @_; my %args = @_;
my $self = { _rcpt => [], started => time }; my $self = { _rcpt => [], started => time };
bless ($self, $class); bless ($self, $class);
my $sz = $self->config('memory_threshold');
$sz = 10_000 unless defined($sz);
$self->{_size_threshold} = $sz;
return $self; return $self;
} }
@ -91,13 +88,27 @@ sub body_current_pos {
return $self->{_body_current_pos} || 0; return $self->{_body_current_pos} || 0;
} }
# TODO - should we create the file here if we're storing as an array?
sub body_filename { sub body_filename {
my $self = shift; my $self = shift;
return unless $self->{_body_file}; $self->body_spool() unless $self->{_body_file};
return $self->{_filename}; return $self->{_filename};
} }
sub body_spool {
my $self = shift;
$self->log(LOGWARN, "spooling to disk");
$self->{_filename} = $self->temp_file();
$self->{_body_file} = IO::File->new($self->{_filename}, O_RDWR|O_CREAT, 0600)
or die "Could not open file $self->{_filename} - $! "; # . $self->{_body_file}->error;
if ($self->{_body_array}) {
foreach my $line (@{ $self->{_body_array} }) {
$self->{_body_file}->print($line) or die "Cannot print to temp file: $!";
}
$self->{_body_start} = $self->{_header_size};
}
$self->{_body_array} = undef;
}
sub body_write { sub body_write {
my $self = shift; my $self = shift;
my $data = shift; my $data = shift;
@ -125,19 +136,7 @@ sub body_write {
$self->{_body_size} += length($1); $self->{_body_size} += length($1);
++$self->{_body_current_pos}; ++$self->{_body_current_pos};
} }
if ($self->{_body_size} >= $self->{_size_threshold}) { $self->body_spool if ( $self->{_body_size} >= $self->size_threshold() );
#warn("spooling to disk\n");
$self->{_filename} = $self->temp_file();
$self->{_body_file} = IO::File->new($self->{_filename}, O_RDWR|O_CREAT, 0600)
or die "Could not open file $self->{_filename} - $! "; # . $self->{_body_file}->error;
if ($self->{_body_array}) {
foreach my $line (@{ $self->{_body_array} }) {
$self->{_body_file}->print($line) or die "Cannot print to temp file: $!";
}
$self->{_body_start} = $self->{_header_size};
}
$self->{_body_array} = undef;
}
} }
} }

View File

@ -169,6 +169,10 @@ if ($PID_FILE) {
close PID; close PID;
} }
# Populate class cached variables
$qpsmtpd->spool_dir;
$qpsmtpd->size_threshold;
while (1) { while (1) {
REAPER(); REAPER();
my $running = scalar keys %childstatus; my $running = scalar keys %childstatus;