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 "apr_arch_networkio.h"
18 #include "apr_errno.h"
19 #include "apr_general.h"
20 #include "apr_network_io.h"
21 #include "apr_support.h"
26 APR_DECLARE(apr_status_t) apr_socket_sendto(apr_socket_t *sock,
27 apr_sockaddr_t *where,
28 apr_int32_t flags, const char *buf,
35 rv = sendto(sock->socketdes, buf, (*len), flags,
36 (struct sockaddr*)&where->sa,
38 } while (rv == -1 && (serrno = sock_errno()) == EINTR);
40 if (rv == -1 && serrno == SOCEWOULDBLOCK && sock->timeout != 0) {
41 apr_status_t arv = apr_wait_for_io_or_timeout(NULL, sock, 0);
43 if (arv != APR_SUCCESS) {
48 rv = sendto(sock->socketdes, buf, *len, flags,
49 (const struct sockaddr*)&where->sa,
51 } while (rv == -1 && (serrno = sock_errno()) == SOCEINTR);
57 return APR_FROM_OS_ERROR(serrno);
66 APR_DECLARE(apr_status_t) apr_socket_recvfrom(apr_sockaddr_t *from,
68 apr_int32_t flags, char *buf,
75 rv = recvfrom(sock->socketdes, buf, (*len), flags,
76 (struct sockaddr*)&from->sa, &from->salen);
77 } while (rv == -1 && (serrno = sock_errno()) == EINTR);
79 if (rv == -1 && serrno == SOCEWOULDBLOCK && sock->timeout != 0) {
80 apr_status_t arv = apr_wait_for_io_or_timeout(NULL, sock, 1);
82 if (arv != APR_SUCCESS) {
87 rv = recvfrom(sock->socketdes, buf, *len, flags,
88 (struct sockaddr*)&from->sa, &from->salen);
89 } while (rv == -1 && (serrno = sock_errno()) == EINTR);
95 return APR_FROM_OS_ERROR(serrno);
100 if (rv == 0 && sock->type == SOCK_STREAM)