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 /* Choose the best method platform specific to use in apr_pollset */
50 #define POLLSET_USES_KQUEUE
51 #define POLLSET_DEFAULT_METHOD APR_POLLSET_KQUEUE
52 #elif defined(HAVE_PORT_CREATE)
53 #define POLLSET_USES_PORT
54 #define POLLSET_DEFAULT_METHOD APR_POLLSET_PORT
55 #elif defined(HAVE_EPOLL)
56 #define POLLSET_USES_EPOLL
57 #define POLLSET_DEFAULT_METHOD APR_POLLSET_EPOLL
58 #elif defined(HAVE_POLL)
59 #define POLLSET_USES_POLL
60 #define POLLSET_DEFAULT_METHOD APR_POLLSET_POLL
62 #define POLLSET_USES_SELECT
63 #define POLLSET_DEFAULT_METHOD APR_POLLSET_SELECT
67 #define POLL_USES_SELECT
68 #undef POLLSET_DEFAULT_METHOD
69 #define POLLSET_DEFAULT_METHOD APR_POLLSET_SELECT
72 #define POLL_USES_POLL
74 #define POLL_USES_SELECT
78 #if defined(POLLSET_USES_KQUEUE) || defined(POLLSET_USES_EPOLL) || defined(POLLSET_USES_PORT)
83 #include "apr_thread_mutex.h"
84 #define pollset_lock_rings() \
85 if (pollset->flags & APR_POLLSET_THREADSAFE) \
86 apr_thread_mutex_lock(pollset->p->ring_lock);
87 #define pollset_unlock_rings() \
88 if (pollset->flags & APR_POLLSET_THREADSAFE) \
89 apr_thread_mutex_unlock(pollset->p->ring_lock);
91 #define pollset_lock_rings()
92 #define pollset_unlock_rings()
95 typedef struct pfd_elem_t pfd_elem_t;
98 APR_RING_ENTRY(pfd_elem_t) link;
100 #ifdef HAVE_PORT_CREATE
107 typedef struct apr_pollset_private_t apr_pollset_private_t;
108 typedef struct apr_pollset_provider_t apr_pollset_provider_t;
109 typedef struct apr_pollcb_provider_t apr_pollcb_provider_t;
116 /* Pipe descriptors used for wakeup */
117 apr_file_t *wakeup_pipe[2];
118 apr_pollfd_t wakeup_pfd;
119 apr_pollset_private_t *p;
120 apr_pollset_provider_t *provider;
124 #if defined(HAVE_EPOLL)
125 struct epoll_event *epoll;
127 #if defined(HAVE_PORT_CREATE)
130 #if defined(HAVE_KQUEUE)
133 #if defined(HAVE_POLL)
139 struct apr_pollcb_t {
144 apr_pollcb_pset pollset;
145 apr_pollfd_t **copyset;
146 apr_pollcb_provider_t *provider;
149 struct apr_pollset_provider_t {
150 apr_status_t (*create)(apr_pollset_t *, apr_uint32_t, apr_pool_t *, apr_uint32_t);
151 apr_status_t (*add)(apr_pollset_t *, const apr_pollfd_t *);
152 apr_status_t (*remove)(apr_pollset_t *, const apr_pollfd_t *);
153 apr_status_t (*poll)(apr_pollset_t *, apr_interval_time_t, apr_int32_t *, const apr_pollfd_t **);
154 apr_status_t (*cleanup)(apr_pollset_t *);
158 struct apr_pollcb_provider_t {
159 apr_status_t (*create)(apr_pollcb_t *, apr_uint32_t, apr_pool_t *, apr_uint32_t);
160 apr_status_t (*add)(apr_pollcb_t *, apr_pollfd_t *);
161 apr_status_t (*remove)(apr_pollcb_t *, apr_pollfd_t *);
162 apr_status_t (*poll)(apr_pollcb_t *, apr_interval_time_t, apr_pollcb_cb_t, void *);
166 /* Private functions */
167 void apr_pollset_drain_wakeup_pipe(apr_pollset_t *pollset);
169 #endif /* APR_ARCH_POLL_PRIVATE_H */