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
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 #ifndef APR_ARCH_POLL_PRIVATE_H
18 #define APR_ARCH_POLL_PRIVATE_H
28 #ifdef HAVE_PORT_CREATE
30 #include <sys/port_impl.h>
34 #include <sys/types.h>
35 #include <sys/event.h>
40 #include <sys/epoll.h>
44 #define HAS_SOCKETS(dt) (dt == APR_POLL_SOCKET) ? 1 : 0
45 #define HAS_PIPES(dt) (dt == APR_POLL_FILE) ? 1 : 0
48 #if defined(HAVE_AIO_H) && defined(HAVE_AIO_MSGQ)
49 #define _AIO_OS390 /* enable a bunch of z/OS aio.h definitions */
50 #include <aio.h> /* aiocb */
53 /* Choose the best method platform specific to use in apr_pollset */
55 #define POLLSET_USES_KQUEUE
56 #define POLLSET_DEFAULT_METHOD APR_POLLSET_KQUEUE
57 #elif defined(HAVE_PORT_CREATE)
58 #define POLLSET_USES_PORT
59 #define POLLSET_DEFAULT_METHOD APR_POLLSET_PORT
60 #elif defined(HAVE_EPOLL)
61 #define POLLSET_USES_EPOLL
62 #define POLLSET_DEFAULT_METHOD APR_POLLSET_EPOLL
63 #elif defined(HAVE_AIO_MSGQ)
64 #define POLLSET_USES_AIO_MSGQ
65 #define POLLSET_DEFAULT_METHOD APR_POLLSET_AIO_MSGQ
66 #elif defined(HAVE_POLL)
67 #define POLLSET_USES_POLL
68 #define POLLSET_DEFAULT_METHOD APR_POLLSET_POLL
70 #define POLLSET_USES_SELECT
71 #define POLLSET_DEFAULT_METHOD APR_POLLSET_SELECT
75 #define POLL_USES_SELECT
76 #undef POLLSET_DEFAULT_METHOD
77 #define POLLSET_DEFAULT_METHOD APR_POLLSET_SELECT
80 #define POLL_USES_POLL
82 #define POLL_USES_SELECT
86 #if defined(POLLSET_USES_KQUEUE) || defined(POLLSET_USES_EPOLL) || defined(POLLSET_USES_PORT) || defined(POLLSET_USES_AIO_MSGQ)
91 #include "apr_thread_mutex.h"
92 #define pollset_lock_rings() \
93 if (pollset->flags & APR_POLLSET_THREADSAFE) \
94 apr_thread_mutex_lock(pollset->p->ring_lock);
95 #define pollset_unlock_rings() \
96 if (pollset->flags & APR_POLLSET_THREADSAFE) \
97 apr_thread_mutex_unlock(pollset->p->ring_lock);
99 #define pollset_lock_rings()
100 #define pollset_unlock_rings()
103 typedef struct pfd_elem_t pfd_elem_t;
106 APR_RING_ENTRY(pfd_elem_t) link;
108 #ifdef HAVE_PORT_CREATE
115 typedef struct apr_pollset_private_t apr_pollset_private_t;
116 typedef struct apr_pollset_provider_t apr_pollset_provider_t;
117 typedef struct apr_pollcb_provider_t apr_pollcb_provider_t;
125 /* Pipe descriptors used for wakeup */
126 apr_file_t *wakeup_pipe[2];
127 apr_pollfd_t wakeup_pfd;
128 apr_pollset_private_t *p;
129 apr_pollset_provider_t *provider;
133 #if defined(HAVE_EPOLL)
134 struct epoll_event *epoll;
136 #if defined(HAVE_PORT_CREATE)
139 #if defined(HAVE_KQUEUE)
142 #if defined(HAVE_POLL)
148 struct apr_pollcb_t {
153 apr_pollcb_pset pollset;
154 apr_pollfd_t **copyset;
155 apr_pollcb_provider_t *provider;
158 struct apr_pollset_provider_t {
159 apr_status_t (*create)(apr_pollset_t *, apr_uint32_t, apr_pool_t *, apr_uint32_t);
160 apr_status_t (*add)(apr_pollset_t *, const apr_pollfd_t *);
161 apr_status_t (*remove)(apr_pollset_t *, const apr_pollfd_t *);
162 apr_status_t (*poll)(apr_pollset_t *, apr_interval_time_t, apr_int32_t *, const apr_pollfd_t **);
163 apr_status_t (*cleanup)(apr_pollset_t *);
167 struct apr_pollcb_provider_t {
168 apr_status_t (*create)(apr_pollcb_t *, apr_uint32_t, apr_pool_t *, apr_uint32_t);
169 apr_status_t (*add)(apr_pollcb_t *, apr_pollfd_t *);
170 apr_status_t (*remove)(apr_pollcb_t *, apr_pollfd_t *);
171 apr_status_t (*poll)(apr_pollcb_t *, apr_interval_time_t, apr_pollcb_cb_t, void *);
175 /* Private functions */
176 void apr_pollset_drain_wakeup_pipe(apr_pollset_t *pollset);
178 #endif /* APR_ARCH_POLL_PRIVATE_H */