Apache2
apr_arch_poll_private.h
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 #ifndef APR_ARCH_POLL_PRIVATE_H
18 #define APR_ARCH_POLL_PRIVATE_H
19 
20 #if HAVE_POLL_H
21 #include <poll.h>
22 #elif HAVE_SYS_POLL_H
23 #include <sys/poll.h>
24 #endif
25 
26 #ifdef HAVE_PORT_CREATE
27 #include <port.h>
28 #include <sys/port_impl.h>
29 #endif
30 
31 #ifdef HAVE_KQUEUE
32 #include <sys/types.h>
33 #include <sys/event.h>
34 #include <sys/time.h>
35 #endif
36 
37 #ifdef HAVE_EPOLL
38 #include <sys/epoll.h>
39 #endif
40 
41 #ifdef NETWARE
42 #define HAS_SOCKETS(dt) (dt == APR_POLL_SOCKET) ? 1 : 0
43 #define HAS_PIPES(dt) (dt == APR_POLL_FILE) ? 1 : 0
44 #endif
45 
46 #if defined(HAVE_AIO_H) && defined(HAVE_AIO_MSGQ)
47 #define _AIO_OS390 /* enable a bunch of z/OS aio.h definitions */
48 #include <aio.h> /* aiocb */
49 #endif
50 
51 /* Choose the best method platform specific to use in apr_pollset */
52 #ifdef HAVE_KQUEUE
53 #define POLLSET_USES_KQUEUE
54 #define POLLSET_DEFAULT_METHOD APR_POLLSET_KQUEUE
55 #elif defined(HAVE_PORT_CREATE)
56 #define POLLSET_USES_PORT
57 #define POLLSET_DEFAULT_METHOD APR_POLLSET_PORT
58 #elif defined(HAVE_EPOLL)
59 #define POLLSET_USES_EPOLL
60 #define POLLSET_DEFAULT_METHOD APR_POLLSET_EPOLL
61 #elif defined(HAVE_AIO_MSGQ)
62 #define POLLSET_USES_AIO_MSGQ
63 #define POLLSET_DEFAULT_METHOD APR_POLLSET_AIO_MSGQ
64 #elif defined(HAVE_POLL)
65 #define POLLSET_USES_POLL
66 #define POLLSET_DEFAULT_METHOD APR_POLLSET_POLL
67 #else
68 #define POLLSET_USES_SELECT
69 #define POLLSET_DEFAULT_METHOD APR_POLLSET_SELECT
70 #endif
71 
72 #ifdef WIN32
73 #define POLL_USES_SELECT
74 #undef POLLSET_DEFAULT_METHOD
75 #define POLLSET_DEFAULT_METHOD APR_POLLSET_SELECT
76 #else
77 #ifdef HAVE_POLL
78 #define POLL_USES_POLL
79 #else
80 #define POLL_USES_SELECT
81 #endif
82 #endif
83 
84 #ifdef WIN32
85 #define WAKEUP_USES_PIPE 0
86 #else
87 #define WAKEUP_USES_PIPE 1
88 #endif
89 
90 #if defined(POLLSET_USES_KQUEUE) || defined(POLLSET_USES_EPOLL) || defined(POLLSET_USES_PORT) || defined(POLLSET_USES_AIO_MSGQ)
91 
92 #include "apr_ring.h"
93 
94 #if APR_HAS_THREADS
95 #include "apr_thread_mutex.h"
96 #define pollset_lock_rings() \
97  if (pollset->flags & APR_POLLSET_THREADSAFE) \
98  apr_thread_mutex_lock(pollset->p->ring_lock);
99 #define pollset_unlock_rings() \
100  if (pollset->flags & APR_POLLSET_THREADSAFE) \
101  apr_thread_mutex_unlock(pollset->p->ring_lock);
102 #else
103 #define pollset_lock_rings()
104 #define pollset_unlock_rings()
105 #endif
106 
107 typedef struct pfd_elem_t pfd_elem_t;
108 
109 struct pfd_elem_t {
110  APR_RING_ENTRY(pfd_elem_t) link;
111  apr_pollfd_t pfd;
112 #ifdef HAVE_PORT_CREATE
113  int on_query_ring;
114 #endif
115 };
116 
117 #endif
118 
122 
124 {
129  /* Pipe descriptors used for wakeup */
130 #if WAKEUP_USES_PIPE
132 #else
133  apr_socket_t *wakeup_socket[2];
134 #endif
139 };
140 
141 typedef union {
142 #if defined(HAVE_EPOLL)
143  struct epoll_event *epoll;
144 #endif
145 #if defined(HAVE_PORT_CREATE)
146  port_event_t *port;
147 #endif
148 #if defined(HAVE_KQUEUE)
149  struct kevent *ke;
150 #endif
151 #if defined(HAVE_POLL)
152  struct pollfd *ps;
153 #endif
154  void *undef;
156 
157 struct apr_pollcb_t {
162  /* Pipe descriptors used for wakeup */
163 #if WAKEUP_USES_PIPE
165 #else
166  apr_socket_t *wakeup_socket[2];
167 #endif
170  int fd;
174 };
175 
182  const char *name;
183 };
184 
191  const char *name;
192 };
193 
194 /*
195  * Private functions used for the implementation of both apr_pollcb_* and
196  * apr_pollset_*
197  */
198 #if WAKEUP_USES_PIPE
200  apr_file_t **wakeup_pipe);
202 void apr_poll_drain_wakeup_pipe(volatile apr_uint32_t *wakeup_set, apr_file_t **wakeup_pipe);
203 #else
204 apr_status_t apr_poll_create_wakeup_socket(apr_pool_t *pool, apr_pollfd_t *pfd,
205  apr_socket_t **wakeup_socket);
206 apr_status_t apr_poll_close_wakeup_socket(apr_socket_t **wakeup_socket);
207 void apr_poll_drain_wakeup_socket(volatile apr_uint32_t *wakeup_set, apr_socket_t **wakeup_socket);
208 #endif
209 
210 #endif /* APR_ARCH_POLL_PRIVATE_H */
apr_status_t apr_poll_create_wakeup_pipe(apr_pool_t *pool, apr_pollfd_t *pfd, apr_file_t **wakeup_pipe)
struct apr_pollset_private_t apr_pollset_private_t
Definition: apr_arch_poll_private.h:119
void apr_poll_drain_wakeup_pipe(volatile apr_uint32_t *wakeup_set, apr_file_t **wakeup_pipe)
apr_status_t apr_poll_close_wakeup_pipe(apr_file_t **wakeup_pipe)
APR Rings.
APR Thread Mutex Routines.
apr_bucket_brigade request_rec apr_pool_t * pool
Definition: mod_dav.h:557
int apr_status_t
Definition: apr_errno.h:44
int apr_int32_t
Definition: apr.h:347
unsigned int apr_uint32_t
Definition: apr.h:348
apr_status_t(* apr_pollcb_cb_t)(void *baton, apr_pollfd_t *descriptor)
Definition: apr_poll.h:402
struct apr_pool_t apr_pool_t
Definition: apr_pools.h:60
#define APR_RING_ENTRY(elem)
Definition: apr_ring.h:70
apr_int64_t apr_interval_time_t
Definition: apr_time.h:55
Definition: apr_arch_file_io.h:107
Definition: apr_arch_poll_private.h:185
apr_status_t(* remove)(apr_pollcb_t *, apr_pollfd_t *)
Definition: apr_arch_poll_private.h:188
apr_status_t(* create)(apr_pollcb_t *, apr_uint32_t, apr_pool_t *, apr_uint32_t)
Definition: apr_arch_poll_private.h:186
apr_status_t(* poll)(apr_pollcb_t *, apr_interval_time_t, apr_pollcb_cb_t, void *)
Definition: apr_arch_poll_private.h:189
apr_status_t(* cleanup)(apr_pollcb_t *)
Definition: apr_arch_poll_private.h:190
const char * name
Definition: apr_arch_poll_private.h:191
apr_status_t(* add)(apr_pollcb_t *, apr_pollfd_t *)
Definition: apr_arch_poll_private.h:187
Definition: apr_arch_poll_private.h:157
apr_uint32_t flags
Definition: apr_arch_poll_private.h:161
volatile apr_uint32_t wakeup_set
Definition: apr_arch_poll_private.h:169
apr_file_t * wakeup_pipe[2]
Definition: apr_arch_poll_private.h:164
int fd
Definition: apr_arch_poll_private.h:170
apr_pollfd_t wakeup_pfd
Definition: apr_arch_poll_private.h:168
const apr_pollcb_provider_t * provider
Definition: apr_arch_poll_private.h:173
apr_pollcb_pset pollset
Definition: apr_arch_poll_private.h:171
apr_uint32_t nalloc
Definition: apr_arch_poll_private.h:160
apr_pool_t * pool
Definition: apr_arch_poll_private.h:158
apr_uint32_t nelts
Definition: apr_arch_poll_private.h:159
apr_pollfd_t ** copyset
Definition: apr_arch_poll_private.h:172
Definition: apr_poll.h:109
Definition: apr_arch_poll_private.h:176
apr_status_t(* add)(apr_pollset_t *, const apr_pollfd_t *)
Definition: apr_arch_poll_private.h:178
apr_status_t(* poll)(apr_pollset_t *, apr_interval_time_t, apr_int32_t *, const apr_pollfd_t **)
Definition: apr_arch_poll_private.h:180
const char * name
Definition: apr_arch_poll_private.h:182
apr_status_t(* cleanup)(apr_pollset_t *)
Definition: apr_arch_poll_private.h:181
apr_status_t(* remove)(apr_pollset_t *, const apr_pollfd_t *)
Definition: apr_arch_poll_private.h:179
apr_status_t(* create)(apr_pollset_t *, apr_uint32_t, apr_pool_t *, apr_uint32_t)
Definition: apr_arch_poll_private.h:177
Definition: apr_arch_poll_private.h:124
apr_uint32_t nalloc
Definition: apr_arch_poll_private.h:127
apr_file_t * wakeup_pipe[2]
Definition: apr_arch_poll_private.h:131
const apr_pollset_provider_t * provider
Definition: apr_arch_poll_private.h:138
apr_pollset_private_t * p
Definition: apr_arch_poll_private.h:137
apr_uint32_t flags
Definition: apr_arch_poll_private.h:128
apr_pool_t * pool
Definition: apr_arch_poll_private.h:125
apr_pollfd_t wakeup_pfd
Definition: apr_arch_poll_private.h:135
volatile apr_uint32_t wakeup_set
Definition: apr_arch_poll_private.h:136
apr_uint32_t nelts
Definition: apr_arch_poll_private.h:126
Definition: apr_arch_networkio.h:37
Definition: apr_arch_poll_private.h:141
void * undef
Definition: apr_arch_poll_private.h:154