Hi, This [attached] seems to still work in mp1 land and all the A::SL tests still pass. I haven't tried mp2 yet. Does this seem a like a route we want to go ?
I envision an Apache2::SizeLimit package with '*' aliasing of functions or wrappers to this one and no real code.....? P.S. Dave, are you subscribed here ?, I'll stop CC'ing you if so. -- ------------------------------------------------------------------------ Philip M. Gollucci ([EMAIL PROTECTED]) 323.219.4708 Consultant / http://p6m7g8.net/Resume/resume.shtml Senior Software Engineer - TicketMaster - http://ticketmaster.com 1024D/A79997FA F357 0FDD 2301 6296 690F 6A47 D55A 7172 A799 97F "In all that I've done wrong I know I must have done something right to deserve a hug every morning and butterfly kisses at night."
Index: lib/Apache/SizeLimit.pm =================================================================== --- lib/Apache/SizeLimit.pm (revision 422654) +++ lib/Apache/SizeLimit.pm (working copy) @@ -16,10 +16,37 @@ package Apache::SizeLimit; use strict; - -use Apache::Constants qw(DECLINED OK); use Config; +use constant MP2 => (exists $ENV{MOD_PERL_API_VERSION} && + $ENV{MOD_PERL_API_VERSION} == 2) ? 1 : 0; + +BEGIN { + my @constants = qw(OK DECLINED); + if (MP2) { + require mod_perl2; + + require APR::Pool; + require Apache2::MPM; + require Apache2::RequestRec; + require Apache2::RequestUtil; + require ModPerl::Util; + + require Apache2::Const; + import Apache2::Const @constants; + + die "Apache2::SizeLimit at the moment works only with non-threaded MPMs" + if Apache2::MPM->is_threaded(); + } + elsif (defined $modperl::VERSION && $modperl::VERSION > 1 && + $modperl::VERSION < 1.99) { + require Apache; + + require Apache::Constants; + import Apache::Constants @constants; + } +} + use vars qw( $VERSION $REQUEST_COUNT @@ -67,24 +94,35 @@ sub handler ($$) { my $class = shift; - my $r = shift || Apache->request; + my $r = shift || (MP2 ? Apache2::RequestUtil->request() : Apache->request); - return DECLINED unless $r->is_main(); + if (MP2) { + return Apache2::Const::DECLINED() if $r->is_initial_req(); - # we want to operate in a cleanup handler - if ( $r->current_callback eq 'PerlCleanupHandler' ) { - return $class->_exit_if_too_big($r); + if (ModPerl::Util::current_callback() eq 'PerlCleanupHandler') { + return $class->_exit_if_too_big($r); + } + else { + $class->add_cleanup_handler($r); + } } else { - $class->add_cleanup_handler($r); + return Apache::Constants::DECLINED() unless $r->is_main(); + + if ( $r->current_callback eq 'PerlCleanupHandler' ) { + return $class->_exit_if_too_big($r); + } + else { + $class->add_cleanup_handler($r); + } } - return DECLINED; + return MP2 ? Apache2::Const::DECLINED() : Apache::Constants::DECLINED(); } sub add_cleanup_handler { my $class = shift; - my $r = shift || Apache->request; + my $r = shift || (MP2 ? Apache2::RequestUtil->request() : Apache->request); return unless $r; return if $r->pnotes('size_limit_cleanup'); @@ -93,18 +131,20 @@ # test it, since apparently it does not push a handler onto the # PerlCleanupHandler phase. That means that there's no way to use # $r->get_handlers() to check the results of calling this method. - $r->push_handlers( 'PerlCleanupHandler', - sub { $class->_exit_if_too_big() } ); - $r->pnotes( size_limit_cleanup => 1 ); + $r->push_handlers( + 'PerlCleanupHandler', + sub { $class->_exit_if_too_big() } + ); + $r->pnotes('size_limit_cleanup', 1); } sub _exit_if_too_big { my $class = shift; my $r = shift; - return DECLINED - if ( $CHECK_EVERY_N_REQUESTS - && ( $REQUEST_COUNT++ % $CHECK_EVERY_N_REQUESTS ) ); + return (MP2 ? Apache2::Const::DECLINED() : Apache::Constants::DECLINED()) + if $CHECK_EVERY_N_REQUESTS + && ($REQUEST_COUNT++ % $CHECK_EVERY_N_REQUESTS); $START_TIME ||= time; @@ -119,6 +159,9 @@ $msg .= " REQUESTS=$REQUEST_COUNT LIFETIME=$e seconds"; $class->_error_log($msg); + ## XXX: some different logic here + ## XXX: child_terminate() seems to work in WIN32 in 2.x + ## XXX: also so getppid() foo if (IS_WIN32) { # child_terminate() is disabled in win32 Apache CORE::exit(-2); @@ -134,7 +177,7 @@ $class->_error_log($msg); } } - return OK; + return MP2 ? Apache2::Const::OK() : Apache::Constants::OK(); } # REVIEW - Why doesn't this use $r->warn or some other
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]