[svn:qpsmtpd] r547 - in branches/0.31: . lib lib/Qpsmtpd
[email protected] 22 Sep 2005 17:14:23 -0000
| Newsgroups | perl.cvs.qpsmtpd |
|---|---|
| Message-ID | <[email protected]> |
Author: jpeacock
Date: Thu Sep 22 10:14:20 2005
New Revision: 547
Modified:
branches/0.31/lib/Qpsmtpd.pm
branches/0.31/lib/Qpsmtpd/TcpServer.pm
branches/0.31/lib/Qpsmtpd/Transaction.pm
branches/0.31/qpsmtpd-forkserver
Log:
* 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.
Modified: branches/0.31/lib/Qpsmtpd.pm
==============================================================================
--- branches/0.31/lib/Qpsmtpd.pm (original)
+++ branches/0.31/lib/Qpsmtpd.pm Thu Sep 22 10:14:20 2005
@@ -1,6 +1,6 @@
package Qpsmtpd;
use strict;
-use vars qw($VERSION $Logger $TraceLevel $Spool_dir);
+use vars qw($VERSION $Logger $TraceLevel $Spool_dir $Size_threshold);
use Sys::Hostname;
use Qpsmtpd::Constants;
@@ -415,6 +415,15 @@ sub temp_dir {
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;
__END__
Modified: branches/0.31/lib/Qpsmtpd/TcpServer.pm
==============================================================================
--- branches/0.31/lib/Qpsmtpd/TcpServer.pm (original)
+++ branches/0.31/lib/Qpsmtpd/TcpServer.pm Thu Sep 22 10:14:20 2005
@@ -39,7 +39,7 @@ sub run {
my $self = shift;
# should be somewhere in Qpsmtpd.pm and not here...
- $self->load_plugins;
+ $self->load_plugins unless $self->{hooks};
my $rc = $self->start_conversation;
return if $rc != DONE;
Modified: branches/0.31/lib/Qpsmtpd/Transaction.pm
==============================================================================
--- branches/0.31/lib/Qpsmtpd/Transaction.pm (original)
+++ branches/0.31/lib/Qpsmtpd/Transaction.pm Thu Sep 22 10:14:20 2005
@@ -15,9 +15,6 @@ sub start {
my %args = @_;
my $self = { _rcpt => [], started => time };
bless ($self, $class);
- my $sz = $self->config('memory_threshold');
- $sz = 10_000 unless defined($sz);
- $self->{_size_threshold} = $sz;
return $self;
}
@@ -91,13 +88,27 @@ sub body_current_pos {
return $self->{_body_current_pos} || 0;
}
-# TODO - should we create the file here if we're storing as an array?
sub body_filename {
my $self = shift;
- return unless $self->{_body_file};
+ $self->body_spool() unless $self->{_body_file};
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 {
my $self = shift;
my $data = shift;
@@ -125,19 +136,7 @@ sub body_write {
$self->{_body_size} += length($1);
++$self->{_body_current_pos};
}
- 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;
- }
+ $self->body_spool if ( $self->{_body_size} >= $self->size_threshold() );
}
}
Modified: branches/0.31/qpsmtpd-forkserver
==============================================================================
--- branches/0.31/qpsmtpd-forkserver (original)
+++ branches/0.31/qpsmtpd-forkserver Thu Sep 22 10:14:20 2005
@@ -169,6 +169,10 @@ if ($PID_FILE) {
close PID;
}
+# Populate class cached variables
+$qpsmtpd->spool_dir;
+$qpsmtpd->size_threshold;
+
while (1) {
REAPER();
my $running = scalar keys %childstatus;