Apache HTTPD
pollcb.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
31#if defined(HAVE_KQUEUE)
33#endif
34#if defined(HAVE_PORT_CREATE)
36#endif
37#if defined(HAVE_EPOLL)
39#endif
40#if defined(HAVE_POLL)
42#endif
43
45{
46 const apr_pollcb_provider_t *provider = NULL;
47 switch (method) {
49#if defined(HAVE_KQUEUE)
51#endif
52 break;
54#if defined(HAVE_PORT_CREATE)
55 provider = apr_pollcb_provider_port;
56#endif
57 break;
59#if defined(HAVE_EPOLL)
61#endif
62 break;
64#if defined(HAVE_POLL)
65 provider = apr_pollcb_provider_poll;
66#endif
67 break;
71 break;
72 }
73 return provider;
74}
75
89
95{
96 apr_status_t rv;
98 const apr_pollcb_provider_t *provider = NULL;
99
100 *ret_pollcb = NULL;
101
102 #ifdef WIN32
103 /* This will work only if ws2_32.dll has WSAPoll funtion.
104 * We could check the presence of the function here,
105 * but someone might implement other pollcb method in
106 * the future.
107 */
110 }
111 #endif
112
115 while (provider == NULL) {
116 provider = pollcb_provider(method);
117 if (!provider) {
119 return APR_ENOTIMPL;
121 return APR_ENOTIMPL;
123 }
124 }
125
127 /* Add room for wakeup descriptor */
128 size++;
129 }
130
131 pollcb = apr_palloc(p, sizeof(*pollcb));
132 pollcb->nelts = 0;
133 pollcb->nalloc = size;
134 pollcb->flags = flags;
135 pollcb->pool = p;
136 pollcb->provider = provider;
137
138 rv = (*provider->create)(pollcb, size, p, flags);
139 if (rv == APR_ENOTIMPL) {
141 return rv;
142 }
143
145 return rv;
146 }
147
148 /* Try with default provider */
150 if (!provider) {
151 return APR_ENOTIMPL;
152 }
153 rv = (*provider->create)(pollcb, size, p, flags);
154 if (rv != APR_SUCCESS) {
155 return rv;
156 }
157 pollcb->provider = provider;
158 }
159 else if (rv != APR_SUCCESS) {
160 return rv;
161 }
162
164 /* Create wakeup pipe */
167 != APR_SUCCESS) {
168 return rv;
169 }
170
172 return rv;
173 }
174 }
175 if ((flags & APR_POLLSET_WAKEABLE) || provider->cleanup)
178
180 return APR_SUCCESS;
181}
182
185 apr_pool_t *p,
187{
190}
191
194{
195 return (*pollcb->provider->add)(pollcb, descriptor);
196}
197
200{
201 return (*pollcb->provider->remove)(pollcb, descriptor);
202}
203
204
208 void *baton)
209{
210 return (*pollcb->provider->poll)(pollcb, timeout, func, baton);
211}
212
214{
216 return apr_file_putc(1, pollcb->wakeup_pipe[1]);
217 else
218 return APR_EINIT;
219}
220
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.
ap_vhost_iterate_conn_cb void * baton
Definition http_vhost.h:87
#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_status_t(* apr_pollcb_cb_t)(void *baton, apr_pollfd_t *descriptor)
Definition apr_poll.h:401
apr_uint32_t apr_pool_t apr_uint32_t apr_pollset_method_e method
Definition apr_poll.h:195
const apr_pollfd_t * descriptor
Definition apr_poll.h:230
apr_pollset_method_e
Definition apr_poll.h:80
apr_interval_time_t apr_pollcb_cb_t func
Definition apr_poll.h:422
@ 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
static apr_status_t pollcb_cleanup(void *p)
Definition pollcb.c:76
static apr_pollset_method_e pollset_default_method
Definition pollcb.c:30
static const apr_pollcb_provider_t * pollcb_provider(apr_pollset_method_e method)
Definition pollcb.c:44
apr_status_t(* remove)(apr_pollcb_t *, apr_pollfd_t *)
apr_status_t(* create)(apr_pollcb_t *, apr_uint32_t, apr_pool_t *, apr_uint32_t)
apr_status_t(* poll)(apr_pollcb_t *, apr_interval_time_t, apr_pollcb_cb_t, void *)
apr_status_t(* cleanup)(apr_pollcb_t *)
apr_status_t(* add)(apr_pollcb_t *, apr_pollfd_t *)
apr_file_t * wakeup_pipe[2]
apr_pollfd_t wakeup_pfd
const apr_pollcb_provider_t * provider
static apr_pollcb_t * pollcb
Definition testpoll.c:42
IN ULONG IN INT timeout