pollcb.c (302408) | pollcb.c (362181) |
---|---|
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 --- 15 unchanged lines hidden (view full) --- 24#include "apr_time.h" 25#include "apr_portable.h" 26#include "apr_arch_file_io.h" 27#include "apr_arch_networkio.h" 28#include "apr_arch_poll_private.h" 29 30static apr_pollset_method_e pollset_default_method = POLLSET_DEFAULT_METHOD; 31#if defined(HAVE_KQUEUE) | 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 --- 15 unchanged lines hidden (view full) --- 24#include "apr_time.h" 25#include "apr_portable.h" 26#include "apr_arch_file_io.h" 27#include "apr_arch_networkio.h" 28#include "apr_arch_poll_private.h" 29 30static apr_pollset_method_e pollset_default_method = POLLSET_DEFAULT_METHOD; 31#if defined(HAVE_KQUEUE) |
32extern apr_pollcb_provider_t *apr_pollcb_provider_kqueue; | 32extern const apr_pollcb_provider_t *apr_pollcb_provider_kqueue; |
33#endif 34#if defined(HAVE_PORT_CREATE) | 33#endif 34#if defined(HAVE_PORT_CREATE) |
35extern apr_pollcb_provider_t *apr_pollcb_provider_port; | 35extern const apr_pollcb_provider_t *apr_pollcb_provider_port; |
36#endif 37#if defined(HAVE_EPOLL) | 36#endif 37#if defined(HAVE_EPOLL) |
38extern apr_pollcb_provider_t *apr_pollcb_provider_epoll; | 38extern const apr_pollcb_provider_t *apr_pollcb_provider_epoll; |
39#endif 40#if defined(HAVE_POLL) | 39#endif 40#if defined(HAVE_POLL) |
41extern apr_pollcb_provider_t *apr_pollcb_provider_poll; | 41extern const apr_pollcb_provider_t *apr_pollcb_provider_poll; |
42#endif 43 | 42#endif 43 |
44static apr_pollcb_provider_t *pollcb_provider(apr_pollset_method_e method) | 44static const apr_pollcb_provider_t *pollcb_provider(apr_pollset_method_e method) |
45{ | 45{ |
46 apr_pollcb_provider_t *provider = NULL; | 46 const apr_pollcb_provider_t *provider = NULL; |
47 switch (method) { 48 case APR_POLLSET_KQUEUE: 49#if defined(HAVE_KQUEUE) 50 provider = apr_pollcb_provider_kqueue; 51#endif 52 break; 53 case APR_POLLSET_PORT: 54#if defined(HAVE_PORT_CREATE) --- 13 unchanged lines hidden (view full) --- 68 case APR_POLLSET_SELECT: 69 case APR_POLLSET_AIO_MSGQ: 70 case APR_POLLSET_DEFAULT: 71 break; 72 } 73 return provider; 74} 75 | 47 switch (method) { 48 case APR_POLLSET_KQUEUE: 49#if defined(HAVE_KQUEUE) 50 provider = apr_pollcb_provider_kqueue; 51#endif 52 break; 53 case APR_POLLSET_PORT: 54#if defined(HAVE_PORT_CREATE) --- 13 unchanged lines hidden (view full) --- 68 case APR_POLLSET_SELECT: 69 case APR_POLLSET_AIO_MSGQ: 70 case APR_POLLSET_DEFAULT: 71 break; 72 } 73 return provider; 74} 75 |
76static apr_status_t pollcb_cleanup(void *p) 77{ 78 apr_pollcb_t *pollcb = (apr_pollcb_t *) p; 79 80 if (pollcb->provider->cleanup) { 81 (*pollcb->provider->cleanup)(pollcb); 82 } 83 if (pollcb->flags & APR_POLLSET_WAKEABLE) { 84 apr_poll_close_wakeup_pipe(pollcb->wakeup_pipe); 85 } 86 87 return APR_SUCCESS; 88} 89 |
|
76APR_DECLARE(apr_status_t) apr_pollcb_create_ex(apr_pollcb_t **ret_pollcb, 77 apr_uint32_t size, 78 apr_pool_t *p, 79 apr_uint32_t flags, 80 apr_pollset_method_e method) 81{ 82 apr_status_t rv; 83 apr_pollcb_t *pollcb; | 90APR_DECLARE(apr_status_t) apr_pollcb_create_ex(apr_pollcb_t **ret_pollcb, 91 apr_uint32_t size, 92 apr_pool_t *p, 93 apr_uint32_t flags, 94 apr_pollset_method_e method) 95{ 96 apr_status_t rv; 97 apr_pollcb_t *pollcb; |
84 apr_pollcb_provider_t *provider = NULL; | 98 const apr_pollcb_provider_t *provider = NULL; |
85 86 *ret_pollcb = NULL; 87 88 #ifdef WIN32 89 /* This will work only if ws2_32.dll has WSAPoll funtion. 90 * We could check the presence of the function here, 91 * but someone might implement other pollcb method in 92 * the future. --- 11 unchanged lines hidden (view full) --- 104 if ((flags & APR_POLLSET_NODEFAULT) == APR_POLLSET_NODEFAULT) 105 return APR_ENOTIMPL; 106 if (method == pollset_default_method) 107 return APR_ENOTIMPL; 108 method = pollset_default_method; 109 } 110 } 111 | 99 100 *ret_pollcb = NULL; 101 102 #ifdef WIN32 103 /* This will work only if ws2_32.dll has WSAPoll funtion. 104 * We could check the presence of the function here, 105 * but someone might implement other pollcb method in 106 * the future. --- 11 unchanged lines hidden (view full) --- 118 if ((flags & APR_POLLSET_NODEFAULT) == APR_POLLSET_NODEFAULT) 119 return APR_ENOTIMPL; 120 if (method == pollset_default_method) 121 return APR_ENOTIMPL; 122 method = pollset_default_method; 123 } 124 } 125 |
126 if (flags & APR_POLLSET_WAKEABLE) { 127 /* Add room for wakeup descriptor */ 128 size++; 129 } 130 |
|
112 pollcb = apr_palloc(p, sizeof(*pollcb)); 113 pollcb->nelts = 0; 114 pollcb->nalloc = size; | 131 pollcb = apr_palloc(p, sizeof(*pollcb)); 132 pollcb->nelts = 0; 133 pollcb->nalloc = size; |
134 pollcb->flags = flags; |
|
115 pollcb->pool = p; 116 pollcb->provider = provider; 117 118 rv = (*provider->create)(pollcb, size, p, flags); 119 if (rv == APR_ENOTIMPL) { 120 if (method == pollset_default_method) { 121 return rv; 122 } --- 12 unchanged lines hidden (view full) --- 135 return rv; 136 } 137 pollcb->provider = provider; 138 } 139 else if (rv != APR_SUCCESS) { 140 return rv; 141 } 142 | 135 pollcb->pool = p; 136 pollcb->provider = provider; 137 138 rv = (*provider->create)(pollcb, size, p, flags); 139 if (rv == APR_ENOTIMPL) { 140 if (method == pollset_default_method) { 141 return rv; 142 } --- 12 unchanged lines hidden (view full) --- 155 return rv; 156 } 157 pollcb->provider = provider; 158 } 159 else if (rv != APR_SUCCESS) { 160 return rv; 161 } 162 |
163 if (flags & APR_POLLSET_WAKEABLE) { 164 /* Create wakeup pipe */ 165 if ((rv = apr_poll_create_wakeup_pipe(pollcb->pool, &pollcb->wakeup_pfd, 166 pollcb->wakeup_pipe)) 167 != APR_SUCCESS) { 168 return rv; 169 } 170 171 if ((rv = apr_pollcb_add(pollcb, &pollcb->wakeup_pfd)) != APR_SUCCESS) { 172 return rv; 173 } 174 } 175 if ((flags & APR_POLLSET_WAKEABLE) || provider->cleanup) 176 apr_pool_cleanup_register(p, pollcb, pollcb_cleanup, 177 apr_pool_cleanup_null); 178 |
|
143 *ret_pollcb = pollcb; 144 return APR_SUCCESS; 145} 146 147APR_DECLARE(apr_status_t) apr_pollcb_create(apr_pollcb_t **pollcb, 148 apr_uint32_t size, 149 apr_pool_t *p, 150 apr_uint32_t flags) --- 17 unchanged lines hidden (view full) --- 168 169APR_DECLARE(apr_status_t) apr_pollcb_poll(apr_pollcb_t *pollcb, 170 apr_interval_time_t timeout, 171 apr_pollcb_cb_t func, 172 void *baton) 173{ 174 return (*pollcb->provider->poll)(pollcb, timeout, func, baton); 175} | 179 *ret_pollcb = pollcb; 180 return APR_SUCCESS; 181} 182 183APR_DECLARE(apr_status_t) apr_pollcb_create(apr_pollcb_t **pollcb, 184 apr_uint32_t size, 185 apr_pool_t *p, 186 apr_uint32_t flags) --- 17 unchanged lines hidden (view full) --- 204 205APR_DECLARE(apr_status_t) apr_pollcb_poll(apr_pollcb_t *pollcb, 206 apr_interval_time_t timeout, 207 apr_pollcb_cb_t func, 208 void *baton) 209{ 210 return (*pollcb->provider->poll)(pollcb, timeout, func, baton); 211} |
212 213APR_DECLARE(apr_status_t) apr_pollcb_wakeup(apr_pollcb_t *pollcb) 214{ 215 if (pollcb->flags & APR_POLLSET_WAKEABLE) 216 return apr_file_putc(1, pollcb->wakeup_pipe[1]); 217 else 218 return APR_EINIT; 219} 220 221APR_DECLARE(const char *) apr_pollcb_method_name(apr_pollcb_t *pollcb) 222{ 223 return pollcb->provider->name; 224} |
|