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_arch_file_io.h"
18
#include "apr_arch_networkio.h"
20
#include "apr_errno.h"
21
#include "apr_support.h"
23
/* The only case where we don't use wait_for_io_or_timeout is on
24
* pre-BONE BeOS, so this check should be sufficient and simpler */
26
#define USE_WAIT_FOR_IO
29
#ifdef USE_WAIT_FOR_IO
31
#ifdef WAITIO_USES_POLL
36
#ifdef HAVE_SYS_POLL_H
40
apr_status_t apr_wait_for_io_or_timeout(apr_file_t *f, apr_socket_t *s,
46
timeout = f ? f->timeout / 1000 : s->timeout / 1000;
47
pfd.fd = f ? f->filedes : s->socketdes;
48
pfd.events = for_read ? POLLIN : POLLOUT;
51
rc = poll(&pfd, 1, timeout);
52
} while (rc == -1 && errno == EINTR);
64
#else /* !WAITIO_USES_POLL */
66
apr_status_t apr_wait_for_io_or_timeout(apr_file_t *f, apr_socket_t *s,
69
apr_interval_time_t timeout;
71
int type = for_read ? APR_POLLIN : APR_POLLOUT;
72
apr_pollset_t *pollset;
75
/* TODO - timeout should be less each time through this loop */
77
pfd.desc_type = APR_POLL_FILE;
81
if (pollset == NULL) {
82
status = apr_pollset_create(&(f->pollset), 1, f->pool, 0);
83
if (status != APR_SUCCESS) {
91
pfd.desc_type = APR_POLL_SOCKET;
99
/* Remove the object if it was in the pollset, then add in the new
100
* object with the correct reqevents value. Ignore the status result
101
* on the remove, because it might not be in there (yet).
103
(void) apr_pollset_remove(pollset, &pfd);
105
/* ### check status code */
106
(void) apr_pollset_add(pollset, &pfd);
110
const apr_pollfd_t *pdesc;
112
status = apr_pollset_poll(pollset, timeout, &numdesc, &pdesc);
114
if (numdesc == 1 && (pdesc[0].rtnevents & type) != 0) {
117
} while (APR_STATUS_IS_EINTR(status));
121
#endif /* WAITIO_USES_POLL */
123
#endif /* USE_WAIT_FOR_IO */