Apache HTTPD
pollset.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#ifdef WIN32
18/* POSIX defines 1024 for the FD_SETSIZE */
19#define FD_SETSIZE 1024
20#endif
21
22#include "apr.h"
23#include "apr_poll.h"
24#include "apr_time.h"
25#include "apr_portable.h"
26#include "apr_arch_file_io.h"
27#include "apr_arch_networkio.h"
29#include "apr_arch_inherit.h"
30
32
45
46#if defined(HAVE_KQUEUE)
48#endif
49#if defined(HAVE_PORT_CREATE)
51#endif
52#if defined(HAVE_EPOLL)
54#endif
55#if defined(HAVE_AIO_MSGQ)
57#endif
58#if defined(HAVE_POLL)
60#endif
62
64{
65 const apr_pollset_provider_t *provider = NULL;
66 switch (method) {
68#if defined(HAVE_KQUEUE)
70#endif
71 break;
73#if defined(HAVE_PORT_CREATE)
75#endif
76 break;
78#if defined(HAVE_EPOLL)
80#endif
81 break;
83#if defined(HAVE_AIO_MSGQ)
85#endif
86 break;
88#if defined(HAVE_POLL)
90#endif
91 break;
94 break;
96 break;
97 }
98 return provider;
99}
100
103 apr_pool_t *p,
106{
107 apr_status_t rv;
109 const apr_pollset_provider_t *provider = NULL;
110
111 *ret_pollset = NULL;
112
113 #ifdef WIN32
114 /* Favor WSAPoll if supported.
115 * This will work only if ws2_32.dll has WSAPoll funtion.
116 * In other cases it will fall back to select() method unless
117 * the APR_POLLSET_NODEFAULT is added to the flags.
118 */
121 }
122 #endif
123
126 while (provider == NULL) {
127 provider = pollset_provider(method);
128 if (!provider) {
130 return APR_ENOTIMPL;
132 return APR_ENOTIMPL;
134 }
135 }
137 /* Add room for wakeup descriptor */
138 size++;
139 }
140
141 pollset = apr_palloc(p, sizeof(*pollset));
142 pollset->nelts = 0;
144 pollset->pool = p;
146 pollset->provider = provider;
147
148 rv = (*provider->create)(pollset, size, p, flags);
149 if (rv == APR_ENOTIMPL) {
151 return rv;
152 }
154 if (!provider) {
155 return APR_ENOTIMPL;
156 }
157 rv = (*provider->create)(pollset, size, p, flags);
158 if (rv != APR_SUCCESS) {
159 return rv;
160 }
161 pollset->provider = provider;
162 }
163 else if (rv != APR_SUCCESS) {
164 return rv;
165 }
167 /* Create wakeup pipe */
170 != APR_SUCCESS) {
171 return rv;
172 }
173
175 return rv;
176 }
177 }
178 if ((flags & APR_POLLSET_WAKEABLE) || provider->cleanup)
181
183 return APR_SUCCESS;
184}
185
190
191APR_DECLARE(const char *) apr_poll_method_defname(void)
192{
193 const apr_pollset_provider_t *provider = NULL;
194
196 if (provider)
197 return provider->name;
198 else
199 return "unknown";
200}
201
204 apr_pool_t *p,
206{
209}
210
212{
217 else
218 return APR_SUCCESS;
219}
220
222{
224 return apr_file_putc(1, pollset->wakeup_pipe[1]);
225 else
226 return APR_EINIT;
227}
228
231{
232 return (*pollset->provider->add)(pollset, descriptor);
233}
234
237{
239}
240
245{
247}
apr_status_t apr_poll_create_wakeup_pipe(apr_pool_t *pool, apr_pollfd_t *pfd, apr_file_t **wakeup_pipe)
#define POLLSET_DEFAULT_METHOD
apr_status_t apr_poll_close_wakeup_pipe(apr_file_t **wakeup_pipe)
Definition wakeup.c:69
APR Poll interface.
APR Portability Routines.
APR Time Library.
#define APR_ENOTIMPL
Definition apr_errno.h:476
#define APR_EINIT
Definition apr_errno.h:474
const char apr_ssize_t int flags
Definition apr_encode.h:168
const void apr_status_t(*) apr_status_t(* APR_DECLARE)(void) apr_pool_pre_cleanup_register(apr_pool_t *p
Definition apr_pools.h:646
apr_size_t size
#define APR_SUCCESS
Definition apr_errno.h:225
int apr_status_t
Definition apr_errno.h:44
apr_uint32_t apr_pool_t apr_uint32_t apr_pollset_method_e method
Definition apr_poll.h:195
apr_interval_time_t apr_int32_t const apr_pollfd_t ** descriptors
Definition apr_poll.h:274
apr_interval_time_t apr_int32_t * num
Definition apr_poll.h:273
const apr_pollfd_t * descriptor
Definition apr_poll.h:230
apr_pollset_method_e
Definition apr_poll.h:80
@ APR_POLLSET_EPOLL
Definition apr_poll.h:85
@ APR_POLLSET_KQUEUE
Definition apr_poll.h:83
@ APR_POLLSET_SELECT
Definition apr_poll.h:82
@ APR_POLLSET_POLL
Definition apr_poll.h:86
@ APR_POLLSET_AIO_MSGQ
Definition apr_poll.h:87
@ APR_POLLSET_DEFAULT
Definition apr_poll.h:81
@ APR_POLLSET_PORT
Definition apr_poll.h:84
apr_int64_t apr_interval_time_t
Definition apr_time.h:55
#define APR_POLLSET_WAKEABLE
Definition apr_poll.h:68
#define APR_POLLSET_NODEFAULT
Definition apr_poll.h:71
apr_pool_t * p
Definition md_event.c:32
return NULL
Definition mod_so.c:359
apr_status_t(* add)(apr_pollset_t *, const apr_pollfd_t *)
apr_status_t(* poll)(apr_pollset_t *, apr_interval_time_t, apr_int32_t *, const apr_pollfd_t **)
apr_status_t(* cleanup)(apr_pollset_t *)
apr_status_t(* remove)(apr_pollset_t *, const apr_pollfd_t *)
apr_status_t(* create)(apr_pollset_t *, apr_uint32_t, apr_pool_t *, apr_uint32_t)
apr_file_t * wakeup_pipe[2]
const apr_pollset_provider_t * provider
static apr_pollset_t * pollset
Definition testpoll.c:41
static apr_pollset_method_e pollset_default_method
Definition pollset.c:31
static const apr_pollset_provider_t * pollset_provider(apr_pollset_method_e method)
Definition pollset.c:63
static apr_status_t pollset_cleanup(void *p)
Definition pollset.c:33
const apr_pollset_provider_t * apr_pollset_provider_select
Definition select.c:449
IN ULONG IN INT timeout