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.
20 apr_status_t
ajp_ilink_send(apr_socket_t
*sock
, ajp_msg_t
*msg
)
27 ap_log_error(APLOG_MARK
, APLOG_ERR
, 0, NULL
,
28 "ajp_ilink_send(): NULL socket provided");
35 buf
= (char *)msg
->buf
;
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");
54 static apr_status_t
ilink_read(apr_socket_t
*sock
, apr_byte_t
*buf
,
57 apr_size_t length
= 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
))
69 else if (status
!= APR_SUCCESS
)
70 return status
; /* any error. */
79 apr_status_t
ajp_ilink_receive(apr_socket_t
*sock
, ajp_msg_t
*msg
)
86 ap_log_error(APLOG_MARK
, APLOG_ERR
, 0, NULL
,
87 "ajp_ilink_receive(): NULL socket provided");
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
,
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
122 blen
, (int)msg
->buf
[hlen
]);