Moved apache code into a folder to help prepare for packaging where we dont want...
[httpd-crcsyncproxy.git] / apache / modules / proxy / ajp_link.c
blob04c8f092e9260a74379171a8e982b5b26b620d8e
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.
17 #include "ajp.h"
20 apr_status_t ajp_ilink_send(apr_socket_t *sock, ajp_msg_t *msg)
22 char *buf;
23 apr_status_t status;
24 apr_size_t length;
26 if (sock == NULL) {
27 ap_log_error(APLOG_MARK, APLOG_ERR, 0, NULL,
28 "ajp_ilink_send(): NULL socket provided");
29 return AJP_EINVAL;
32 ajp_msg_end(msg);
34 length = msg->len;
35 buf = (char *)msg->buf;
37 do {
38 apr_size_t written = length;
40 status = apr_socket_send(sock, buf, &written);
41 if (status != APR_SUCCESS) {
42 ap_log_error(APLOG_MARK, APLOG_ERR, status, NULL,
43 "ajp_ilink_send(): send failed");
44 return status;
46 length -= written;
47 buf += written;
48 } while (length);
50 return APR_SUCCESS;
54 static apr_status_t ilink_read(apr_socket_t *sock, apr_byte_t *buf,
55 apr_size_t len)
57 apr_size_t length = len;
58 apr_size_t rdlen = 0;
59 apr_status_t status;
61 while (rdlen < len) {
63 status = apr_socket_recv(sock, (char *)(buf + rdlen), &length);
65 if (status == APR_EOF)
66 return status; /* socket closed. */
67 else if (APR_STATUS_IS_EAGAIN(status))
68 continue;
69 else if (status != APR_SUCCESS)
70 return status; /* any error. */
72 rdlen += length;
73 length = len - rdlen;
75 return APR_SUCCESS;
79 apr_status_t ajp_ilink_receive(apr_socket_t *sock, ajp_msg_t *msg)
81 apr_status_t status;
82 apr_size_t hlen;
83 apr_size_t blen;
85 if (sock == NULL) {
86 ap_log_error(APLOG_MARK, APLOG_ERR, 0, NULL,
87 "ajp_ilink_receive(): NULL socket provided");
88 return AJP_EINVAL;
91 hlen = msg->header_len;
93 status = ilink_read(sock, msg->buf, hlen);
95 if (status != APR_SUCCESS) {
96 ap_log_error(APLOG_MARK, APLOG_ERR, status, NULL,
97 "ajp_ilink_receive() can't receive header");
98 return AJP_ENO_HEADER;
101 status = ajp_msg_check_header(msg, &blen);
103 if (status != APR_SUCCESS) {
104 ap_log_error(APLOG_MARK, APLOG_ERR, 0, NULL,
105 "ajp_ilink_receive() received bad header");
106 return AJP_EBAD_HEADER;
109 status = ilink_read(sock, msg->buf + hlen, blen);
111 if (status != APR_SUCCESS) {
112 ap_log_error(APLOG_MARK, APLOG_ERR, status, NULL,
113 "ajp_ilink_receive() error while receiving message body "
114 "of length %" APR_SIZE_T_FMT,
115 hlen);
116 return AJP_EBAD_MESSAGE;
119 ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, NULL,
120 "ajp_ilink_receive() received packet len=%" APR_SIZE_T_FMT
121 "type=%d",
122 blen, (int)msg->buf[hlen]);
124 return APR_SUCCESS;