--- /dev/null
+/* Licensed to the Apache Software Foundation (ASF) under one or more\r
+ * contributor license agreements. See the NOTICE file distributed with\r
+ * this work for additional information regarding copyright ownership.\r
+ * The ASF licenses this file to You under the Apache License, Version 2.0\r
+ * (the "License"); you may not use this file except in compliance with\r
+ * the License. You may obtain a copy of the License at\r
+ *\r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ */\r
+\r
+#include "ajp.h"\r
+\r
+/*\r
+ * Handle the CPING/CPONG\r
+ */\r
+apr_status_t ajp_handle_cping_cpong(apr_socket_t *sock,\r
+ request_rec *r,\r
+ apr_interval_time_t timeout)\r
+{\r
+ ajp_msg_t *msg;\r
+ apr_status_t rc;\r
+ apr_interval_time_t org;\r
+ apr_byte_t result;\r
+\r
+ ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, r->server,\r
+ "Into ajp_handle_cping_cpong");\r
+\r
+ rc = ajp_msg_create(r->pool, &msg);\r
+ if (rc != APR_SUCCESS) {\r
+ ap_log_error(APLOG_MARK, APLOG_ERR, 0, r->server,\r
+ "ajp_handle_cping_cpong: ajp_msg_create failed");\r
+ return rc;\r
+ }\r
+\r
+ rc = ajp_msg_serialize_cping(msg);\r
+ if (rc != APR_SUCCESS) {\r
+ ap_log_error(APLOG_MARK, APLOG_ERR, 0, r->server,\r
+ "ajp_handle_cping_cpong: ajp_marshal_into_msgb failed");\r
+ return rc;\r
+ }\r
+\r
+ rc = ajp_ilink_send(sock, msg);\r
+ if (rc != APR_SUCCESS) {\r
+ ap_log_error(APLOG_MARK, APLOG_ERR, 0, r->server,\r
+ "ajp_handle_cping_cpong: ajp_ilink_send failed");\r
+ return rc;\r
+ }\r
+\r
+ rc = apr_socket_timeout_get(sock, &org);\r
+ if (rc != APR_SUCCESS) {\r
+ ap_log_error(APLOG_MARK, APLOG_ERR, 0, r->server,\r
+ "ajp_handle_cping_cpong: apr_socket_timeout_get failed");\r
+ return rc;\r
+ }\r
+\r
+ /* Set CPING/CPONG response timeout */\r
+ rc = apr_socket_timeout_set(sock, timeout);\r
+ if (rc != APR_SUCCESS) {\r
+ ap_log_error(APLOG_MARK, APLOG_ERR, 0, r->server,\r
+ "ajp_handle_cping_cpong: apr_socket_timeout_set failed");\r
+ return rc;\r
+ }\r
+ ajp_msg_reuse(msg);\r
+\r
+ /* Read CPONG reply */\r
+ rc = ajp_ilink_receive(sock, msg);\r
+ if (rc != APR_SUCCESS) {\r
+ ap_log_error(APLOG_MARK, APLOG_ERR, 0, r->server,\r
+ "ajp_handle_cping_cpong: ajp_ilink_receive failed");\r
+ return rc;\r
+ }\r
+\r
+ rc = ajp_msg_get_uint8(msg, &result);\r
+ if (rc != APR_SUCCESS) {\r
+ ap_log_error(APLOG_MARK, APLOG_ERR, 0, r->server,\r
+ "ajp_handle_cping_cpong: invalid CPONG message");\r
+ return rc;\r
+ }\r
+ if (result != CMD_AJP13_CPONG) {\r
+ ap_log_error(APLOG_MARK, APLOG_ERR, 0, r->server,\r
+ "ajp_handle_cping_cpong: awaited CPONG, received %d ",\r
+ result);\r
+ return APR_EGENERAL;\r
+\r
+ }\r
+\r
+ /* Restore original socket timeout */\r
+ rc = apr_socket_timeout_set(sock, org);\r
+ if (rc != APR_SUCCESS) {\r
+ ap_log_error(APLOG_MARK, APLOG_ERR, 0, r->server,\r
+ "ajp_handle_cping_cpong: apr_socket_timeout_set failed");\r
+ return rc;\r
+ }\r
+\r
+ ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, r->server,\r
+ "ajp_handle_cping_cpong: Done");\r
+ return APR_SUCCESS;\r
+}\r