GME
13
|
00001 /* Licensed to the Apache Software Foundation (ASF) under one or more 00002 * contributor license agreements. See the NOTICE file distributed with 00003 * this work for additional information regarding copyright ownership. 00004 * The ASF licenses this file to You under the Apache License, Version 2.0 00005 * (the "License"); you may not use this file except in compliance with 00006 * the License. You may obtain a copy of the License at 00007 * 00008 * http://www.apache.org/licenses/LICENSE-2.0 00009 * 00010 * Unless required by applicable law or agreed to in writing, software 00011 * distributed under the License is distributed on an "AS IS" BASIS, 00012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00013 * See the License for the specific language governing permissions and 00014 * limitations under the License. 00015 */ 00016 00017 #ifndef APR_ARCH_POLL_PRIVATE_H 00018 #define APR_ARCH_POLL_PRIVATE_H 00019 00020 #if HAVE_POLL_H 00021 #include <poll.h> 00022 #endif 00023 00024 #if HAVE_SYS_POLL_H 00025 #include <sys/poll.h> 00026 #endif 00027 00028 #ifdef HAVE_PORT_CREATE 00029 #include <port.h> 00030 #include <sys/port_impl.h> 00031 #endif 00032 00033 #ifdef HAVE_KQUEUE 00034 #include <sys/types.h> 00035 #include <sys/event.h> 00036 #include <sys/time.h> 00037 #endif 00038 00039 #ifdef HAVE_EPOLL 00040 #include <sys/epoll.h> 00041 #endif 00042 00043 #ifdef NETWARE 00044 #define HAS_SOCKETS(dt) (dt == APR_POLL_SOCKET) ? 1 : 0 00045 #define HAS_PIPES(dt) (dt == APR_POLL_FILE) ? 1 : 0 00046 #endif 00047 00048 /* Choose the best method platform specific to use in apr_pollset */ 00049 #ifdef HAVE_KQUEUE 00050 #define POLLSET_USES_KQUEUE 00051 #define POLLSET_DEFAULT_METHOD APR_POLLSET_KQUEUE 00052 #elif defined(HAVE_PORT_CREATE) 00053 #define POLLSET_USES_PORT 00054 #define POLLSET_DEFAULT_METHOD APR_POLLSET_PORT 00055 #elif defined(HAVE_EPOLL) 00056 #define POLLSET_USES_EPOLL 00057 #define POLLSET_DEFAULT_METHOD APR_POLLSET_EPOLL 00058 #elif defined(HAVE_POLL) 00059 #define POLLSET_USES_POLL 00060 #define POLLSET_DEFAULT_METHOD APR_POLLSET_POLL 00061 #else 00062 #define POLLSET_USES_SELECT 00063 #define POLLSET_DEFAULT_METHOD APR_POLLSET_SELECT 00064 #endif 00065 00066 #ifdef WIN32 00067 #define POLL_USES_SELECT 00068 #undef POLLSET_DEFAULT_METHOD 00069 #define POLLSET_DEFAULT_METHOD APR_POLLSET_SELECT 00070 #else 00071 #ifdef HAVE_POLL 00072 #define POLL_USES_POLL 00073 #else 00074 #define POLL_USES_SELECT 00075 #endif 00076 #endif 00077 00078 #if defined(POLLSET_USES_KQUEUE) || defined(POLLSET_USES_EPOLL) || defined(POLLSET_USES_PORT) 00079 00080 #include "apr_ring.h" 00081 00082 #if APR_HAS_THREADS 00083 #include "apr_thread_mutex.h" 00084 #define pollset_lock_rings() \ 00085 if (pollset->flags & APR_POLLSET_THREADSAFE) \ 00086 apr_thread_mutex_lock(pollset->p->ring_lock); 00087 #define pollset_unlock_rings() \ 00088 if (pollset->flags & APR_POLLSET_THREADSAFE) \ 00089 apr_thread_mutex_unlock(pollset->p->ring_lock); 00090 #else 00091 #define pollset_lock_rings() 00092 #define pollset_unlock_rings() 00093 #endif 00094 00095 typedef struct pfd_elem_t pfd_elem_t; 00096 00097 struct pfd_elem_t { 00098 APR_RING_ENTRY(pfd_elem_t) link; 00099 apr_pollfd_t pfd; 00100 #ifdef HAVE_PORT_CREATE 00101 int on_query_ring; 00102 #endif 00103 }; 00104 00105 #endif 00106 00107 typedef struct apr_pollset_private_t apr_pollset_private_t; 00108 typedef struct apr_pollset_provider_t apr_pollset_provider_t; 00109 typedef struct apr_pollcb_provider_t apr_pollcb_provider_t; 00110 struct apr_pollset_t 00111 { 00112 apr_pool_t *pool; 00113 apr_uint32_t nelts; 00114 apr_uint32_t nalloc; 00115 apr_uint32_t flags; 00116 /* Pipe descriptors used for wakeup */ 00117 apr_file_t *wakeup_pipe[2]; 00118 apr_pollfd_t wakeup_pfd; 00119 apr_pollset_private_t *p; 00120 apr_pollset_provider_t *provider; 00121 }; 00122 00123 typedef union { 00124 #if defined(HAVE_EPOLL) 00125 struct epoll_event *epoll; 00126 #endif 00127 #if defined(HAVE_PORT_CREATE) 00128 port_event_t *port; 00129 #endif 00130 #if defined(HAVE_KQUEUE) 00131 struct kevent *ke; 00132 #endif 00133 #if defined(HAVE_POLL) 00134 struct pollfd *ps; 00135 #endif 00136 void *undef; 00137 } apr_pollcb_pset; 00138 00139 struct apr_pollcb_t { 00140 apr_pool_t *pool; 00141 apr_uint32_t nelts; 00142 apr_uint32_t nalloc; 00143 int fd; 00144 apr_pollcb_pset pollset; 00145 apr_pollfd_t **copyset; 00146 apr_pollcb_provider_t *provider; 00147 }; 00148 00149 struct apr_pollset_provider_t { 00150 apr_status_t (*create)(apr_pollset_t *, apr_uint32_t, apr_pool_t *, apr_uint32_t); 00151 apr_status_t (*add)(apr_pollset_t *, const apr_pollfd_t *); 00152 apr_status_t (*remove)(apr_pollset_t *, const apr_pollfd_t *); 00153 apr_status_t (*poll)(apr_pollset_t *, apr_interval_time_t, apr_int32_t *, const apr_pollfd_t **); 00154 apr_status_t (*cleanup)(apr_pollset_t *); 00155 const char *name; 00156 }; 00157 00158 struct apr_pollcb_provider_t { 00159 apr_status_t (*create)(apr_pollcb_t *, apr_uint32_t, apr_pool_t *, apr_uint32_t); 00160 apr_status_t (*add)(apr_pollcb_t *, apr_pollfd_t *); 00161 apr_status_t (*remove)(apr_pollcb_t *, apr_pollfd_t *); 00162 apr_status_t (*poll)(apr_pollcb_t *, apr_interval_time_t, apr_pollcb_cb_t, void *); 00163 const char *name; 00164 }; 00165 00166 /* Private functions */ 00167 void apr_pollset_drain_wakeup_pipe(apr_pollset_t *pollset); 00168 00169 #endif /* APR_ARCH_POLL_PRIVATE_H */