poll.c (302408) | poll.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 --- 227 unchanged lines hidden (view full) --- 236static apr_status_t impl_pollset_poll(apr_pollset_t *pollset, 237 apr_interval_time_t timeout, 238 apr_int32_t *num, 239 const apr_pollfd_t **descriptors) 240{ 241 int ret; 242 apr_status_t rv = APR_SUCCESS; 243 | 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 --- 227 unchanged lines hidden (view full) --- 236static apr_status_t impl_pollset_poll(apr_pollset_t *pollset, 237 apr_interval_time_t timeout, 238 apr_int32_t *num, 239 const apr_pollfd_t **descriptors) 240{ 241 int ret; 242 apr_status_t rv = APR_SUCCESS; 243 |
244 *num = 0; 245 |
|
244#ifdef WIN32 245 /* WSAPoll() requires at least one socket. */ 246 if (pollset->nelts == 0) { | 246#ifdef WIN32 247 /* WSAPoll() requires at least one socket. */ 248 if (pollset->nelts == 0) { |
247 *num = 0; | |
248 if (timeout > 0) { 249 apr_sleep(timeout); 250 return APR_TIMEUP; 251 } 252 return APR_SUCCESS; 253 } 254 if (timeout > 0) { 255 timeout /= 1000; 256 } 257 ret = WSAPoll(pollset->p->pollset, pollset->nelts, (int)timeout); 258#else 259 if (timeout > 0) { 260 timeout /= 1000; 261 } 262 ret = poll(pollset->p->pollset, pollset->nelts, timeout); 263#endif | 249 if (timeout > 0) { 250 apr_sleep(timeout); 251 return APR_TIMEUP; 252 } 253 return APR_SUCCESS; 254 } 255 if (timeout > 0) { 256 timeout /= 1000; 257 } 258 ret = WSAPoll(pollset->p->pollset, pollset->nelts, (int)timeout); 259#else 260 if (timeout > 0) { 261 timeout /= 1000; 262 } 263 ret = poll(pollset->p->pollset, pollset->nelts, timeout); 264#endif |
264 (*num) = ret; | |
265 if (ret < 0) { 266 return apr_get_netos_error(); 267 } 268 else if (ret == 0) { 269 return APR_TIMEUP; 270 } 271 else { 272 apr_uint32_t i, j; 273 274 for (i = 0, j = 0; i < pollset->nelts; i++) { 275 if (pollset->p->pollset[i].revents != 0) { 276 /* Check if the polled descriptor is our 277 * wakeup pipe. In that case do not put it result set. 278 */ 279 if ((pollset->flags & APR_POLLSET_WAKEABLE) && 280 pollset->p->query_set[i].desc_type == APR_POLL_FILE && 281 pollset->p->query_set[i].desc.f == pollset->wakeup_pipe[0]) { | 265 if (ret < 0) { 266 return apr_get_netos_error(); 267 } 268 else if (ret == 0) { 269 return APR_TIMEUP; 270 } 271 else { 272 apr_uint32_t i, j; 273 274 for (i = 0, j = 0; i < pollset->nelts; i++) { 275 if (pollset->p->pollset[i].revents != 0) { 276 /* Check if the polled descriptor is our 277 * wakeup pipe. In that case do not put it result set. 278 */ 279 if ((pollset->flags & APR_POLLSET_WAKEABLE) && 280 pollset->p->query_set[i].desc_type == APR_POLL_FILE && 281 pollset->p->query_set[i].desc.f == pollset->wakeup_pipe[0]) { |
282 apr_pollset_drain_wakeup_pipe(pollset); 283 rv = APR_EINTR; | 282 apr_poll_drain_wakeup_pipe(pollset->wakeup_pipe); 283 rv = APR_EINTR; |
284 } 285 else { 286 pollset->p->result_set[j] = pollset->p->query_set[i]; 287 pollset->p->result_set[j].rtnevents = 288 get_revent(pollset->p->pollset[i].revents); 289 j++; 290 } 291 } 292 } | 284 } 285 else { 286 pollset->p->result_set[j] = pollset->p->query_set[i]; 287 pollset->p->result_set[j].rtnevents = 288 get_revent(pollset->p->pollset[i].revents); 289 j++; 290 } 291 } 292 } |
293 if (((*num) = j) > 0) | 293 if ((*num = j)) { /* any event besides wakeup pipe? */ |
294 rv = APR_SUCCESS; | 294 rv = APR_SUCCESS; |
295 } |
|
295 } 296 if (descriptors && (*num)) 297 *descriptors = pollset->p->result_set; 298 return rv; 299} 300 | 296 } 297 if (descriptors && (*num)) 298 *descriptors = pollset->p->result_set; 299 return rv; 300} 301 |
301static apr_pollset_provider_t impl = { | 302static const apr_pollset_provider_t impl = { |
302 impl_pollset_create, 303 impl_pollset_add, 304 impl_pollset_remove, 305 impl_pollset_poll, 306 NULL, 307 "poll" 308}; 309 | 303 impl_pollset_create, 304 impl_pollset_add, 305 impl_pollset_remove, 306 impl_pollset_poll, 307 NULL, 308 "poll" 309}; 310 |
310apr_pollset_provider_t *apr_pollset_provider_poll = &impl; | 311const apr_pollset_provider_t *apr_pollset_provider_poll = &impl; |
311 312/* Poll method pollcb. 313 * This is probably usable only for WIN32 having WSAPoll 314 */ 315static apr_status_t impl_pollcb_create(apr_pollcb_t *pollcb, 316 apr_uint32_t size, 317 apr_pool_t *p, 318 apr_uint32_t flags) --- 102 unchanged lines hidden (view full) --- 421 } 422 else if (ret == 0) { 423 return APR_TIMEUP; 424 } 425 else { 426 for (i = 0; i < pollcb->nelts; i++) { 427 if (pollcb->pollset.ps[i].revents != 0) { 428 apr_pollfd_t *pollfd = pollcb->copyset[i]; | 312 313/* Poll method pollcb. 314 * This is probably usable only for WIN32 having WSAPoll 315 */ 316static apr_status_t impl_pollcb_create(apr_pollcb_t *pollcb, 317 apr_uint32_t size, 318 apr_pool_t *p, 319 apr_uint32_t flags) --- 102 unchanged lines hidden (view full) --- 422 } 423 else if (ret == 0) { 424 return APR_TIMEUP; 425 } 426 else { 427 for (i = 0; i < pollcb->nelts; i++) { 428 if (pollcb->pollset.ps[i].revents != 0) { 429 apr_pollfd_t *pollfd = pollcb->copyset[i]; |
430 431 if ((pollcb->flags & APR_POLLSET_WAKEABLE) && 432 pollfd->desc_type == APR_POLL_FILE && 433 pollfd->desc.f == pollcb->wakeup_pipe[0]) { 434 apr_poll_drain_wakeup_pipe(pollcb->wakeup_pipe); 435 return APR_EINTR; 436 } 437 |
|
429 pollfd->rtnevents = get_revent(pollcb->pollset.ps[i].revents); 430 rv = func(baton, pollfd); 431 if (rv) { 432 return rv; 433 } 434 } 435 } 436 } 437 return rv; 438} 439 | 438 pollfd->rtnevents = get_revent(pollcb->pollset.ps[i].revents); 439 rv = func(baton, pollfd); 440 if (rv) { 441 return rv; 442 } 443 } 444 } 445 } 446 return rv; 447} 448 |
440static apr_pollcb_provider_t impl_cb = { | 449static const apr_pollcb_provider_t impl_cb = { |
441 impl_pollcb_create, 442 impl_pollcb_add, 443 impl_pollcb_remove, 444 impl_pollcb_poll, | 450 impl_pollcb_create, 451 impl_pollcb_add, 452 impl_pollcb_remove, 453 impl_pollcb_poll, |
454 NULL, |
|
445 "poll" 446}; 447 | 455 "poll" 456}; 457 |
448apr_pollcb_provider_t *apr_pollcb_provider_poll = &impl_cb; | 458const apr_pollcb_provider_t *apr_pollcb_provider_poll = &impl_cb; |
449 450#endif /* HAVE_POLL */ | 459 460#endif /* HAVE_POLL */ |