stas 2004/06/02 11:49:22
Modified: src/modules/perl modperl_filter.c
xs modperl_xs_util.h
xs/APR/PerlIO apr_perlio.c
xs/Apache/Filter Apache__Filter.h
xs/Apache/RequestIO Apache__RequestIO.h
Log:
improve the error handling
Revision Changes Path
1.92 +19 -21 modperl-2.0/src/modules/perl/modperl_filter.c
Index: modperl_filter.c
===================================================================
RCS file: /home/cvs/modperl-2.0/src/modules/perl/modperl_filter.c,v
retrieving revision 1.91
retrieving revision 1.92
diff -u -u -r1.91 -r1.92
--- modperl_filter.c 1 Jun 2004 20:16:46 -0000 1.91
+++ modperl_filter.c 2 Jun 2004 18:49:21 -0000 1.92
@@ -649,12 +649,8 @@
(unsigned long)filter->bucket);
}
else {
- MP_TRACE_f(MP_FUNC,
- MP_FILTER_NAME_FORMAT
- "read in: apr_bucket_read error: %s\n",
- MP_FILTER_NAME(filter->f),
- modperl_error_strerror(aTHX_ filter->rc));
- return len;
+ SvREFCNT_dec(buffer);
+ modperl_croak(aTHX_ filter->rc, "Apache::Filter::read");
}
if (buf_len) {
@@ -692,32 +688,28 @@
apr_size_t len = 0;
if (!filter->bb_in) {
- apr_status_t rc;
/* This should be read only once per handler invocation! */
filter->bb_in = apr_brigade_create(filter->pool,
filter->f->c->bucket_alloc);
- rc = ap_get_brigade(filter->f->next, filter->bb_in,
- filter->input_mode, filter->block,
- filter->readbytes);
- if (!(rc == APR_SUCCESS || rc == APR_EOF)) {
- modperl_croak(aTHX_ rc, "Apache::Filter::read");
- }
MP_TRACE_f(MP_FUNC, MP_FILTER_NAME_FORMAT
"retrieving bb: 0x%lx\n",
MP_FILTER_NAME(filter->f),
(unsigned long)(filter->bb_in));
+ MP_RUN_CROAK(ap_get_brigade(filter->f->next, filter->bb_in,
+ filter->input_mode, filter->block,
+ filter->readbytes),
+ "Apache::Filter::read");
}
len = modperl_filter_read(aTHX_ filter, buffer, wanted);
-/* if (APR_BRIGADE_EMPTY(filter->bb_in)) { */
-/* apr_brigade_destroy(filter->bb_in); */
-/* filter->bb_in = NULL; */
-/* } */
-
if (filter->flush && len == 0) {
/* if len > 0 then $filter->write will flush */
- modperl_input_filter_flush(filter);
+ apr_status_t rc = modperl_input_filter_flush(filter);
+ if (rc != APR_SUCCESS) {
+ SvREFCNT_dec(buffer);
+ modperl_croak(aTHX_ rc, "Apache::Filter::read");
+ }
}
return len;
@@ -734,7 +726,11 @@
if (filter->flush && len == 0) {
/* if len > 0 then $filter->write will flush */
- MP_FAILURE_CROAK(modperl_output_filter_flush(filter));
+ apr_status_t rc = modperl_output_filter_flush(filter);
+ if (rc != APR_SUCCESS) {
+ SvREFCNT_dec(buffer);
+ modperl_croak(aTHX_ rc, "Apache::Filter::read");
+ }
}
return len;
@@ -1158,7 +1154,9 @@
if (handler->attrs & MP_FILTER_HAS_INIT_HANDLER && handler->next) {
int status = modperl_run_filter_init(f, mode, handler->next);
if (status != OK) {
- /* XXX */
+ modperl_croak(aTHX_ status, strEQ("InputFilter", type)
+ ? "Apache::Filter::add_input_filter"
+ : "Apache::Filter::add_output_filter");
}
}
1.23 +2 -7 modperl-2.0/xs/modperl_xs_util.h
Index: modperl_xs_util.h
===================================================================
RCS file: /home/cvs/modperl-2.0/xs/modperl_xs_util.h,v
retrieving revision 1.22
retrieving revision 1.23
diff -u -u -r1.22 -r1.23
--- modperl_xs_util.h 4 May 2004 06:19:12 -0000 1.22
+++ modperl_xs_util.h 2 Jun 2004 18:49:21 -0000 1.23
@@ -94,17 +94,12 @@
mpxs_usage_va(2, obj, msg); \
arg = *MARK++
-/* XXX: we probably shouldn't croak here */
-#define mpxs_write_loop(func, obj) \
+#define mpxs_write_loop(func, obj, name) \
while (MARK <= SP) { \
apr_size_t wlen; \
- apr_status_t rv; \
char *buf = SvPV(*MARK, wlen); \
MP_TRACE_o(MP_FUNC, "%d bytes [%s]", wlen, buf); \
- rv = func(aTHX_ obj, buf, &wlen); \
- if (rv != APR_SUCCESS) { \
- Perl_croak(aTHX_ modperl_error_strerror(aTHX_ rv)); \
- } \
+ MP_RUN_CROAK(func(aTHX_ obj, buf, &wlen), name); \
bytes += wlen; \
MARK++; \
}
1.40 +5 -3 modperl-2.0/xs/APR/PerlIO/apr_perlio.c
Index: apr_perlio.c
===================================================================
RCS file: /home/cvs/modperl-2.0/xs/APR/PerlIO/apr_perlio.c,v
retrieving revision 1.39
retrieving revision 1.40
diff -u -u -r1.39 -r1.40
--- apr_perlio.c 16 May 2004 09:19:40 -0000 1.39
+++ apr_perlio.c 2 Jun 2004 18:49:21 -0000 1.40
@@ -134,6 +134,9 @@
path ? path : "(UNKNOWN)", rc);
if (rc != APR_SUCCESS) {
+ /* it just so happens that since $! is tied to errno, we get
+ * it set right via the system call that apr_file_open has
+ * performed internally, no need to do anything special */
PerlIO_pop(aTHX_ f);
return NULL;
}
@@ -144,7 +147,7 @@
static IV PerlIOAPR_fileno(pTHX_ PerlIO *f)
{
- /* apr_file_t* is an opaque struct, so fileno is not available
+ /* apr_file_t* is an opaque struct, so fileno is not available.
* -1 in this case indicates that the layer cannot provide fileno
*/
return -1;
@@ -190,8 +193,7 @@
return count;
}
else if (rc != APR_SUCCESS) {
- Perl_croak(aTHX_ "failed to read from file: %s",
- modperl_error_strerror(aTHX_ rc));
+ modperl_croak(aTHX_ rc, "APR::PerlIO::read");
}
return count;
1.40 +4 -2 modperl-2.0/xs/Apache/Filter/Apache__Filter.h
Index: Apache__Filter.h
===================================================================
RCS file: /home/cvs/modperl-2.0/xs/Apache/Filter/Apache__Filter.h,v
retrieving revision 1.39
retrieving revision 1.40
diff -u -u -r1.39 -r1.40
--- Apache__Filter.h 1 Jun 2004 23:33:50 -0000 1.39
+++ Apache__Filter.h 2 Jun 2004 18:49:22 -0000 1.40
@@ -34,10 +34,12 @@
MP_TRACE_f(MP_FUNC, "from %s\n",
((modperl_filter_ctx_t *)modperl_filter->f->ctx)->handler->name);
if (modperl_filter->mode == MP_OUTPUT_FILTER_MODE) {
- mpxs_write_loop(modperl_output_filter_write, modperl_filter);
+ mpxs_write_loop(modperl_output_filter_write,
+ modperl_filter, "Apache::Filter::print");
}
else {
- mpxs_write_loop(modperl_input_filter_write, modperl_filter);
+ mpxs_write_loop(modperl_input_filter_write,
+ modperl_filter, "Apache::Filter::print");
}
/* XXX: ap_rflush if $| */
1.46 +4 -2 modperl-2.0/xs/Apache/RequestIO/Apache__RequestIO.h
Index: Apache__RequestIO.h
===================================================================
RCS file: /home/cvs/modperl-2.0/xs/Apache/RequestIO/Apache__RequestIO.h,v
retrieving revision 1.45
retrieving revision 1.46
diff -u -u -r1.45 -r1.46
--- Apache__RequestIO.h 29 Apr 2004 00:06:41 -0000 1.45
+++ Apache__RequestIO.h 2 Jun 2004 18:49:22 -0000 1.46
@@ -60,7 +60,8 @@
MP_START_TIMES();
MP_CHECK_WBUCKET_INIT("$r->puts");
- mpxs_write_loop(modperl_wbucket_write, rcfg->wbucket);
+ mpxs_write_loop(modperl_wbucket_write, rcfg->wbucket,
+ "Apache::RequestIO::puts");
MP_END_TIMES();
MP_PRINT_TIMES("r->puts");
@@ -88,7 +89,8 @@
rcfg = modperl_config_req_get(r);
MP_CHECK_WBUCKET_INIT("$r->print");
- mpxs_write_loop(modperl_wbucket_write, rcfg->wbucket);
+ mpxs_write_loop(modperl_wbucket_write, rcfg->wbucket,
+ "Apache::RequestIO::print");
mpxs_output_flush(r, rcfg);