apr_arch_poll_private.h revision 269847
1263865Smarcel/* Licensed to the Apache Software Foundation (ASF) under one or more
2253923Smarcel * contributor license agreements.  See the NOTICE file distributed with
3253923Smarcel * this work for additional information regarding copyright ownership.
4253923Smarcel * The ASF licenses this file to You under the Apache License, Version 2.0
5253923Smarcel * (the "License"); you may not use this file except in compliance with
6253923Smarcel * the License.  You may obtain a copy of the License at
7253923Smarcel *
8253923Smarcel *     http://www.apache.org/licenses/LICENSE-2.0
9253923Smarcel *
10253923Smarcel * Unless required by applicable law or agreed to in writing, software
11253923Smarcel * distributed under the License is distributed on an "AS IS" BASIS,
12253923Smarcel * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13253923Smarcel * See the License for the specific language governing permissions and
14253923Smarcel * limitations under the License.
15253923Smarcel */
16253923Smarcel
17253923Smarcel#ifndef APR_ARCH_POLL_PRIVATE_H
18253923Smarcel#define APR_ARCH_POLL_PRIVATE_H
19253923Smarcel
20253923Smarcel#if HAVE_POLL_H
21253923Smarcel#include <poll.h>
22253923Smarcel#endif
23253923Smarcel
24253923Smarcel#if HAVE_SYS_POLL_H
25253923Smarcel#include <sys/poll.h>
26253923Smarcel#endif
27287122Smarcel
28253923Smarcel#ifdef HAVE_PORT_CREATE
29253923Smarcel#include <port.h>
30253923Smarcel#include <sys/port_impl.h>
31253923Smarcel#endif
32269177Smarcel
33253923Smarcel#ifdef HAVE_KQUEUE
34253923Smarcel#include <sys/types.h>
35263865Smarcel#include <sys/event.h>
36263865Smarcel#include <sys/time.h>
37263865Smarcel#endif
38263865Smarcel
39253923Smarcel#ifdef HAVE_EPOLL
40284523Smarcel#include <sys/epoll.h>
41268161Smarcel#endif
42253923Smarcel
43263865Smarcel#ifdef NETWARE
44269177Smarcel#define HAS_SOCKETS(dt) (dt == APR_POLL_SOCKET) ? 1 : 0
45284523Smarcel#define HAS_PIPES(dt) (dt == APR_POLL_FILE) ? 1 : 0
46272774Smarcel#endif
47272774Smarcel
48253923Smarcel#if defined(HAVE_AIO_H) && defined(HAVE_AIO_MSGQ)
49253923Smarcel#define _AIO_OS390	/* enable a bunch of z/OS aio.h definitions */
50253923Smarcel#include <aio.h>	/* aiocb	*/
51263865Smarcel#endif
52263865Smarcel
53263865Smarcel/* Choose the best method platform specific to use in apr_pollset */
54263865Smarcel#ifdef HAVE_KQUEUE
55263865Smarcel#define POLLSET_USES_KQUEUE
56263865Smarcel#define POLLSET_DEFAULT_METHOD APR_POLLSET_KQUEUE
57263865Smarcel#elif defined(HAVE_PORT_CREATE)
58263865Smarcel#define POLLSET_USES_PORT
59263865Smarcel#define POLLSET_DEFAULT_METHOD APR_POLLSET_PORT
60263865Smarcel#elif defined(HAVE_EPOLL)
61263865Smarcel#define POLLSET_USES_EPOLL
62268161Smarcel#define POLLSET_DEFAULT_METHOD APR_POLLSET_EPOLL
63268161Smarcel#elif defined(HAVE_AIO_MSGQ)
64268161Smarcel#define POLLSET_USES_AIO_MSGQ
65268161Smarcel#define POLLSET_DEFAULT_METHOD APR_POLLSET_AIO_MSGQ
66263865Smarcel#elif defined(HAVE_POLL)
67263865Smarcel#define POLLSET_USES_POLL
68263865Smarcel#define POLLSET_DEFAULT_METHOD APR_POLLSET_POLL
69263865Smarcel#else
70263865Smarcel#define POLLSET_USES_SELECT
71263865Smarcel#define POLLSET_DEFAULT_METHOD APR_POLLSET_SELECT
72263865Smarcel#endif
73263865Smarcel
74263865Smarcel#ifdef WIN32
75263865Smarcel#define POLL_USES_SELECT
76263865Smarcel#undef POLLSET_DEFAULT_METHOD
77263865Smarcel#define POLLSET_DEFAULT_METHOD APR_POLLSET_SELECT
78263865Smarcel#else
79263865Smarcel#ifdef HAVE_POLL
80263865Smarcel#define POLL_USES_POLL
81263865Smarcel#else
82263865Smarcel#define POLL_USES_SELECT
83263865Smarcel#endif
84263865Smarcel#endif
85263865Smarcel
86263865Smarcel#if defined(POLLSET_USES_KQUEUE) || defined(POLLSET_USES_EPOLL) || defined(POLLSET_USES_PORT) || defined(POLLSET_USES_AIO_MSGQ)
87263865Smarcel
88263865Smarcel#include "apr_ring.h"
89263865Smarcel
90263865Smarcel#if APR_HAS_THREADS
91263865Smarcel#include "apr_thread_mutex.h"
92263865Smarcel#define pollset_lock_rings() \
93263865Smarcel    if (pollset->flags & APR_POLLSET_THREADSAFE) \
94263865Smarcel        apr_thread_mutex_lock(pollset->p->ring_lock);
95263865Smarcel#define pollset_unlock_rings() \
96263865Smarcel    if (pollset->flags & APR_POLLSET_THREADSAFE) \
97263865Smarcel        apr_thread_mutex_unlock(pollset->p->ring_lock);
98263865Smarcel#else
99263865Smarcel#define pollset_lock_rings()
100263865Smarcel#define pollset_unlock_rings()
101263865Smarcel#endif
102263865Smarcel
103263865Smarceltypedef struct pfd_elem_t pfd_elem_t;
104263865Smarcel
105263865Smarcelstruct pfd_elem_t {
106263865Smarcel    APR_RING_ENTRY(pfd_elem_t) link;
107263865Smarcel    apr_pollfd_t pfd;
108263865Smarcel#ifdef HAVE_PORT_CREATE
109263865Smarcel   int on_query_ring;
110263865Smarcel#endif
111284523Smarcel};
112284523Smarcel
113284523Smarcel#endif
114284523Smarcel
115284523Smarceltypedef struct apr_pollset_private_t apr_pollset_private_t;
116284523Smarceltypedef struct apr_pollset_provider_t apr_pollset_provider_t;
117284523Smarceltypedef struct apr_pollcb_provider_t apr_pollcb_provider_t;
118284523Smarcel
119284523Smarcelstruct apr_pollset_t
120284523Smarcel{
121284523Smarcel    apr_pool_t *pool;
122284523Smarcel    apr_uint32_t nelts;
123284523Smarcel    apr_uint32_t nalloc;
124284523Smarcel    apr_uint32_t flags;
125284523Smarcel    /* Pipe descriptors used for wakeup */
126284523Smarcel    apr_file_t *wakeup_pipe[2];
127284523Smarcel    apr_pollfd_t wakeup_pfd;
128263865Smarcel    apr_pollset_private_t *p;
129263865Smarcel    apr_pollset_provider_t *provider;
130263865Smarcel};
131263895Smarcel
132269177Smarceltypedef union {
133284523Smarcel#if defined(HAVE_EPOLL)
134269177Smarcel    struct epoll_event *epoll;
135269177Smarcel#endif
136269177Smarcel#if defined(HAVE_PORT_CREATE)
137269177Smarcel    port_event_t *port;
138269177Smarcel#endif
139269177Smarcel#if defined(HAVE_KQUEUE)
140269177Smarcel    struct kevent *ke;
141269177Smarcel#endif
142272774Smarcel#if defined(HAVE_POLL)
143263895Smarcel    struct pollfd *ps;
144287122Smarcel#endif
145272774Smarcel    void *undef;
146272774Smarcel} apr_pollcb_pset;
147272774Smarcel
148272774Smarcelstruct apr_pollcb_t {
149272774Smarcel    apr_pool_t *pool;
150272774Smarcel    apr_uint32_t nelts;
151272774Smarcel    apr_uint32_t nalloc;
152272774Smarcel    int fd;
153272774Smarcel    apr_pollcb_pset pollset;
154272774Smarcel    apr_pollfd_t **copyset;
155272774Smarcel    apr_pollcb_provider_t *provider;
156272774Smarcel};
157272774Smarcel
158272774Smarcelstruct apr_pollset_provider_t {
159272774Smarcel    apr_status_t (*create)(apr_pollset_t *, apr_uint32_t, apr_pool_t *, apr_uint32_t);
160272774Smarcel    apr_status_t (*add)(apr_pollset_t *, const apr_pollfd_t *);
161272774Smarcel    apr_status_t (*remove)(apr_pollset_t *, const apr_pollfd_t *);
162272774Smarcel    apr_status_t (*poll)(apr_pollset_t *, apr_interval_time_t, apr_int32_t *, const apr_pollfd_t **);
163272774Smarcel    apr_status_t (*cleanup)(apr_pollset_t *);
164272774Smarcel    const char *name;
165272774Smarcel};
166263895Smarcel
167272774Smarcelstruct apr_pollcb_provider_t {
168287122Smarcel    apr_status_t (*create)(apr_pollcb_t *, apr_uint32_t, apr_pool_t *, apr_uint32_t);
169287122Smarcel    apr_status_t (*add)(apr_pollcb_t *, apr_pollfd_t *);
170287122Smarcel    apr_status_t (*remove)(apr_pollcb_t *, apr_pollfd_t *);
171287122Smarcel    apr_status_t (*poll)(apr_pollcb_t *, apr_interval_time_t, apr_pollcb_cb_t, void *);
172287122Smarcel    const char *name;
173287122Smarcel};
174287122Smarcel
175287122Smarcel/* Private functions */
176287122Smarcelvoid apr_pollset_drain_wakeup_pipe(apr_pollset_t *pollset);
177287122Smarcel
178287122Smarcel#endif /* APR_ARCH_POLL_PRIVATE_H */
179287122Smarcel