summaryrefslogtreecommitdiffstats
path: root/modules/proxy
diff options
context:
space:
mode:
authorMladen Turk <mturk@apache.org>2006-07-25 18:50:07 +0200
committerMladen Turk <mturk@apache.org>2006-07-25 18:50:07 +0200
commit4fd2c57da015ee636ed7e5a4c627b0402cdf6ba8 (patch)
treefc3681eb04e3496554193ecf06fce6011bea7298 /modules/proxy
parentAdd mod_authz_core module to the build. (diff)
downloadapache2-4fd2c57da015ee636ed7e5a4c627b0402cdf6ba8.tar.xz
apache2-4fd2c57da015ee636ed7e5a4c627b0402cdf6ba8.zip
Added cping/cpong support for the AJP protocol.
git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@425454 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'modules/proxy')
-rw-r--r--modules/proxy/NWGNUproxyajp1
-rw-r--r--modules/proxy/ajp_utils.c104
-rw-r--r--modules/proxy/mod_proxy.c11
-rw-r--r--modules/proxy/mod_proxy.h2
-rw-r--r--modules/proxy/mod_proxy_ajp.c14
-rw-r--r--modules/proxy/mod_proxy_ajp.dsp4
6 files changed, 135 insertions, 1 deletions
diff --git a/modules/proxy/NWGNUproxyajp b/modules/proxy/NWGNUproxyajp
index 3d65d706c4..6750891413 100644
--- a/modules/proxy/NWGNUproxyajp
+++ b/modules/proxy/NWGNUproxyajp
@@ -171,6 +171,7 @@ FILES_nlm_objs = \
$(OBJDIR)/ajp_header.o \
$(OBJDIR)/ajp_msg.o \
$(OBJDIR)/ajp_link.o \
+ $(OBJDIR)/ajp_utils.o \
$(OBJDIR)/libprews.o \
$(EOLIST)
diff --git a/modules/proxy/ajp_utils.c b/modules/proxy/ajp_utils.c
new file mode 100644
index 0000000000..3532eb8546
--- /dev/null
+++ b/modules/proxy/ajp_utils.c
@@ -0,0 +1,104 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "ajp.h"
+
+/*
+ * Handle the CPING/CPONG
+ */
+apr_status_t ajp_handle_cping_cpong(apr_socket_t *sock,
+ request_rec *r,
+ apr_interval_time_t timeout)
+{
+ ajp_msg_t *msg;
+ apr_status_t rc;
+ apr_interval_time_t org;
+ apr_byte_t result;
+
+ ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, r->server,
+ "Into ajp_handle_cping_cpong");
+
+ rc = ajp_msg_create(r->pool, &msg);
+ if (rc != APR_SUCCESS) {
+ ap_log_error(APLOG_MARK, APLOG_ERR, 0, r->server,
+ "ajp_handle_cping_cpong: ajp_msg_create failed");
+ return rc;
+ }
+
+ rc = ajp_msg_serialize_cping(msg);
+ if (rc != APR_SUCCESS) {
+ ap_log_error(APLOG_MARK, APLOG_ERR, 0, r->server,
+ "ajp_handle_cping_cpong: ajp_marshal_into_msgb failed");
+ return rc;
+ }
+
+ rc = ajp_ilink_send(sock, msg);
+ if (rc != APR_SUCCESS) {
+ ap_log_error(APLOG_MARK, APLOG_ERR, 0, r->server,
+ "ajp_handle_cping_cpong: ajp_ilink_send failed");
+ return rc;
+ }
+
+ rc = apr_socket_timeout_get(sock, &org);
+ if (rc != APR_SUCCESS) {
+ ap_log_error(APLOG_MARK, APLOG_ERR, 0, r->server,
+ "ajp_handle_cping_cpong: apr_socket_timeout_get failed");
+ return rc;
+ }
+
+ /* Set CPING/CPONG response timeout */
+ rc = apr_socket_timeout_set(sock, timeout);
+ if (rc != APR_SUCCESS) {
+ ap_log_error(APLOG_MARK, APLOG_ERR, 0, r->server,
+ "ajp_handle_cping_cpong: apr_socket_timeout_set failed");
+ return rc;
+ }
+ ajp_msg_reuse(msg);
+
+ /* Read CPONG reply */
+ rc = ajp_ilink_receive(sock, msg);
+ if (rc != APR_SUCCESS) {
+ ap_log_error(APLOG_MARK, APLOG_ERR, 0, r->server,
+ "ajp_handle_cping_cpong: ajp_ilink_receive failed");
+ return rc;
+ }
+
+ rc = ajp_msg_get_uint8(msg, &result);
+ if (rc != APR_SUCCESS) {
+ ap_log_error(APLOG_MARK, APLOG_ERR, 0, r->server,
+ "ajp_handle_cping_cpong: invalid CPONG message");
+ return rc;
+ }
+ if (result != CMD_AJP13_CPONG) {
+ ap_log_error(APLOG_MARK, APLOG_ERR, 0, r->server,
+ "ajp_handle_cping_cpong: awaited CPONG, received %d ",
+ result);
+ return APR_EGENERAL;
+
+ }
+
+ /* Restore original socket timeout */
+ rc = apr_socket_timeout_set(sock, org);
+ if (rc != APR_SUCCESS) {
+ ap_log_error(APLOG_MARK, APLOG_ERR, 0, r->server,
+ "ajp_handle_cping_cpong: apr_socket_timeout_set failed");
+ return rc;
+ }
+
+ ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, r->server,
+ "ajp_handle_cping_cpong: Done");
+ return APR_SUCCESS;
+}
diff --git a/modules/proxy/mod_proxy.c b/modules/proxy/mod_proxy.c
index 26aae7fb9a..2b1a9ba3d0 100644
--- a/modules/proxy/mod_proxy.c
+++ b/modules/proxy/mod_proxy.c
@@ -244,6 +244,15 @@ static const char *set_worker_param(apr_pool_t *p,
else
worker->flush_wait = ival * 1000; /* change to microseconds */
}
+ else if (!strcasecmp(key, "ping")) {
+ /* Ping/Pong timeout in seconds.
+ */
+ ival = atoi(val);
+ if (ival < 1)
+ return "Ping/Pong timeout must be at least one second";
+ worker->ping_timeout = apr_time_from_sec(ival);
+ worker->ping_timeout_set = 1;
+ }
else {
return "unknown Worker parameter";
}
@@ -423,7 +432,7 @@ static const char *proxy_interpolate(request_rec *r, const char *str)
const char *var;
const char *val;
const char *firstpart;
-
+
start = ap_strstr_c(str, "${");
if (start == NULL) {
return str;
diff --git a/modules/proxy/mod_proxy.h b/modules/proxy/mod_proxy.h
index bc35f87e79..66e27dcbf6 100644
--- a/modules/proxy/mod_proxy.h
+++ b/modules/proxy/mod_proxy.h
@@ -332,6 +332,8 @@ struct proxy_worker {
flush_auto
} flush_packets; /* control AJP flushing */
int flush_wait; /* poll wait time in microseconds if flush_auto */
+ apr_interval_time_t ping_timeout;
+ char ping_timeout_set;
};
/*
diff --git a/modules/proxy/mod_proxy_ajp.c b/modules/proxy/mod_proxy_ajp.c
index 1a0d6e155e..bbca7fe9ba 100644
--- a/modules/proxy/mod_proxy_ajp.c
+++ b/modules/proxy/mod_proxy_ajp.c
@@ -530,6 +530,20 @@ static int proxy_ajp_handler(request_rec *r, proxy_worker *worker,
goto cleanup;
}
+ /* Handle CPING/CPONG */
+ if (worker->ping_timeout_set) {
+ status = ajp_handle_cping_cpong(backend->sock, r,
+ worker->ping_timeout);
+ if (status != APR_SUCCESS) {
+ backend->close++;
+ ap_log_error(APLOG_MARK, APLOG_ERR, status, r->server,
+ "proxy: AJP: cping/cpong failed to %pI (%s)",
+ worker->cp->addr,
+ worker->hostname);
+ status = HTTP_SERVICE_UNAVAILABLE;
+ goto cleanup;
+ }
+ }
/* Step Three: Process the Request */
status = ap_proxy_ajp_request(p, r, backend, origin, dconf, uri, url,
server_portstr);
diff --git a/modules/proxy/mod_proxy_ajp.dsp b/modules/proxy/mod_proxy_ajp.dsp
index 989a702028..0a0873b92f 100644
--- a/modules/proxy/mod_proxy_ajp.dsp
+++ b/modules/proxy/mod_proxy_ajp.dsp
@@ -126,6 +126,10 @@ SOURCE=.\ajp_link.c
SOURCE=.\ajp_msg.c
# End Source File
+# Begin Source File
+
+SOURCE=.\ajp_utils.c
+# End Source File
# End Group
# Begin Source File