From a8203308d9a7285e324382e9c013da50f4fda790 Mon Sep 17 00:00:00 2001 From: "Roy T. Fielding" Date: Thu, 26 Aug 1999 14:15:07 +0000 Subject: Changes from pthreads. Removes timeouts, adds mutex. This probably breaks the proxy on everything but pthreads. Submitted by: Bill Stoddard git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@83769 13f79535-47bb-0310-9956-ffa450edef68 --- modules/proxy/proxy_ftp.c | 82 +++++++++++----------------------------------- modules/proxy/proxy_http.c | 13 +------- modules/proxy/proxy_util.c | 32 +++--------------- 3 files changed, 26 insertions(+), 101 deletions(-) (limited to 'modules') diff --git a/modules/proxy/proxy_ftp.c b/modules/proxy/proxy_ftp.c index 47ca9daf9d..f4aa899fce 100644 --- a/modules/proxy/proxy_ftp.c +++ b/modules/proxy/proxy_ftp.c @@ -396,7 +396,6 @@ static long int send_dir(BUFF *f, request_rec *r, cache_req *c, char *cwd) w = ap_bwrite(con->client, &buf[o], n); if (w <= 0) break; - ap_reset_timeout(r); /* reset timeout after successfule write */ n -= w; o += w; } @@ -515,9 +514,9 @@ int ap_proxy_ftp_handler(request_rec *r, cache_req *c, char *url) * because it has the lifetime of the connection. The other allocations * are temporary and can be tossed away any time. */ - user = ap_getword_nulls (r->connection->pool, &password, ':'); - r->connection->ap_auth_type = "Basic"; - r->connection->user = r->parsed_uri.user = user; + user = ap_getword_nulls (r->pool, &password, ':'); + r->ap_auth_type = "Basic"; + r->user = r->parsed_uri.user = user; nocache = 1; /* This resource only accessible with username/password */ } else if ((user = r->parsed_uri.user) != NULL) { @@ -612,7 +611,7 @@ int ap_proxy_ftp_handler(request_rec *r, cache_req *c, char *url) } f = ap_bcreate(p, B_RDWR | B_SOCKET); - ap_bpushfd(f, sock, sock); + ap_bpushfd(f, sock); /* shouldn't we implement telnet control options here? */ #ifdef CHARSET_EBCDIC @@ -623,17 +622,14 @@ int ap_proxy_ftp_handler(request_rec *r, cache_req *c, char *url) /* 120 Service ready in nnn minutes. */ /* 220 Service ready for new user. */ /* 421 Service not available, closing control connection. */ - ap_hard_timeout("proxy ftp", r); i = ftp_getrc_msg(f, resp, sizeof resp); Explain1("FTP: returned status %d", i); if (i == -1) { - ap_kill_timeout(r); return ap_proxyerror(r, HTTP_BAD_GATEWAY, - "Error reading from remote server"); + "Error reading from remote server"); } #if 0 if (i == 120) { - ap_kill_timeout(r); /* RFC2068 states: * 14.38 Retry-After * @@ -649,7 +645,6 @@ int ap_proxy_ftp_handler(request_rec *r, cache_req *c, char *url) } #endif if (i != 220) { - ap_kill_timeout(r); return ap_proxyerror(r, HTTP_BAD_GATEWAY, resp); } @@ -672,16 +667,13 @@ int ap_proxy_ftp_handler(request_rec *r, cache_req *c, char *url) i = ftp_getrc(f); Explain1("FTP: returned status %d", i); if (i == -1) { - ap_kill_timeout(r); return ap_proxyerror(r, HTTP_BAD_GATEWAY, - "Error reading from remote server"); + "Error reading from remote server"); } if (i == 530) { - ap_kill_timeout(r); return ftp_unauthorized (r, 1); /* log it: user name guessing attempt? */ } if (i != 230 && i != 331) { - ap_kill_timeout(r); return HTTP_BAD_GATEWAY; } @@ -703,22 +695,16 @@ int ap_proxy_ftp_handler(request_rec *r, cache_req *c, char *url) i = ftp_getrc(f); Explain1("FTP: returned status %d", i); if (i == -1) { - ap_kill_timeout(r); - return ap_proxyerror(r, HTTP_BAD_GATEWAY, - "Error reading from remote server"); + return ap_proxyerror(r, HTTP_BAD_GATEWAY, "Error reading from remote server"); } if (i == 332) { - ap_kill_timeout(r); - return ap_proxyerror(r, HTTP_UNAUTHORIZED, - "Need account for login"); + return ap_proxyerror(r, HTTP_UNAUTHORIZED, "Need account for login"); } /* @@@ questionable -- we might as well return a 403 Forbidden here */ if (i == 530) { - ap_kill_timeout(r); return ftp_unauthorized (r, 1); /* log it: passwd guessing attempt? */ } if (i != 230 && i != 202) { - ap_kill_timeout(r); return HTTP_BAD_GATEWAY; } } @@ -749,16 +735,13 @@ int ap_proxy_ftp_handler(request_rec *r, cache_req *c, char *url) i = ftp_getrc(f); Explain1("FTP: returned status %d", i); if (i == -1) { - ap_kill_timeout(r); return ap_proxyerror(r, HTTP_BAD_GATEWAY, - "Error reading from remote server"); + "Error reading from remote server"); } if (i == 550) { - ap_kill_timeout(r); return HTTP_NOT_FOUND; } if (i != 250) { - ap_kill_timeout(r); return HTTP_BAD_GATEWAY; } @@ -793,12 +776,10 @@ int ap_proxy_ftp_handler(request_rec *r, cache_req *c, char *url) i = ftp_getrc(f); Explain1("FTP: returned status %d", i); if (i == -1) { - ap_kill_timeout(r); return ap_proxyerror(r, HTTP_BAD_GATEWAY, - "Error reading from remote server"); + "Error reading from remote server"); } if (i != 200 && i != 504) { - ap_kill_timeout(r); return HTTP_BAD_GATEWAY; } /* Allow not implemented */ @@ -812,7 +793,6 @@ int ap_proxy_ftp_handler(request_rec *r, cache_req *c, char *url) ap_log_rerror(APLOG_MARK, APLOG_ERR, r, "proxy: error creating PASV socket"); ap_bclose(f); - ap_kill_timeout(r); return HTTP_INTERNAL_SERVER_ERROR; } @@ -840,7 +820,6 @@ int ap_proxy_ftp_handler(request_rec *r, cache_req *c, char *url) "PASV: control connection is toast"); ap_pclosesocket(p, dsock); ap_bclose(f); - ap_kill_timeout(r); return HTTP_INTERNAL_SERVER_ERROR; } else { @@ -875,11 +854,10 @@ int ap_proxy_ftp_handler(request_rec *r, cache_req *c, char *url) i = ap_proxy_doconnect(dsock, &data_addr, r); if (i == -1) { - ap_kill_timeout(r); return ap_proxyerror(r, HTTP_BAD_GATEWAY, - ap_pstrcat(r->pool, - "Could not connect to remote machine: ", - strerror(errno), NULL)); + ap_pstrcat(r->pool, + "Could not connect to remote machine: ", + strerror(errno), NULL)); } else { pasvmode = 1; @@ -895,7 +873,6 @@ int ap_proxy_ftp_handler(request_rec *r, cache_req *c, char *url) ap_log_rerror(APLOG_MARK, APLOG_ERR, r, "proxy: error getting socket address"); ap_bclose(f); - ap_kill_timeout(r); return HTTP_INTERNAL_SERVER_ERROR; } @@ -904,7 +881,6 @@ int ap_proxy_ftp_handler(request_rec *r, cache_req *c, char *url) ap_log_rerror(APLOG_MARK, APLOG_ERR, r, "proxy: error creating socket"); ap_bclose(f); - ap_kill_timeout(r); return HTTP_INTERNAL_SERVER_ERROR; } @@ -915,7 +891,6 @@ int ap_proxy_ftp_handler(request_rec *r, cache_req *c, char *url) "proxy: error setting reuseaddr option"); ap_pclosesocket(p, dsock); ap_bclose(f); - ap_kill_timeout(r); return HTTP_INTERNAL_SERVER_ERROR; #endif /*_OSD_POSIX*/ } @@ -966,16 +941,13 @@ int ap_proxy_ftp_handler(request_rec *r, cache_req *c, char *url) /* 550 Requested action not taken. */ Explain1("FTP: returned status %d", i); if (i == -1) { - ap_kill_timeout(r); return ap_proxyerror(r, HTTP_BAD_GATEWAY, - "Error reading from remote server"); + "Error reading from remote server"); } if (i == 550) { - ap_kill_timeout(r); return HTTP_NOT_FOUND; } if (i != 250) { - ap_kill_timeout(r); return HTTP_BAD_GATEWAY; } path = ""; @@ -1005,12 +977,10 @@ int ap_proxy_ftp_handler(request_rec *r, cache_req *c, char *url) i = ftp_getrc_msg(f, resp, sizeof resp); Explain1("FTP: PWD returned status %d", i); if (i == -1 || i == 421) { - ap_kill_timeout(r); return ap_proxyerror(r, HTTP_BAD_GATEWAY, - "Error reading from remote server"); + "Error reading from remote server"); } if (i == 550) { - ap_kill_timeout(r); return HTTP_NOT_FOUND; } if (i == 257) { @@ -1050,9 +1020,8 @@ int ap_proxy_ftp_handler(request_rec *r, cache_req *c, char *url) rc = ftp_getrc(f); Explain1("FTP: returned status %d", rc); if (rc == -1) { - ap_kill_timeout(r); return ap_proxyerror(r, HTTP_BAD_GATEWAY, - "Error reading from remote server"); + "Error reading from remote server"); } if (rc == 550) { Explain0("FTP: RETR failed, trying LIST instead"); @@ -1071,16 +1040,13 @@ int ap_proxy_ftp_handler(request_rec *r, cache_req *c, char *url) rc = ftp_getrc(f); Explain1("FTP: returned status %d", rc); if (rc == -1) { - ap_kill_timeout(r); return ap_proxyerror(r, HTTP_BAD_GATEWAY, - "Error reading from remote server"); + "Error reading from remote server"); } if (rc == 550) { - ap_kill_timeout(r); return HTTP_NOT_FOUND; } if (rc != 250) { - ap_kill_timeout(r); return HTTP_BAD_GATEWAY; } @@ -1098,12 +1064,10 @@ int ap_proxy_ftp_handler(request_rec *r, cache_req *c, char *url) i = ftp_getrc_msg(f, resp, sizeof resp); Explain1("FTP: PWD returned status %d", i); if (i == -1 || i == 421) { - ap_kill_timeout(r); return ap_proxyerror(r, HTTP_BAD_GATEWAY, - "Error reading from remote server"); + "Error reading from remote server"); } if (i == 550) { - ap_kill_timeout(r); return HTTP_NOT_FOUND; } if (i == 257) { @@ -1121,7 +1085,6 @@ int ap_proxy_ftp_handler(request_rec *r, cache_req *c, char *url) return ap_proxyerror(r, HTTP_BAD_GATEWAY, "Error reading from remote server"); } - ap_kill_timeout(r); if (rc != 125 && rc != 150 && rc != 226 && rc != 250) return HTTP_BAD_GATEWAY; @@ -1171,7 +1134,6 @@ int ap_proxy_ftp_handler(request_rec *r, cache_req *c, char *url) } if (!pasvmode) { /* wait for connection */ - ap_hard_timeout("proxy ftp data connect", r); clen = sizeof(struct sockaddr_in); do csd = accept(dsock, (struct sockaddr *) &server, &clen); @@ -1181,22 +1143,19 @@ int ap_proxy_ftp_handler(request_rec *r, cache_req *c, char *url) "proxy: failed to accept data connection"); ap_pclosesocket(p, dsock); ap_bclose(f); - ap_kill_timeout(r); if (c != NULL) c = ap_proxy_cache_error(c); return HTTP_BAD_GATEWAY; } ap_note_cleanups_for_socket(p, csd); data = ap_bcreate(p, B_RDWR | B_SOCKET); - ap_bpushfd(data, csd, -1); - ap_kill_timeout(r); + ap_bpushfd(data, csd); } else { data = ap_bcreate(p, B_RDWR | B_SOCKET); - ap_bpushfd(data, dsock, dsock); + ap_bpushfd(data, dsock); } - ap_hard_timeout("proxy receive", r); /* send response */ /* write status line */ if (!r->assbackwards) @@ -1259,7 +1218,6 @@ int ap_proxy_ftp_handler(request_rec *r, cache_req *c, char *url) Explain1("FTP: returned status %d", i); } - ap_kill_timeout(r); ap_proxy_cache_tidy(c); /* finish */ diff --git a/modules/proxy/proxy_http.c b/modules/proxy/proxy_http.c index 42938062d9..ff092c8acd 100644 --- a/modules/proxy/proxy_http.c +++ b/modules/proxy/proxy_http.c @@ -300,9 +300,8 @@ int ap_proxy_http_handler(request_rec *r, cache_req *c, char *url, clear_connection(r->pool, r->headers_in); /* Strip connection-based headers */ f = ap_bcreate(p, B_RDWR | B_SOCKET); - ap_bpushfd(f, sock, sock); + ap_bpushfd(f, sock); - ap_hard_timeout("proxy send", r); ap_bvputs(f, r->method, " ", proxyhost ? url : urlptr, " HTTP/1.0" CRLF, NULL); if (destportstr != NULL && destport != DEFAULT_HTTP_PORT) @@ -359,14 +358,10 @@ int ap_proxy_http_handler(request_rec *r, cache_req *c, char *url, ap_bwrite(f, buffer, i); } ap_bflush(f); - ap_kill_timeout(r); - - ap_hard_timeout("proxy receive", r); len = ap_bgets(buffer, sizeof buffer - 1, f); if (len == -1) { ap_bclose(f); - ap_kill_timeout(r); ap_log_rerror(APLOG_MARK, APLOG_ERR, r, "ap_bgets() - proxy receive - Error reading from remote server %s (length %d)", proxyhost ? proxyhost : desthost, len); @@ -374,7 +369,6 @@ int ap_proxy_http_handler(request_rec *r, cache_req *c, char *url, "Error reading from remote server"); } else if (len == 0) { ap_bclose(f); - ap_kill_timeout(r); return ap_proxyerror(r, HTTP_BAD_GATEWAY, "Document contains no data"); } @@ -390,7 +384,6 @@ int ap_proxy_http_handler(request_rec *r, cache_req *c, char *url, /* If not an HTTP/1 message or if the status line was > 8192 bytes */ if (buffer[5] != '1' || buffer[len - 1] != '\n') { ap_bclose(f); - ap_kill_timeout(r); return HTTP_BAD_GATEWAY; } backasswards = 0; @@ -448,7 +441,6 @@ int ap_proxy_http_handler(request_rec *r, cache_req *c, char *url, c->hdrs = resp_hdrs; - ap_kill_timeout(r); /* * HTTP/1.0 requires us to accept 3 types of dates, but only generate @@ -479,8 +471,6 @@ int ap_proxy_http_handler(request_rec *r, cache_req *c, char *url, return i; } - ap_hard_timeout("proxy receive", r); - /* write status line */ if (!r->assbackwards) ap_rvputs(r, "HTTP/1.0 ", r->status_line, CRLF, NULL); @@ -515,7 +505,6 @@ int ap_proxy_http_handler(request_rec *r, cache_req *c, char *url, c = ap_proxy_cache_error(c); } } - ap_kill_timeout(r); #ifdef CHARSET_EBCDIC /* What we read/write after the header should not be modified diff --git a/modules/proxy/proxy_util.c b/modules/proxy/proxy_util.c index c1258f1499..1276b6f567 100644 --- a/modules/proxy/proxy_util.c +++ b/modules/proxy/proxy_util.c @@ -59,11 +59,12 @@ #include "mod_proxy.h" #include "http_main.h" #include "ap_md5.h" -#include "multithread.h" #include "http_log.h" #include "util_uri.h" #include "util_date.h" /* get ap_checkmask() decl. */ +#include + static int proxy_match_ipaddr(struct dirconn_entry *This, request_rec *r); static int proxy_match_domainname(struct dirconn_entry *This, request_rec *r); static int proxy_match_hostname(struct dirconn_entry *This, request_rec *r); @@ -515,23 +516,17 @@ long int ap_proxy_send_fb(BUFF *f, request_rec *r, cache_req *c) * has its own timeout handler which can set both buffers to EOUT. */ - ap_kill_timeout(r); - #ifdef WIN32 /* works fine under win32, so leave it */ - ap_hard_timeout("proxy send body", r); - alternate_timeouts = 0; #else /* CHECKME! Since hard_timeout won't work in unix on sends with partial * cache completion, we have to alternate between hard_timeout * for reads, and soft_timeout for send. This is because we need * to get a return from ap_bwrite to be able to continue caching. * BUT, if we *can't* continue anyway, just use hard_timeout. - * (Also, if no cache file is written, use hard timeouts) */ if (c == NULL || c->len <= 0 || c->cache_completion == 1.0) { - ap_hard_timeout("proxy send body", r); alternate_timeouts = 0; } #endif @@ -540,18 +535,10 @@ long int ap_proxy_send_fb(BUFF *f, request_rec *r, cache_req *c) * or (after the client aborted) while we can successfully * read and finish the configured cache_completion. */ - for (ok = 1; ok; ) { - if (alternate_timeouts) - ap_hard_timeout("proxy recv body from upstream server", r); - + for (ok = 1; ok; ) { /* Read block from server */ n = ap_bread(f, buf, IOBUFSIZE); - if (alternate_timeouts) - ap_kill_timeout(r); - else - ap_reset_timeout(r); - if (n == -1) { /* input error */ if (c != NULL) { ap_log_rerror(APLOG_MARK, APLOG_ERR, c->req, @@ -579,16 +566,8 @@ long int ap_proxy_send_fb(BUFF *f, request_rec *r, cache_req *c) /* Write the block to the client, detect aborted transfers */ while (!con->aborted && n > 0) { - if (alternate_timeouts) - ap_soft_timeout("proxy send body", r); - w = ap_bwrite(con->client, &buf[o], n); - if (alternate_timeouts) - ap_kill_timeout(r); - else - ap_reset_timeout(r); - if (w <= 0) { if (c != NULL && c->fp != NULL) { /* when a send failure occurs, we need to decide @@ -617,7 +596,6 @@ long int ap_proxy_send_fb(BUFF *f, request_rec *r, cache_req *c) if (!con->aborted) ap_bflush(con->client); - ap_kill_timeout(r); return total_bytes_rcvd; } @@ -863,6 +841,8 @@ const char * { int i; struct hostent *hp; +/* XXX - Either get rid of TLS, or use pthread/APR functions */ +#define APACHE_TLS static APACHE_TLS struct hostent hpbuf; static APACHE_TLS u_long ipaddr; static APACHE_TLS char *charpbuf[2]; @@ -1239,7 +1219,6 @@ int ap_proxy_doconnect(int sock, struct sockaddr_in *addr, request_rec *r) { int i; - ap_hard_timeout("proxy connect", r); do { i = connect(sock, (struct sockaddr *) addr, sizeof(struct sockaddr_in)); #ifdef WIN32 @@ -1252,7 +1231,6 @@ int ap_proxy_doconnect(int sock, struct sockaddr_in *addr, request_rec *r) "proxy connect to %s port %d failed", inet_ntoa(addr->sin_addr), ntohs(addr->sin_port)); } - ap_kill_timeout(r); return i; } -- cgit v1.2.3