Apache HTTPD
poll.c
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#include "apr.h"
18#include "apr_poll.h"
19#include "apr_arch_networkio.h"
20
23{
24 int *pollset;
25 int i;
26 int num_read = 0, num_write = 0, num_except = 0, num_total;
28
29 for (i = 0; i < num; i++) {
30 if (aprset[i].desc_type == APR_POLL_SOCKET) {
31 num_read += (aprset[i].reqevents & APR_POLLIN) != 0;
32 num_write += (aprset[i].reqevents & APR_POLLOUT) != 0;
33 num_except += (aprset[i].reqevents & APR_POLLPRI) != 0;
34 }
35 }
36
37 num_total = num_read + num_write + num_except;
38 pollset = alloca(sizeof(int) * num_total);
39 memset(pollset, 0, sizeof(int) * num_total);
40
41 pos_read = 0;
42 pos_write = num_read;
43 pos_except = pos_write + num_write;
44
45 for (i = 0; i < num; i++) {
46 if (aprset[i].desc_type == APR_POLL_SOCKET) {
47 if (aprset[i].reqevents & APR_POLLIN) {
48 pollset[pos_read++] = aprset[i].desc.s->socketdes;
49 }
50
51 if (aprset[i].reqevents & APR_POLLOUT) {
52 pollset[pos_write++] = aprset[i].desc.s->socketdes;
53 }
54
55 if (aprset[i].reqevents & APR_POLLPRI) {
56 pollset[pos_except++] = aprset[i].desc.s->socketdes;
57 }
58
59 aprset[i].rtnevents = 0;
60 }
61 }
62
63 if (timeout > 0) {
64 /* convert microseconds to milliseconds (round up) */
65 timeout = (timeout + 999) / 1000;
66 }
67
68 i = select(pollset, num_read, num_write, num_except, timeout);
69 (*nsds) = i;
70
71 if ((*nsds) < 0) {
73 }
74
75 if ((*nsds) == 0) {
76 return APR_TIMEUP;
77 }
78
79 pos_read = 0;
80 pos_write = num_read;
81 pos_except = pos_write + num_write;
82
83 for (i = 0; i < num; i++) {
84 if (aprset[i].desc_type == APR_POLL_SOCKET) {
85 if (aprset[i].reqevents & APR_POLLIN) {
86 if (pollset[pos_read++] > 0) {
87 aprset[i].rtnevents |= APR_POLLIN;
88 }
89 }
90
91 if (aprset[i].reqevents & APR_POLLOUT) {
92 if (pollset[pos_write++] > 0) {
93 aprset[i].rtnevents |= APR_POLLOUT;
94 }
95 }
96
97 if (aprset[i].reqevents & APR_POLLPRI) {
98 if (pollset[pos_except++] > 0) {
99 aprset[i].rtnevents |= APR_POLLPRI;
100 }
101 }
102 }
103 }
104
105 return APR_SUCCESS;
106}
#define select
#define sock_errno
APR Poll interface.
#define APR_TIMEUP
Definition apr_errno.h:450
const void apr_status_t(*) apr_status_t(* APR_DECLARE)(void) apr_pool_pre_cleanup_register(apr_pool_t *p
Definition apr_pools.h:646
apr_size_t size
#define APR_FROM_OS_ERROR(e)
Definition apr_errno.h:1214
#define APR_SUCCESS
Definition apr_errno.h:225
int apr_status_t
Definition apr_errno.h:44
apr_int32_t apr_int32_t * nsds
Definition apr_poll.h:301
apr_interval_time_t apr_int32_t * num
Definition apr_poll.h:273
@ APR_POLL_SOCKET
Definition apr_poll.h:93
apr_int64_t apr_interval_time_t
Definition apr_time.h:55
#define APR_POLLPRI
Definition apr_poll.h:50
#define APR_POLLOUT
Definition apr_poll.h:51
#define APR_POLLIN
Definition apr_poll.h:49
int i
Definition mod_so.c:347
static apr_pollset_t * pollset
Definition testpoll.c:41
IN ULONG IN INT timeout