Commit 6f2afefa authored by Mladen Turk's avatar Mladen Turk
Browse files

Backport support for ping/pong.

git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/branches/2.2.x@479647 13f79535-47bb-0310-9956-ffa450edef68
parent e51f9a62
Loading
Loading
Loading
Loading
+6 −0
Changes for CHANGES: 6 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -17,6 +17,12 @@ Changes with Apache 2.2.4
     parameter in the URL correctly. PR 40400.
     [Ruediger Pluem, Tomokazu Harada <harada sysrdc.ns-sol.co.jp>]
  *) mod_proxy_ajp: Added cping/cpong support for the AJP protocol.
     A new worker directive ping=timeout will cause CPING packet
     to be send expecting CPONG packet within defined timeout.  
     In case the backend is too busy this will fail instead
     sending the full header.  [Mladen Turk]
  *) mod_disk_cache: Make sure that only positive integers are accepted
     for the CacheMaxFileSize and CacheMinFileSize parameters in the
     config file. PR39380 [Niklas Edmundsson <nikke acc.umu.se>]
+0 −12
Changes for STATUS: 0 added lines, 12 removed lines.
Original line number Diff line number Diff line
@@ -156,18 +156,6 @@ PATCHES PROPOSED TO BACKPORT FROM TRUNK:
        deflate output filter.
      +1: rpluem, niq

    * mod_proxy: Add in support for ping/pong (heartbeat test) for
      the Proxy. Implement cping/cpong for AJP.
      Trunk version of patch:
        http://svn.apache.org/viewvc?view=rev&revision=425454
      2.2.x version of patch:
        http://people.apache.org/~jim/patches/pingpong2.txt
        http://svn.apache.org/viewvc?view=rev&revision=425559
        http://svn.apache.org/viewvc?view=rev&revision=425690
        http://svn.apache.org/viewvc?view=rev&revision=452549
        (Note: your patch should auto-createmodules/proxy/ajp_utils.c)
      +1: jim, rpluem, mturk

    * Allow htcacheclean and httxt2dbm to link apr/apr-util statically
      like the older support programs.
      Trunk version of patch:
+1 −0
Changes for modules/proxy/NWGNUproxyajp: 1 added line, 0 removed lines.
Original line number Diff line number Diff line
@@ -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)

+11 −0
Changes for modules/proxy/ajp.h: 11 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -471,6 +471,17 @@ apr_status_t ajp_parse_header(request_rec *r, proxy_dir_conf *conf,
apr_status_t  ajp_parse_data(request_rec  *r, ajp_msg_t *msg,
                             apr_uint16_t *len, char **ptr);


/** 
 * Handle the CPING/CPONG messages
 * @param sock      backend socket
 * @param r         current request
 * @param timeout   time window for receiving cpong reply
 * @return          APR_SUCCESS or error
 */
apr_status_t ajp_handle_cping_cpong(apr_socket_t *sock,
                                    request_rec *r,
                                    apr_interval_time_t timeout);
/** @} */

#endif /* AJP_H */
+105 −0
Changes for modules/proxy/ajp_utils.c: 105 added lines, 0 removed lines.
Original line number Diff line number Diff line
/* 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, rv;
    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 */
    rv = ajp_ilink_receive(sock, msg);
    if (rv != APR_SUCCESS) {
        ap_log_error(APLOG_MARK, APLOG_ERR, 0, r->server,
               "ajp_handle_cping_cpong: ajp_ilink_receive failed");
        goto cleanup;
    }

    rv = ajp_msg_get_uint8(msg, &result);
    if (rv != APR_SUCCESS) {
        ap_log_error(APLOG_MARK, APLOG_ERR, 0, r->server,
               "ajp_handle_cping_cpong: invalid CPONG message");
        goto cleanup;
    }
    if (result != CMD_AJP13_CPONG) {
        ap_log_error(APLOG_MARK, APLOG_ERR, 0, r->server,
               "ajp_handle_cping_cpong: awaited CPONG, received %d ",
               result);
        rv = APR_EGENERAL;
        goto cleanup;
    }

cleanup:
    /* 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 rv;
}
Loading