Push enable/disable read call into lib/Qpsmtpd.pm

git-svn-id: https://svn.perl.org/qpsmtpd/branches/high_perf@445 958fd67b-6ff1-0310-b445-bb7760255be9
This commit is contained in:
Matt Sergeant 2005-06-22 18:25:16 +00:00
parent 5853c3a011
commit bc3f52a380
2 changed files with 4 additions and 5 deletions

View File

@ -220,6 +220,7 @@ sub run_hooks {
@r = $self->run_hook($hook, $code, @_); @r = $self->run_hook($hook, $code, @_);
next unless @r; next unless @r;
if ($r[0] == CONTINUATION) { if ($r[0] == CONTINUATION) {
$self->disable_read() if $self->isa('Danga::Client');
$self->{_continuation} = [$hook, [@_], @local_hooks]; $self->{_continuation} = [$hook, [@_], @local_hooks];
} }
last unless $r[0] == DECLINED; last unless $r[0] == DECLINED;
@ -233,6 +234,7 @@ sub run_hooks {
sub finish_continuation { sub finish_continuation {
my ($self) = @_; my ($self) = @_;
die "No continuation in progress" unless $self->{_continuation}; die "No continuation in progress" unless $self->{_continuation};
$self->enable_read() if $self->isa('Danga::Client');
my $todo = $self->{_continuation}; my $todo = $self->{_continuation};
$self->{_continuation} = undef; $self->{_continuation} = undef;
my $hook = shift @$todo || die "No hook in the continuation"; my $hook = shift @$todo || die "No hook in the continuation";
@ -242,6 +244,7 @@ sub finish_continuation {
my $code = shift @$todo; my $code = shift @$todo;
@r = $self->run_hook($hook, $code, @$args); @r = $self->run_hook($hook, $code, @$args);
if ($r[0] == CONTINUATION) { if ($r[0] == CONTINUATION) {
$self->disable_read() if $self->isa('Danga::Client');
$self->{_continuation} = [$hook, $args, @$todo]; $self->{_continuation} = [$hook, $args, @$todo];
return @r; return @r;
} }
@ -250,6 +253,7 @@ sub finish_continuation {
$r[0] = DECLINED if not defined $r[0]; $r[0] = DECLINED if not defined $r[0];
my $responder = $hook . "_respond"; my $responder = $hook . "_respond";
if (my $meth = $self->can($responder)) { if (my $meth = $self->can($responder)) {
warn("continuation finished on $self\n");
return $meth->($self, @r, @$args); return $meth->($self, @r, @$args);
} }
die "No ${hook}_respond method"; die "No ${hook}_respond method";

View File

@ -61,26 +61,21 @@ sub register {
$self->register_hook('connect', 'connect_post_handler'); $self->register_hook('connect', 'connect_post_handler');
$self->register_hook('mail', 'mail_handler') $self->register_hook('mail', 'mail_handler')
if $self->{_args}->{'defer-reject'}; if $self->{_args}->{'defer-reject'};
warn("check_earlytalker registered\n");
1; 1;
} }
sub connect_handler { sub connect_handler {
my ($self, $transaction) = @_; my ($self, $transaction) = @_;
warn("check early talker");
my $qp = $self->qp; my $qp = $self->qp;
my $conn = $qp->connection; my $conn = $qp->connection;
$qp->AddTimer($self->{_args}{'wait'}, sub { read_now($qp, $conn) }); $qp->AddTimer($self->{_args}{'wait'}, sub { read_now($qp, $conn) });
$qp->disable_read();
return CONTINUATION; return CONTINUATION;
} }
sub read_now { sub read_now {
my ($qp, $conn) = @_; my ($qp, $conn) = @_;
warn("read now");
$qp->enable_read();
if (my $data = $qp->read(1024)) { if (my $data = $qp->read(1024)) {
if (length($$data)) { if (length($$data)) {
$qp->log(LOGNOTICE, 'remote host started talking before we said hello'); $qp->log(LOGNOTICE, 'remote host started talking before we said hello');