1
/* Copyright 2000-2005 The Apache Software Foundation or its licensors, as
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
* you may not use this file except in compliance with the License.
6
* 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_private.h"
18
#if BEOS_BONE /* BONE uses the unix code - woohoo */
19
#include "../unix/sendrecv.c"
21
#include "apr_arch_networkio.h"
24
static apr_status_t wait_for_io_or_timeout(apr_socket_t *sock, int for_read)
26
struct timeval tv, *tvptr;
32
FD_SET(sock->socketdes, &fdset);
33
if (sock->timeout < 0) {
37
tv.tv_sec = sock->timeout / APR_USEC_PER_SEC;
38
tv.tv_usec = sock->timeout % APR_USEC_PER_SEC;
41
srv = select(sock->socketdes + 1,
42
for_read ? &fdset : NULL,
43
for_read ? NULL : &fdset,
46
/* TODO - timeout should be smaller on repeats of this loop */
47
} while (srv == -1 && errno == EINTR);
58
#define SEND_WAIT APR_USEC_PER_SEC / 10
60
APR_DECLARE(apr_status_t) apr_socket_send(apr_socket_t *sock, const char *buf,
66
rv = send(sock->socketdes, buf, (*len), 0);
67
} while (rv == -1 && errno == EINTR);
69
if (rv == -1 && errno == EWOULDBLOCK && sock->timeout > 0) {
70
apr_int32_t snooze_val = SEND_WAIT;
74
rv = send(sock->socketdes, buf, (*len), 0);
75
if (rv == -1 && errno == EWOULDBLOCK){
76
apr_sleep (snooze_val);
78
snooze_val += SEND_WAIT;
79
/* have we passed our timeout value */
80
if (zzz > (sock->timeout * APR_USEC_PER_SEC))
83
} while (rv == -1 && (errno == EINTR || errno == EWOULDBLOCK));
94
APR_DECLARE(apr_status_t) apr_socket_recv(apr_socket_t *sock, char *buf,
100
rv = recv(sock->socketdes, buf, (*len), 0);
101
} while (rv == -1 && errno == EINTR);
103
if (rv == -1 && errno == EWOULDBLOCK && sock->timeout > 0) {
104
apr_status_t arv = wait_for_io_or_timeout(sock, 1);
105
if (arv != APR_SUCCESS) {
111
rv = recv(sock->socketdes, buf, (*len), 0);
112
} while (rv == -1 && errno == EINTR);
125
/* BeOS doesn't have writev for sockets so we use the following instead...
127
APR_DECLARE(apr_status_t) apr_socket_sendv(apr_socket_t * sock,
128
const struct iovec *vec,
129
apr_int32_t nvec, apr_size_t *len)
131
*len = vec[0].iov_len;
132
return apr_socket_send(sock, vec[0].iov_base, len);
135
APR_DECLARE(apr_status_t) apr_socket_sendto(apr_socket_t *sock,
136
apr_sockaddr_t *where,
137
apr_int32_t flags, const char *buf,
143
rv = sendto(sock->socketdes, buf, (*len), flags,
144
(const struct sockaddr*)&where->sa,
146
} while (rv == -1 && errno == EINTR);
148
if (rv == -1 && (errno == EAGAIN || errno == EWOULDBLOCK)
149
&& sock->timeout != 0) {
150
apr_status_t arv = wait_for_io_or_timeout(sock, 0);
151
if (arv != APR_SUCCESS) {
156
rv = sendto(sock->socketdes, buf, (*len), flags,
157
(const struct sockaddr*)&where->sa,
159
} while (rv == -1 && errno == EINTR);
170
APR_DECLARE(apr_status_t) apr_socket_recvfrom(apr_sockaddr_t *from,
172
apr_int32_t flags, char *buf,
179
/* Not sure if this is correct. Maybe we should just allocate
185
rv = recvfrom(sock->socketdes, buf, (*len), flags,
186
(struct sockaddr*)&from->sa, &from->salen);
187
} while (rv == -1 && errno == EINTR);
189
if (rv == -1 && (errno == EAGAIN || errno == EWOULDBLOCK) &&
190
sock->timeout != 0) {
191
apr_status_t arv = wait_for_io_or_timeout(sock, 1);
192
if (arv != APR_SUCCESS) {
197
rv = recvfrom(sock->socketdes, buf, (*len), flags,
198
(struct sockaddr*)&from->sa, &from->salen);
199
} while (rv == -1 && errno == EINTR);
214
#endif /* ! BEOS_BONE */