~ubuntu-branches/ubuntu/feisty/apache2/feisty

« back to all changes in this revision

Viewing changes to srclib/apr/poll/os2/poll.c

  • Committer: Bazaar Package Importer
  • Author(s): Andreas Barth
  • Date: 2006-12-09 21:05:45 UTC
  • mfrom: (0.6.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20061209210545-h70s0xaqc2v8vqr2
Tags: 2.2.3-3.2
* Non-maintainer upload.
* 043_ajp_connection_reuse: Patch from upstream Bugzilla, fixing a critical
  issue with regard to connection reuse in mod_proxy_ajp.
  Closes: #396265

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* Copyright 2000-2005 The Apache Software Foundation or its licensors, as
 
2
 * applicable.
 
3
 *
 
4
 * Licensed under the Apache License, Version 2.0 (the "License");
 
5
 * you may not use this file except in compliance with the License.
 
6
 * 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
 
 
21
APR_DECLARE(apr_status_t) apr_poll(apr_pollfd_t *aprset, apr_int32_t num,
 
22
                      apr_int32_t *nsds, apr_interval_time_t timeout)
 
23
{
 
24
    int *pollset;
 
25
    int i;
 
26
    int num_read = 0, num_write = 0, num_except = 0, num_total;
 
27
    int pos_read, pos_write, pos_except;
 
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
        timeout /= 1000; /* convert microseconds to milliseconds */
 
65
    }
 
66
 
 
67
    i = select(pollset, num_read, num_write, num_except, timeout);
 
68
    (*nsds) = i;
 
69
 
 
70
    if ((*nsds) < 0) {
 
71
        return APR_FROM_OS_ERROR(sock_errno());
 
72
    }
 
73
 
 
74
    if ((*nsds) == 0) {
 
75
        return APR_TIMEUP;
 
76
    }
 
77
 
 
78
    pos_read = 0;
 
79
    pos_write = num_read;
 
80
    pos_except = pos_write + num_write;
 
81
 
 
82
    for (i = 0; i < num; i++) {
 
83
        if (aprset[i].desc_type == APR_POLL_SOCKET) {
 
84
            if (aprset[i].reqevents & APR_POLLIN) {
 
85
                if (pollset[pos_read++] > 0) {
 
86
                    aprset[i].rtnevents |= APR_POLLIN;
 
87
                }
 
88
            }
 
89
 
 
90
            if (aprset[i].reqevents & APR_POLLOUT) {
 
91
                if (pollset[pos_write++] > 0) {
 
92
                    aprset[i].rtnevents |= APR_POLLOUT;
 
93
                }
 
94
            }
 
95
 
 
96
            if (aprset[i].reqevents & APR_POLLPRI) {
 
97
                if (pollset[pos_except++] > 0) {
 
98
                    aprset[i].rtnevents |= APR_POLLPRI;
 
99
                }
 
100
            }
 
101
        }
 
102
    }
 
103
 
 
104
    return APR_SUCCESS;
 
105
}