1 /* Licensed to the Apache Software Foundation (ASF) under one or more
2 * contributor license agreements. See the NOTICE file distributed with
3 * this work for additional information regarding copyright ownership.
4 * The ASF licenses this file to You under the Apache License, Version 2.0
5 * (the "License"); you may not use this file except in compliance with
6 * the License. You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 APLOG_USE_MODULE(proxy_ajp);
21 apr_status_t ajp_ilink_send(apr_socket_t *sock, ajp_msg_t *msg)
30 buf = (char *)msg->buf;
33 apr_size_t written = length;
35 status = apr_socket_send(sock, buf, &written);
36 if (status != APR_SUCCESS) {
37 ap_log_error(APLOG_MARK, APLOG_ERR, status, NULL,
38 "ajp_ilink_send(): send failed");
49 static apr_status_t ilink_read(apr_socket_t *sock, apr_byte_t *buf,
52 apr_size_t length = len;
58 status = apr_socket_recv(sock, (char *)(buf + rdlen), &length);
60 if (status == APR_EOF)
61 return status; /* socket closed. */
62 else if (APR_STATUS_IS_EAGAIN(status))
64 else if (status != APR_SUCCESS)
65 return status; /* any error. */
74 apr_status_t ajp_ilink_receive(apr_socket_t *sock, ajp_msg_t *msg)
80 hlen = msg->header_len;
82 status = ilink_read(sock, msg->buf, hlen);
84 if (status != APR_SUCCESS) {
85 ap_log_error(APLOG_MARK, APLOG_ERR, status, NULL,
86 "ajp_ilink_receive() can't receive header");
87 return (APR_STATUS_IS_TIMEUP(status) ? APR_TIMEUP : AJP_ENO_HEADER);
90 status = ajp_msg_check_header(msg, &blen);
92 if (status != APR_SUCCESS) {
93 ap_log_error(APLOG_MARK, APLOG_ERR, 0, NULL,
94 "ajp_ilink_receive() received bad header");
95 return AJP_EBAD_HEADER;
98 status = ilink_read(sock, msg->buf + hlen, blen);
100 if (status != APR_SUCCESS) {
101 ap_log_error(APLOG_MARK, APLOG_ERR, status, NULL,
102 "ajp_ilink_receive() error while receiving message body "
103 "of length %" APR_SIZE_T_FMT,
105 return AJP_EBAD_MESSAGE;
108 ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, NULL,
109 "ajp_ilink_receive() received packet len=%" APR_SIZE_T_FMT
111 blen, (int)msg->buf[hlen]);