Fix to check client is writable before writing to it.

git-svn-id: https://svn.perl.org/qpsmtpd/trunk@946 958fd67b-6ff1-0310-b445-bb7760255be9
This commit is contained in:
Matt Sergeant 2008-09-26 17:40:04 +00:00 committed by Ask Bjørn Hansen
parent 858fdbc11c
commit 59b826d4bb
4 changed files with 27 additions and 6 deletions

View File

@ -67,16 +67,17 @@ sub start_connection {
}
sub run {
my $self = shift;
my ($self, $client) = @_;
# should be somewhere in Qpsmtpd.pm and not here...
$self->load_plugins unless $self->{hooks};
# Set local client_socket to passed client object for testing socket state on writes
$self->{__client_socket} = $client;
$self->load_plugins;
my $rc = $self->start_conversation;
return if $rc != DONE;
# this should really be the loop and read_input should just get one line; I think
$self->read_input;
}
@ -104,6 +105,12 @@ sub read_input {
sub respond {
my ($self, $code, @messages) = @_;
my $buf = '';
if ( !$self->check_socket() ) {
$self->log(LOGERROR, "Lost connection to client, cannot send response.");
return(0);
}
while (my $msg = shift @messages) {
my $line = $code . (@messages?"-":" ").$msg;
$self->log(LOGINFO, $line);
@ -161,4 +168,12 @@ sub tcpenv {
return ($TCPLOCALIP, $TCPREMOTEIP, $TCPREMOTEHOST || "Unknown");
}
sub check_socket() {
my $self = shift;
return 1 if ( $self->{__client_socket}->connected );
return 0;
}
1;

View File

@ -48,6 +48,12 @@ sub read_input {
sub respond {
my ($self, $code, @messages) = @_;
if ( !$self->check_socket() ) {
$self->log(LOGERROR, "Lost connection to client, cannot send response.");
return(0);
}
while (my $msg = shift @messages) {
my $line = $code . (@messages?"-":" ").$msg;
$self->log(LOGINFO, $line);

View File

@ -316,7 +316,7 @@ while (1) {
remote_ip => $ENV{TCPREMOTEIP},
remote_port => $port,
);
$qpsmtpd->run();
$qpsmtpd->run($client);
$qpsmtpd->run_hooks("post-connection");
$qpsmtpd->connection->reset;

View File

@ -691,7 +691,7 @@ sub qpsmtpd_session {
remote_ip => $ENV{TCPREMOTEIP},
remote_port => $client->peerport,
);
$qpsmtpd->run();
$qpsmtpd->run($client);
$qpsmtpd->run_hooks("post-connection");
$qpsmtpd->connection->reset;
};