1 /* Copyright 1999-2004 The Apache Software Foundation
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
7 * http://www.apache.org/licenses/LICENSE-2.0
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
19 apr_status_t ajp_ilink_send(apr_socket_t *sock, ajp_msg_t *msg)
26 ap_log_error(APLOG_MARK, APLOG_ERR, 0, NULL,
27 "ajp_ilink_send(): NULL socket provided");
34 buf = (char *)msg->buf;
37 apr_size_t written = length;
39 status = apr_socket_send(sock, buf, &written);
40 if (status != APR_SUCCESS) {
41 ap_log_error(APLOG_MARK, APLOG_ERR, status, NULL,
42 "ajp_ilink_send(): send failed");
53 static apr_status_t ilink_read(apr_socket_t *sock, char * buf,
61 ap_log_error(APLOG_MARK, APLOG_ERR, 0, NULL,
62 "ajp_ilink_readN(): NULL socket provided");
71 status = apr_socket_recv(sock, buf + rdlen, &length);
73 if (status == APR_EOF)
74 return status; /* socket closed. */
75 else if (APR_STATUS_IS_EAGAIN(status))
77 else if (status != APR_SUCCESS)
78 return status; /* any error. */
87 apr_status_t ajp_ilink_receive(apr_socket_t *sock, ajp_msg_t *msg)
94 ap_log_error(APLOG_MARK, APLOG_ERR, 0, NULL,
95 "ajp_ilink_receive(): NULL socket provided");
99 hlen = msg->header_len;
101 status = ilink_read(sock, msg->buf, hlen);
103 if (status != APR_SUCCESS) {
104 ap_log_error(APLOG_MARK, APLOG_ERR, status, NULL,
105 "ajp_ilink_receive() can't receive header\n");
106 return AJP_ENO_HEADER;
109 status = ajp_msg_check_header(msg, &blen);
111 if (status != APR_SUCCESS) {
112 ap_log_error(APLOG_MARK, APLOG_ERR, 0, NULL,
113 "ajp_ilink_receive() received bad header\n");
114 return AJP_EBAD_HEADER;
117 status = ilink_read(sock, msg->buf + hlen, blen);
119 if (status != APR_SUCCESS) {
120 ap_log_error(APLOG_MARK, APLOG_ERR, status, NULL,
121 "ajp_ilink_receive() error while receiving message body of length %d\n",
123 return AJP_EBAD_MESSAGE;
126 ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, NULL,
127 "ajp_ilink_receive() received packet len=%d type=%d\n",
128 blen, (int)msg->buf[hlen]);