summaryrefslogtreecommitdiffstats
path: root/rubbos/app/httpd-2.0.64/srclib/apr/poll/os2
diff options
context:
space:
mode:
authorhongbotian <hongbo.tianhongbo@huawei.com>2015-11-30 01:45:08 -0500
committerhongbotian <hongbo.tianhongbo@huawei.com>2015-11-30 01:45:08 -0500
commite8ec7aa8e38a93f5b034ac74cebce5de23710317 (patch)
treeaa031937bf856c1f8d6ad7877b8d2cb0224da5ef /rubbos/app/httpd-2.0.64/srclib/apr/poll/os2
parentcc40af334e619bb549038238507407866f774f8f (diff)
upload http
JIRA: BOTTLENECK-10 Change-Id: I7598427ff904df438ce77c2819ee48ac75ffa8da Signed-off-by: hongbotian <hongbo.tianhongbo@huawei.com>
Diffstat (limited to 'rubbos/app/httpd-2.0.64/srclib/apr/poll/os2')
-rw-r--r--rubbos/app/httpd-2.0.64/srclib/apr/poll/os2/Makefile.in17
-rw-r--r--rubbos/app/httpd-2.0.64/srclib/apr/poll/os2/poll.c105
-rw-r--r--rubbos/app/httpd-2.0.64/srclib/apr/poll/os2/pollacc.c1
-rw-r--r--rubbos/app/httpd-2.0.64/srclib/apr/poll/os2/pollset.c220
4 files changed, 343 insertions, 0 deletions
diff --git a/rubbos/app/httpd-2.0.64/srclib/apr/poll/os2/Makefile.in b/rubbos/app/httpd-2.0.64/srclib/apr/poll/os2/Makefile.in
new file mode 100644
index 00000000..96fc006f
--- /dev/null
+++ b/rubbos/app/httpd-2.0.64/srclib/apr/poll/os2/Makefile.in
@@ -0,0 +1,17 @@
+srcdir = @srcdir@
+VPATH = @srcdir@
+
+TARGETS = \
+ poll.lo \
+ pollset.lo \
+ pollacc.lo
+
+# bring in rules.mk for standard functionality
+@INCLUDE_RULES@
+
+INCDIR=../../include
+OSDIR=$(INCDIR)/arch/@OSDIR@
+DEFOSDIR=$(INCDIR)/arch/@DEFAULT_OSDIR@
+INCLUDES=-I$(INCDIR) -I$(OSDIR) -I$(DEFOSDIR)
+
+# DO NOT REMOVE
diff --git a/rubbos/app/httpd-2.0.64/srclib/apr/poll/os2/poll.c b/rubbos/app/httpd-2.0.64/srclib/apr/poll/os2/poll.c
new file mode 100644
index 00000000..3c36e5e6
--- /dev/null
+++ b/rubbos/app/httpd-2.0.64/srclib/apr/poll/os2/poll.c
@@ -0,0 +1,105 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "apr.h"
+#include "apr_poll.h"
+#include "apr_arch_networkio.h"
+
+APR_DECLARE(apr_status_t) apr_poll(apr_pollfd_t *aprset, apr_int32_t num,
+ apr_int32_t *nsds, apr_interval_time_t timeout)
+{
+ int *pollset;
+ int i;
+ int num_read = 0, num_write = 0, num_except = 0, num_total;
+ int pos_read, pos_write, pos_except;
+
+ for (i = 0; i < num; i++) {
+ if (aprset[i].desc_type == APR_POLL_SOCKET) {
+ num_read += (aprset[i].reqevents & APR_POLLIN) != 0;
+ num_write += (aprset[i].reqevents & APR_POLLOUT) != 0;
+ num_except += (aprset[i].reqevents & APR_POLLPRI) != 0;
+ }
+ }
+
+ num_total = num_read + num_write + num_except;
+ pollset = alloca(sizeof(int) * num_total);
+ memset(pollset, 0, sizeof(int) * num_total);
+
+ pos_read = 0;
+ pos_write = num_read;
+ pos_except = pos_write + num_write;
+
+ for (i = 0; i < num; i++) {
+ if (aprset[i].desc_type == APR_POLL_SOCKET) {
+ if (aprset[i].reqevents & APR_POLLIN) {
+ pollset[pos_read++] = aprset[i].desc.s->socketdes;
+ }
+
+ if (aprset[i].reqevents & APR_POLLOUT) {
+ pollset[pos_write++] = aprset[i].desc.s->socketdes;
+ }
+
+ if (aprset[i].reqevents & APR_POLLPRI) {
+ pollset[pos_except++] = aprset[i].desc.s->socketdes;
+ }
+
+ aprset[i].rtnevents = 0;
+ }
+ }
+
+ if (timeout > 0) {
+ timeout /= 1000; /* convert microseconds to milliseconds */
+ }
+
+ i = select(pollset, num_read, num_write, num_except, timeout);
+ (*nsds) = i;
+
+ if ((*nsds) < 0) {
+ return APR_FROM_OS_ERROR(sock_errno());
+ }
+
+ if ((*nsds) == 0) {
+ return APR_TIMEUP;
+ }
+
+ pos_read = 0;
+ pos_write = num_read;
+ pos_except = pos_write + num_write;
+
+ for (i = 0; i < num; i++) {
+ if (aprset[i].desc_type == APR_POLL_SOCKET) {
+ if (aprset[i].reqevents & APR_POLLIN) {
+ if (pollset[pos_read++] > 0) {
+ aprset[i].rtnevents |= APR_POLLIN;
+ }
+ }
+
+ if (aprset[i].reqevents & APR_POLLOUT) {
+ if (pollset[pos_write++] > 0) {
+ aprset[i].rtnevents |= APR_POLLOUT;
+ }
+ }
+
+ if (aprset[i].reqevents & APR_POLLPRI) {
+ if (pollset[pos_except++] > 0) {
+ aprset[i].rtnevents |= APR_POLLPRI;
+ }
+ }
+ }
+ }
+
+ return APR_SUCCESS;
+}
diff --git a/rubbos/app/httpd-2.0.64/srclib/apr/poll/os2/pollacc.c b/rubbos/app/httpd-2.0.64/srclib/apr/poll/os2/pollacc.c
new file mode 100644
index 00000000..ac87d0aa
--- /dev/null
+++ b/rubbos/app/httpd-2.0.64/srclib/apr/poll/os2/pollacc.c
@@ -0,0 +1 @@
+#include "../unix/pollacc.c"
diff --git a/rubbos/app/httpd-2.0.64/srclib/apr/poll/os2/pollset.c b/rubbos/app/httpd-2.0.64/srclib/apr/poll/os2/pollset.c
new file mode 100644
index 00000000..872571f8
--- /dev/null
+++ b/rubbos/app/httpd-2.0.64/srclib/apr/poll/os2/pollset.c
@@ -0,0 +1,220 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "apr.h"
+#include "apr_poll.h"
+#include "apr_arch_networkio.h"
+
+
+
+struct apr_pollset_t {
+ apr_pool_t *pool;
+ apr_uint32_t nelts;
+ apr_uint32_t nalloc;
+ int *pollset;
+ int num_read;
+ int num_write;
+ int num_except;
+ int num_total;
+ apr_pollfd_t *query_set;
+ apr_pollfd_t *result_set;
+};
+
+
+
+APR_DECLARE(apr_status_t) apr_pollset_create(apr_pollset_t **pollset,
+ apr_uint32_t size,
+ apr_pool_t *p,
+ apr_uint32_t flags)
+{
+ *pollset = apr_palloc(p, sizeof(**pollset));
+ (*pollset)->pool = p;
+ (*pollset)->nelts = 0;
+ (*pollset)->nalloc = size;
+ (*pollset)->pollset = apr_palloc(p, size * sizeof(int) * 3);
+ (*pollset)->query_set = apr_palloc(p, size * sizeof(apr_pollfd_t));
+ (*pollset)->result_set = apr_palloc(p, size * sizeof(apr_pollfd_t));
+ (*pollset)->num_read = -1;
+ return APR_SUCCESS;
+}
+
+
+
+APR_DECLARE(apr_status_t) apr_pollset_destroy(apr_pollset_t *pollset)
+{
+ /* A no-op function for now. If we later implement /dev/poll
+ * support, we'll need to close the /dev/poll fd here
+ */
+ return APR_SUCCESS;
+}
+
+
+
+APR_DECLARE(apr_status_t) apr_pollset_add(apr_pollset_t *pollset,
+ const apr_pollfd_t *descriptor)
+{
+ if (pollset->nelts == pollset->nalloc) {
+ return APR_ENOMEM;
+ }
+
+ pollset->query_set[pollset->nelts] = *descriptor;
+
+ if (descriptor->desc_type != APR_POLL_SOCKET) {
+ return APR_EBADF;
+ }
+
+ pollset->nelts++;
+ pollset->num_read = -1;
+ return APR_SUCCESS;
+}
+
+
+
+APR_DECLARE(apr_status_t) apr_pollset_remove(apr_pollset_t *pollset,
+ const apr_pollfd_t *descriptor)
+{
+ apr_uint32_t i;
+
+ for (i = 0; i < pollset->nelts; i++) {
+ if (descriptor->desc.s == pollset->query_set[i].desc.s) {
+ /* Found an instance of the fd: remove this and any other copies */
+ apr_uint32_t dst = i;
+ apr_uint32_t old_nelts = pollset->nelts;
+ pollset->nelts--;
+
+ for (i++; i < old_nelts; i++) {
+ if (descriptor->desc.s == pollset->query_set[i].desc.s) {
+ pollset->nelts--;
+ }
+ else {
+ pollset->pollset[dst] = pollset->pollset[i];
+ pollset->query_set[dst] = pollset->query_set[i];
+ dst++;
+ }
+ }
+
+ pollset->num_read = -1;
+ return APR_SUCCESS;
+ }
+ }
+
+ return APR_NOTFOUND;
+}
+
+
+
+static void make_pollset(apr_pollset_t *pollset)
+{
+ int i;
+ int pos = 0;
+
+ pollset->num_read = 0;
+ pollset->num_write = 0;
+ pollset->num_except = 0;
+
+ for (i = 0; i < pollset->nelts; i++) {
+ if (pollset->query_set[i].reqevents & APR_POLLIN) {
+ pollset->pollset[pos++] = pollset->query_set[i].desc.s->socketdes;
+ pollset->num_read++;
+ }
+ }
+
+ for (i = 0; i < pollset->nelts; i++) {
+ if (pollset->query_set[i].reqevents & APR_POLLOUT) {
+ pollset->pollset[pos++] = pollset->query_set[i].desc.s->socketdes;
+ pollset->num_write++;
+ }
+ }
+
+ for (i = 0; i < pollset->nelts; i++) {
+ if (pollset->query_set[i].reqevents & APR_POLLPRI) {
+ pollset->pollset[pos++] = pollset->query_set[i].desc.s->socketdes;
+ pollset->num_except++;
+ }
+ }
+
+ pollset->num_total = pollset->num_read + pollset->num_write + pollset->num_except;
+}
+
+
+
+APR_DECLARE(apr_status_t) apr_pollset_poll(apr_pollset_t *pollset,
+ apr_interval_time_t timeout,
+ apr_int32_t *num,
+ const apr_pollfd_t **descriptors)
+{
+ int rv;
+ apr_uint32_t i;
+ int *pollresult;
+ int read_pos, write_pos, except_pos;
+
+ if (pollset->num_read < 0) {
+ make_pollset(pollset);
+ }
+
+ pollresult = alloca(sizeof(int) * pollset->num_total);
+ memcpy(pollresult, pollset->pollset, sizeof(int) * pollset->num_total);
+ (*num) = 0;
+
+ if (timeout > 0) {
+ timeout /= 1000;
+ }
+
+ rv = select(pollresult, pollset->num_read, pollset->num_write, pollset->num_except, timeout);
+
+ if (rv < 0) {
+ return APR_FROM_OS_ERROR(sock_errno());
+ }
+
+ if (rv == 0) {
+ return APR_TIMEUP;
+ }
+
+ read_pos = 0;
+ write_pos = pollset->num_read;
+ except_pos = pollset->num_read + pollset->num_write;
+
+ for (i = 0; i < pollset->nelts; i++) {
+ int rtnevents = 0;
+
+ if (pollset->query_set[i].reqevents & APR_POLLIN) {
+ if (pollresult[read_pos++] != -1) {
+ rtnevents |= APR_POLLIN;
+ }
+ }
+
+ if (pollset->query_set[i].reqevents & APR_POLLOUT) {
+ if (pollresult[write_pos++] != -1) {
+ rtnevents |= APR_POLLOUT;
+ }
+ }
+
+ if (pollset->query_set[i].reqevents & APR_POLLPRI) {
+ if (pollresult[except_pos++] != -1) {
+ rtnevents |= APR_POLLPRI;
+ }
+ }
+
+ if (rtnevents) {
+ pollset->result_set[*num] = pollset->query_set[i];
+ pollset->result_set[*num].rtnevents = rtnevents;
+ (*num)++;
+ }
+ }
+
+ *descriptors = pollset->result_set;
+ return APR_SUCCESS;
+}