Apache HTTPD
framework
httpd-2.4.62
srclib
apr
support
unix
waitio.c
Go to the documentation of this file.
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
7
*
8
* http://www.apache.org/licenses/LICENSE-2.0
9
*
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.
15
*/
16
17
#include "apr_arch_file_io.h"
18
#include "apr_arch_networkio.h"
19
#include "
apr_poll.h
"
20
#include "
apr_errno.h
"
21
#include "
apr_support.h
"
22
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 */
25
#if !defined(BEOS_R5) && !defined(OS2) && APR_FILES_AS_SOCKETS
26
#define USE_WAIT_FOR_IO
27
#endif
28
29
#ifdef USE_WAIT_FOR_IO
30
31
#ifdef WAITIO_USES_POLL
32
33
#if HAVE_POLL_H
34
#include <poll.h>
35
#elif HAVE_SYS_POLL_H
36
#include <sys/poll.h>
37
#endif
38
39
apr_status_t
apr_wait_for_io_or_timeout
(
apr_file_t
*
f
,
apr_socket_t
*
s
,
40
int
for_read
)
41
{
42
struct
pollfd
pfd;
43
int
rc
,
timeout
;
44
45
timeout
=
f
?
f
->
timeout
:
s
->timeout;
46
pfd.fd =
f
?
f
->
filedes
:
s
->socketdes;
47
pfd.events =
for_read
?
POLLIN
:
POLLOUT
;
48
49
if
(
timeout
> 0) {
50
timeout
= (
timeout
+ 999) / 1000;
51
}
52
do
{
53
rc
= poll(&pfd, 1,
timeout
);
54
}
while
(
rc
== -1 &&
errno
==
EINTR
);
55
if
(
rc
== 0) {
56
return
APR_TIMEUP
;
57
}
58
else
if
(
rc
> 0) {
59
return
APR_SUCCESS
;
60
}
61
else
{
62
return
errno
;
63
}
64
}
65
66
#else
/* !WAITIO_USES_POLL */
67
68
apr_status_t
apr_wait_for_io_or_timeout
(
apr_file_t
*
f
,
apr_socket_t
*
s
,
69
int
for_read
)
70
{
71
apr_interval_time_t
timeout
;
72
apr_pollfd_t
pfd;
73
int
type
=
for_read
?
APR_POLLIN
:
APR_POLLOUT
;
74
apr_pollset_t
*
pollset
;
75
apr_status_t
status
;
76
77
/* TODO - timeout should be less each time through this loop */
78
if
(
f
) {
79
pfd.
desc_type
=
APR_POLL_FILE
;
80
pfd.
desc
.
f
=
f
;
81
82
pollset
=
f
->
pollset
;
83
if
(
pollset
==
NULL
) {
84
status
=
apr_pollset_create
(&(
f
->
pollset
), 1,
f
->
pool
, 0);
85
if
(
status
!=
APR_SUCCESS
) {
86
return
status
;
87
}
88
pollset
=
f
->
pollset
;
89
}
90
timeout
=
f
->
timeout
;
91
}
92
else
{
93
pfd.
desc_type
=
APR_POLL_SOCKET
;
94
pfd.
desc
.
s
=
s
;
95
96
pollset
=
s
->
pollset
;
97
timeout
=
s
->timeout;
98
}
99
pfd.
reqevents
=
type
;
100
101
/* Remove the object if it was in the pollset, then add in the new
102
* object with the correct reqevents value. Ignore the status result
103
* on the remove, because it might not be in there (yet).
104
*/
105
(void)
apr_pollset_remove
(
pollset
, &pfd);
106
107
/* ### check status code */
108
(void)
apr_pollset_add
(
pollset
, &pfd);
109
110
do
{
111
int
numdesc
;
112
const
apr_pollfd_t
*
pdesc
;
113
114
status
=
apr_pollset_poll
(
pollset
,
timeout
, &
numdesc
, &
pdesc
);
115
116
if
(
numdesc
== 1 && (
pdesc
[0].rtnevents &
type
) != 0) {
117
return
APR_SUCCESS
;
118
}
119
}
while
(
APR_STATUS_IS_EINTR
(
status
));
120
121
return
status
;
122
}
123
#endif
/* WAITIO_USES_POLL */
124
125
#endif
/* USE_WAIT_FOR_IO */
apr_errno.h
APR Error Codes.
apr_poll.h
APR Poll interface.
apr_support.h
APR Support functions.
APR_TIMEUP
#define APR_TIMEUP
Definition
apr_errno.h:450
APR_STATUS_IS_EINTR
#define APR_STATUS_IS_EINTR(s)
Definition
apr_errno.h:1281
f
apr_file_t * f
Definition
apr_buckets.h:927
rc
apr_redis_t * rc
Definition
apr_redis.h:173
size
apr_size_t size
Definition
apr_allocator.h:115
APR_SUCCESS
#define APR_SUCCESS
Definition
apr_errno.h:225
apr_status_t
int apr_status_t
Definition
apr_errno.h:44
type
int type
Definition
apr_file_io.h:798
APR_POLL_SOCKET
@ APR_POLL_SOCKET
Definition
apr_poll.h:93
APR_POLL_FILE
@ APR_POLL_FILE
Definition
apr_poll.h:94
s
const char * s
Definition
apr_strings.h:95
apr_wait_for_io_or_timeout
apr_status_t apr_wait_for_io_or_timeout(apr_file_t *f, apr_socket_t *s, int for_read)
status
int int status
Definition
apr_thread_proc.h:760
apr_interval_time_t
apr_int64_t apr_interval_time_t
Definition
apr_time.h:55
APR_POLLOUT
#define APR_POLLOUT
Definition
apr_poll.h:51
APR_POLLIN
#define APR_POLLIN
Definition
apr_poll.h:49
NULL
return NULL
Definition
mod_so.c:359
apr_file_t
Definition
apr_arch_file_io.h:97
apr_file_t::timeout
apr_interval_time_t timeout
Definition
apr_arch_file_io.h:104
apr_file_t::filedes
int filedes
Definition
apr_arch_file_io.h:99
apr_file_t::pollset
apr_pollset_t * pollset
Definition
apr_arch_file_io.h:110
apr_file_t::pool
apr_pool_t * pool
Definition
apr_arch_file_io.h:98
apr_pollfd_t
Definition
apr_poll.h:108
apr_pollfd_t::reqevents
apr_int16_t reqevents
Definition
apr_poll.h:111
apr_pollfd_t::desc_type
apr_datatype_e desc_type
Definition
apr_poll.h:110
apr_pollfd_t::desc
apr_descriptor desc
Definition
apr_poll.h:113
apr_pollset_t
Definition
apr_arch_poll_private.h:118
apr_pollset_t::pollset
int * pollset
Definition
pollset.c:29
apr_socket_t
Definition
apr_arch_networkio.h:37
pollfd
Definition
apr_arch_misc.h:467
pollset
static apr_pollset_t * pollset
Definition
testpoll.c:41
apr_descriptor::s
apr_socket_t * s
Definition
apr_poll.h:101
apr_descriptor::f
apr_file_t * f
Definition
apr_poll.h:100
POLLIN
#define POLLIN
Definition
apr_arch_networkio.h:88
POLLOUT
#define POLLOUT
Definition
apr_arch_networkio.h:90
timeout
IN ULONG IN INT timeout
Definition
apr_arch_misc.h:482
Generated by
1.9.8