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

View File

@ -48,6 +48,12 @@ sub read_input {
sub respond { sub respond {
my ($self, $code, @messages) = @_; 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) { while (my $msg = shift @messages) {
my $line = $code . (@messages?"-":" ").$msg; my $line = $code . (@messages?"-":" ").$msg;
$self->log(LOGINFO, $line); $self->log(LOGINFO, $line);

View File

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

View File

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