From 63f93a65043f9a8d84c32a1db191fb64d7ba897f Mon Sep 17 00:00:00 2001 From: Ryan Bloom Date: Mon, 27 Mar 2000 16:22:30 +0000 Subject: [PATCH] Backout layered I/O changes. git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@84842 13f79535-47bb-0310-9956-ffa450edef68 --- docs/manual/developer/index.html | 2 +- include/httpd.h | 12 +--- modules/filters/mod_include.c | 61 +++--------------- modules/generators/mod_cgi.c | 18 ++---- modules/http/http_core.c | 10 ++- modules/http/http_protocol.c | 107 ++++++++++--------------------- 6 files changed, 56 insertions(+), 154 deletions(-) diff --git a/docs/manual/developer/index.html b/docs/manual/developer/index.html index 5c207fa16b..a72dd44b21 100644 --- a/docs/manual/developer/index.html +++ b/docs/manual/developer/index.html @@ -14,6 +14,6 @@

Developer Documentation for Apache-2.0

Apache Hook Functions

Converting Apache 1.3 Modules to Apache 2.0

-

Taking advantage of layered I/O in Apache 2.0

+

MPM listing

diff --git a/include/httpd.h b/include/httpd.h index 56b1c715b7..a34490cf6b 100644 --- a/include/httpd.h +++ b/include/httpd.h @@ -391,10 +391,7 @@ API_EXPORT(const char *) ap_get_server_built(void); * - it's safe to die() with no more output */ #define OK 0 /* Module has handled this stage. */ -#define RERUN_HANDLERS 1 /* Module has handled this request, but - * realizes others may also want to handle - * it. - */ + /* ----------------------- HTTP Status Codes ------------------------- */ @@ -583,13 +580,6 @@ struct request_rec { conn_rec *connection; server_rec *server; - BUFF *input; /* Where to get the data (usually a pipe - * or a file currently). - */ - BUFF *output; /* Where to send the data (usually, a pipe - * or the socket currently). - */ - request_rec *next; /* If we wind up getting redirected, * pointer to the request we redirected to. */ diff --git a/modules/filters/mod_include.c b/modules/filters/mod_include.c index 0f57f87678..2cd7cd1f49 100644 --- a/modules/filters/mod_include.c +++ b/modules/filters/mod_include.c @@ -2364,30 +2364,20 @@ static const char *set_xbithack(cmd_parms *cmd, void *xbp, char *arg) return NULL; } -struct { - ap_thread_t *thread; - request_rec *r; -} ssi_rec; - -void * API_THREAD_FUNC sub_send_parsed_file(void *rec) +static int send_parsed_file(request_rec *r) { ap_file_t *f = NULL; - struct ssi_rec *dumb_rec = (struct ssi_rec *)rec; - ap_thread_t *subthread = dumb_rec->thread - request_rec *r = dumb_rec->r; enum xbithack *state = (enum xbithack *) ap_get_module_config(r->per_dir_config, &includes_module); int errstatus; request_rec *parent; if (!(ap_allow_options(r) & OPT_INCLUDES)) { - ap_thread_exit(0); -/* return DECLINED;*/ + return DECLINED; } r->allowed |= (1 << M_GET); if (r->method_number != M_GET) { - ap_thread_exit(0); -/* return DECLINED;*/ + return DECLINED; } if (r->finfo.protection == 0) { ap_log_rerror(APLOG_MARK, APLOG_NOERRNO|APLOG_ERR, 0, r, @@ -2395,8 +2385,7 @@ void * API_THREAD_FUNC sub_send_parsed_file(void *rec) (r->path_info ? ap_pstrcat(r->pool, r->filename, r->path_info, NULL) : r->filename)); - ap_thread_exit(0); -/* return HTTP_NOT_FOUND;*/ + return HTTP_NOT_FOUND; } errstatus = ap_open(&f, r->filename, APR_READ, 0, r->pool); @@ -2404,8 +2393,7 @@ void * API_THREAD_FUNC sub_send_parsed_file(void *rec) if (errstatus != APR_SUCCESS) { ap_log_rerror(APLOG_MARK, APLOG_ERR, errstatus, r, "file permissions deny server access: %s", r->filename); - ap_thread_exit(0); -/* return HTTP_FORBIDDEN;*/ + return HTTP_FORBIDDEN; } if ((*state == xbithack_full) @@ -2418,16 +2406,14 @@ void * API_THREAD_FUNC sub_send_parsed_file(void *rec) ap_set_last_modified(r); } if ((errstatus = ap_meets_conditions(r)) != OK) { - ap_thread_exit(0); -/* return errstatus;*/ + return errstatus; } ap_send_http_header(r); if (r->header_only) { ap_close(f); - ap_thread_exit(0); -/* return OK;*/ + return OK; } if ((parent = ap_get_module_config(r->request_config, &includes_module))) { @@ -2467,39 +2453,8 @@ void * API_THREAD_FUNC sub_send_parsed_file(void *rec) ap_set_module_config(r->request_config, &includes_module, NESTED_INCLUDE_MAGIC); } - ap_thread_exit(0); -/* return OK;*/ -} -int send_parsed_file(request_rec *r) -{ - struct ssi_rec dumb_rec; - ap_thread_t *subthread = NULL; - ap_file_t *pipein = NULL; - ap_file_t *pipeout = NULL; - ap_iol *iolin; - ap_iol *iolout; - BUFF *bpipeint = NULL; - BUFF *bpipeout = NULL; - - ap_create_pipe(&pipein, &pipeout, r->pool); - - iolin = ap_create_file_iol(pipein); - ap_bpush_iol(bpipein, iolin); - - iolout = ap_create_file_iol(pipeout); - ap_bpush_iol(bpipeout, iolout); - r->output = bpipeout; - - ap_setup_input(r); - - dumb_rec->thread = subthread; - dumb_rec->r = r; - ap_create_thread(&subthread, NULL, sub_send_parsed_file, dumb_rec, r->pool); - r->input = bpipein; - - - return RERUN_HANDLERS; + return OK; } static int send_shtml_file(request_rec *r) diff --git a/modules/generators/mod_cgi.c b/modules/generators/mod_cgi.c index 374aa8f80e..e07d42d1b4 100644 --- a/modules/generators/mod_cgi.c +++ b/modules/generators/mod_cgi.c @@ -621,9 +621,7 @@ static int cgi_handler(request_rec *r) ap_table_unset(r->headers_in, "Content-Length"); ap_internal_redirect_handler(location, r); -/* r->content_type = NULL;*/ - r->handler = NULL; - return RERUN_HANDLERS; + return OK; } else if (location && r->status == 200) { /* XX Note that if a script wants to produce its own Redirect @@ -632,12 +630,12 @@ static int cgi_handler(request_rec *r) return REDIRECT; } -/* ap_send_http_header(r);*/ + ap_send_http_header(r); if (!r->header_only) { - r->input = script_in; + ap_send_fb(script_in, r); } -/* ap_bclose(script_in); -*/ + ap_bclose(script_in); + while (ap_bgets(argsbuffer, HUGE_STRING_LEN, script_err) > 0) { continue; } @@ -645,12 +643,10 @@ static int cgi_handler(request_rec *r) } if (script_in && nph) { - r->input = script_in; + ap_send_fb(script_in, r); } -/* r->content_type = NULL;*/ - r->handler = NULL; - return RERUN_HANDLERS; /* NOT r->status, even if it has changed. */ + return OK; /* NOT r->status, even if it has changed. */ } static const handler_rec cgi_handlers[] = diff --git a/modules/http/http_core.c b/modules/http/http_core.c index d9369a0a65..b68372e939 100644 --- a/modules/http/http_core.c +++ b/modules/http/http_core.c @@ -2530,15 +2530,12 @@ static int default_handler(request_rec *r) if (r->method_number != M_GET) { return METHOD_NOT_ALLOWED; } -/* + if ((status = ap_open(&fd, r->filename, APR_READ | APR_BINARY, 0, r->pool)) != APR_SUCCESS) { ap_log_rerror(APLOG_MARK, APLOG_ERR, status, r, "file permissions deny server access: %s", r->filename); return FORBIDDEN; - }*/ - - ap_setup_input(r); - + } ap_update_mtime(r, r->finfo.mtime); ap_set_last_modified(r); ap_set_etag(r); @@ -2586,7 +2583,7 @@ static int default_handler(request_rec *r) if (!r->header_only) { if (!rangestatus) { - ap_send_fb(r->input, r); + ap_send_fd(fd, r); } else { long length; @@ -2637,6 +2634,7 @@ static int default_handler(request_rec *r) } #endif + ap_close(fd); return OK; } diff --git a/modules/http/http_protocol.c b/modules/http/http_protocol.c index b46004ee36..e345e57eb1 100644 --- a/modules/http/http_protocol.c +++ b/modules/http/http_protocol.c @@ -959,30 +959,6 @@ static void get_mime_headers(request_rec *r) ap_overlap_tables(r->headers_in, tmp_headers, AP_OVERLAP_TABLES_MERGE); } -ap_status_t ap_setup_input(request_rec *r) -{ - BUFF *temp = NULL; - ap_iol *iol; - ap_file_t *fd = NULL; - ap_status_t status; - - if (!r->input) { - if ((status = ap_open(&fd, r->filename, APR_READ | APR_BINARY, 0, r->pool)) != APR_SUCCESS) { - ap_log_rerror(APLOG_MARK, APLOG_ERR, status, r, - "file permissions deny server access: %s", r->filename); - return status; - } - - iol = ap_create_file_iol(fd); - if (!iol) - return APR_EBADF; - temp = ap_bcreate(r->pool, B_RD); - ap_bpush_iol(temp, iol); - r->input = temp; - } - return APR_SUCCESS; -} - request_rec *ap_read_request(conn_rec *conn) { request_rec *r; @@ -1884,13 +1860,10 @@ API_EXPORT(long) ap_get_client_block(request_rec *r, char *buffer, int bufsiz) long chunk_start = 0; unsigned long max_body; ap_status_t rv; - BUFF *used_buff; - - used_buff = r->input ? r->input : r->connection->client; if (!r->read_chunked) { /* Content-length read */ len_to_read = (r->remaining > bufsiz) ? bufsiz : r->remaining; - rv = ap_bread(used_buff, buffer, len_to_read, &len_read); + rv = ap_bread(r->connection->client, buffer, len_to_read, &len_read); if (len_read == 0) { /* error or eof */ if (rv != APR_SUCCESS) { r->connection->keepalive = -1; @@ -1929,7 +1902,7 @@ API_EXPORT(long) ap_get_client_block(request_rec *r, char *buffer, int bufsiz) if (r->remaining == 0) { /* Start of new chunk */ - chunk_start = getline(buffer, bufsiz, used_buff, 0); + chunk_start = getline(buffer, bufsiz, r->connection->client, 0); if ((chunk_start <= 0) || (chunk_start >= (bufsiz - 1)) || !ap_isxdigit(*buffer)) { r->connection->keepalive = -1; @@ -1970,7 +1943,7 @@ API_EXPORT(long) ap_get_client_block(request_rec *r, char *buffer, int bufsiz) len_read = chunk_start; while ((bufsiz > 1) && ((len_read = - getline(buffer, bufsiz, used_buff, 1)) > 0)) { + getline(buffer, bufsiz, r->connection->client, 1)) > 0)) { if (len_read != (bufsiz - 1)) { buffer[len_read++] = CR; /* Restore footer line end */ @@ -2004,7 +1977,7 @@ API_EXPORT(long) ap_get_client_block(request_rec *r, char *buffer, int bufsiz) len_to_read = (r->remaining > bufsiz) ? bufsiz : r->remaining; - (void) ap_bread(used_buff, buffer, len_to_read, &len_read); + (void) ap_bread(r->connection->client, buffer, len_to_read, &len_read); if (len_read == 0) { /* error or eof */ r->connection->keepalive = -1; return -1; @@ -2013,8 +1986,8 @@ API_EXPORT(long) ap_get_client_block(request_rec *r, char *buffer, int bufsiz) r->remaining -= len_read; if (r->remaining == 0) { /* End of chunk, get trailing CRLF */ - if ((c = ap_bgetc(used_buff)) == CR) { - c = ap_bgetc(used_buff); + if ((c = ap_bgetc(r->connection->client)) == CR) { + c = ap_bgetc(r->connection->client); } if (c != LF) { r->connection->keepalive = -1; @@ -2077,17 +2050,16 @@ API_EXPORT(int) ap_discard_request_body(request_rec *r) */ API_EXPORT(long) ap_send_fd(ap_file_t *fd, request_rec *r) { - BUFF *used_buff = r->output ? r->output : r->connection->client; long len = r->finfo.size; #ifdef HAVE_SENDFILE if (!r->chunked) { ap_status_t rv; - ap_bsetopt(used_buff, BO_TIMEOUT, + ap_bsetopt(r->connection->client, BO_TIMEOUT, r->connection->keptalive ? &r->server->keep_alive_timeout : &r->server->timeout); - ap_bflush(used_buff); - rv = iol_sendfile(used_buff->iol, + ap_bflush(r->connection->client); + rv = iol_sendfile(r->connection->client->iol, fd, /* The file to send */ NULL, /* header and trailer iovecs */ 0, /* Offset in file to begin sending from */ @@ -2098,7 +2070,7 @@ API_EXPORT(long) ap_send_fd(ap_file_t *fd, request_rec *r) "ap_send_fd: iol_sendfile failed."); } if (r->connection->keptalive) { - ap_bsetopt(used_buff, BO_TIMEOUT, + ap_bsetopt(r->connection->client, BO_TIMEOUT, &r->server->timeout); } } @@ -2119,7 +2091,6 @@ API_EXPORT(long) ap_send_fd_length(ap_file_t *fd, request_rec *r, long length) ap_ssize_t w; ap_ssize_t n; ap_status_t rv; - BUFF *used_buff = r->output ? r->output : r->connection->client; if (length == 0) return 0; @@ -2142,7 +2113,7 @@ API_EXPORT(long) ap_send_fd_length(ap_file_t *fd, request_rec *r, long length) o = 0; while (n && !ap_is_aborted(r->connection)) { - rv = ap_bwrite(used_buff, &buf[o], n, &w); + rv = ap_bwrite(r->connection->client, &buf[o], n, &w); if (w > 0) { total_bytes_sent += w; n -= w; @@ -2152,7 +2123,7 @@ API_EXPORT(long) ap_send_fd_length(ap_file_t *fd, request_rec *r, long length) if (!ap_is_aborted(r->connection)) { ap_log_rerror(APLOG_MARK, APLOG_INFO, rv, r, "client stopped connection before send body completed"); - ap_bsetflag(used_buff, B_EOUT, 1); + ap_bsetflag(r->connection->client, B_EOUT, 1); r->connection->aborted = 1; } break; @@ -2181,7 +2152,6 @@ API_EXPORT(long) ap_send_fb_length(BUFF *fb, request_rec *r, long length) ap_ssize_t w; ap_ssize_t n; ap_status_t rv; - BUFF *used_buff = r->output ? r->output : r->connection->client; if (length == 0) { return 0; @@ -2223,7 +2193,7 @@ API_EXPORT(long) ap_send_fb_length(BUFF *fb, request_rec *r, long length) o = 0; while (n && !ap_is_aborted(r->connection)) { - rv = ap_bwrite(used_buff, &buf[o], n, &w); + rv = ap_bwrite(r->connection->client, &buf[o], n, &w); if (w > 0) { total_bytes_sent += w; n -= w; @@ -2233,7 +2203,7 @@ API_EXPORT(long) ap_send_fb_length(BUFF *fb, request_rec *r, long length) if (!ap_is_aborted(r->connection)) { ap_log_rerror(APLOG_MARK, APLOG_INFO, rv, r, "client stopped connection before rflush completed"); - ap_bsetflag(used_buff, B_EOUT, 1); + ap_bsetflag(r->connection->client, B_EOUT, 1); r->connection->aborted = 1; } break; @@ -2268,7 +2238,6 @@ API_EXPORT(size_t) ap_send_mmap(ap_mmap_t *mm, request_rec *r, size_t offset, ap_ssize_t w; ap_status_t rv; char *addr; - BUFF *used_buff = r->output ? r->output : r->connection->client; if (length == 0) return 0; @@ -2285,7 +2254,7 @@ API_EXPORT(size_t) ap_send_mmap(ap_mmap_t *mm, request_rec *r, size_t offset, while (n && !r->connection->aborted) { ap_mmap_offset((void**)&addr, mm, offset); - rv = ap_bwrite(used_buff, addr, n, &w); + rv = ap_bwrite(r->connection->client, addr, n, &w); if (w > 0) { total_bytes_sent += w; n -= w; @@ -2299,7 +2268,7 @@ API_EXPORT(size_t) ap_send_mmap(ap_mmap_t *mm, request_rec *r, size_t offset, else { ap_log_rerror(APLOG_MARK, APLOG_INFO, rv, r, "client stopped connection before send mmap completed"); - ap_bsetflag(used_buff, B_EOUT, 1); + ap_bsetflag(r->connection->client, B_EOUT, 1); r->connection->aborted = 1; break; } @@ -2314,16 +2283,15 @@ API_EXPORT(size_t) ap_send_mmap(ap_mmap_t *mm, request_rec *r, size_t offset, API_EXPORT(int) ap_rputc(int c, request_rec *r) { - BUFF *used_buff = r->output ? r->output : r->connection->client; if (r->connection->aborted) return EOF; - if (ap_bputc(c, used_buff) < 0) { + if (ap_bputc(c, r->connection->client) < 0) { if (!r->connection->aborted) { ap_log_rerror(APLOG_MARK, APLOG_INFO, - ap_berror(used_buff), r, + ap_berror(r->connection->client), r, "client stopped connection before rputc completed"); - ap_bsetflag(used_buff, B_EOUT, 1); + ap_bsetflag(r->connection->client, B_EOUT, 1); r->connection->aborted = 1; } return EOF; @@ -2335,18 +2303,17 @@ API_EXPORT(int) ap_rputc(int c, request_rec *r) API_EXPORT(int) ap_rputs(const char *str, request_rec *r) { int rcode; - BUFF *used_buff = r->output ? r->output : r->connection->client; if (r->connection->aborted) return EOF; - rcode = ap_bputs(str, used_buff); + rcode = ap_bputs(str, r->connection->client); if (rcode < 0) { if (!r->connection->aborted) { ap_log_rerror(APLOG_MARK, APLOG_INFO, - ap_berror(used_buff), r, + ap_berror(r->connection->client), r, "client stopped connection before rputs completed"); - ap_bsetflag(used_buff, B_EOUT, 1); + ap_bsetflag(r->connection->client, B_EOUT, 1); r->connection->aborted = 1; } return EOF; @@ -2359,17 +2326,16 @@ API_EXPORT(int) ap_rwrite(const void *buf, int nbyte, request_rec *r) { ap_ssize_t n; ap_status_t rv; - BUFF *used_buff = r->output ? r->output : r->connection->client; if (r->connection->aborted) return EOF; - rv = ap_bwrite(used_buff, buf, nbyte, &n); + rv = ap_bwrite(r->connection->client, buf, nbyte, &n); if (n < 0) { if (!r->connection->aborted) { ap_log_rerror(APLOG_MARK, APLOG_INFO, rv, r, "client stopped connection before rwrite completed"); - ap_bsetflag(used_buff, B_EOUT, 1); + ap_bsetflag(r->connection->client, B_EOUT, 1); r->connection->aborted = 1; } return EOF; @@ -2381,19 +2347,18 @@ API_EXPORT(int) ap_rwrite(const void *buf, int nbyte, request_rec *r) API_EXPORT(int) ap_vrprintf(request_rec *r, const char *fmt, va_list ap) { int n; - BUFF *used_buff = r->output ? r->output : r->connection->client; if (r->connection->aborted) return -1; - n = ap_vbprintf(used_buff, fmt, ap); + n = ap_vbprintf(r->connection->client, fmt, ap); if (n < 0) { if (!r->connection->aborted) { ap_log_rerror(APLOG_MARK, APLOG_INFO, - ap_berror(used_buff), r, + ap_berror(r->connection->client), r, "client stopped connection before vrprintf completed"); - ap_bsetflag(used_buff, B_EOUT, 1); + ap_bsetflag(r->connection->client, B_EOUT, 1); r->connection->aborted = 1; } return -1; @@ -2406,21 +2371,20 @@ API_EXPORT(int) ap_rprintf(request_rec *r, const char *fmt,...) { va_list vlist; int n; - BUFF *used_buff = r->output ? r->output : r->connection->client; if (r->connection->aborted) return -1; va_start(vlist, fmt); - n = ap_vbprintf(used_buff, fmt, vlist); + n = ap_vbprintf(r->connection->client, fmt, vlist); va_end(vlist); if (n < 0) { if (!r->connection->aborted) { ap_log_rerror(APLOG_MARK, APLOG_INFO, - ap_berror(used_buff), r, + ap_berror(r->connection->client), r, "client stopped connection before rprintf completed"); - ap_bsetflag(used_buff, B_EOUT, 1); + ap_bsetflag(r->connection->client, B_EOUT, 1); r->connection->aborted = 1; } return -1; @@ -2435,7 +2399,7 @@ API_EXPORT_NONSTD(int) ap_rvputs(request_rec *r,...) ap_ssize_t i; int j, k; const char *x; - BUFF *used_buff = r->output ? r->output : r->connection->client; + BUFF *fb = r->connection->client; ap_status_t rv; if (r->connection->aborted) @@ -2447,13 +2411,13 @@ API_EXPORT_NONSTD(int) ap_rvputs(request_rec *r,...) if (x == NULL) break; j = strlen(x); - rv = ap_bwrite(used_buff, x, j, &i); + rv = ap_bwrite(fb, x, j, &i); if (i != j) { va_end(args); if (!r->connection->aborted) { ap_log_rerror(APLOG_MARK, APLOG_INFO, rv, r, "client stopped connection before rvputs completed"); - ap_bsetflag(used_buff, B_EOUT, 1); + ap_bsetflag(r->connection->client, B_EOUT, 1); r->connection->aborted = 1; } return EOF; @@ -2469,13 +2433,12 @@ API_EXPORT_NONSTD(int) ap_rvputs(request_rec *r,...) API_EXPORT(int) ap_rflush(request_rec *r) { ap_status_t rv; - BUFF *used_buff = r->output ? r->output : r->connection->client; - if ((rv = ap_bflush(used_buff)) != APR_SUCCESS) { + if ((rv = ap_bflush(r->connection->client)) != APR_SUCCESS) { if (!ap_is_aborted(r->connection)) { ap_log_rerror(APLOG_MARK, APLOG_INFO, rv, r, "client stopped connection before rflush completed"); - ap_bsetflag(used_buff, B_EOUT, 1); + ap_bsetflag(r->connection->client, B_EOUT, 1); r->connection->aborted = 1; } return EOF; -- 2.50.1