summaryrefslogtreecommitdiff
path: root/poll/os2
diff options
context:
space:
mode:
authorrbb <rbb@13f79535-47bb-0310-9956-ffa450edef68>2002-07-11 05:40:23 +0000
committerrbb <rbb@13f79535-47bb-0310-9956-ffa450edef68>2002-07-11 05:40:23 +0000
commite1f3fc068a2b69044feff2eac9d99ad80af42914 (patch)
tree761714ee76ab8cbe6cfa4a50bb63b1c185b3deb2 /poll/os2
parent80daecece485a0a67d51a5e96463f283ee914a45 (diff)
downloadlibapr-e1f3fc068a2b69044feff2eac9d99ad80af42914.tar.gz
An attempt at the OS/2 implementation. I have no OS/2 box, so this
probably won't work, but at least it is a start. My only question is can you select on a file descriptor on OS/2? If not, then we will just have to return an error on OS/2 if somebody tries to. git-svn-id: http://svn.apache.org/repos/asf/apr/apr/trunk@63603 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'poll/os2')
-rwxr-xr-xpoll/os2/Makefile.in15
-rwxr-xr-xpoll/os2/poll.c178
2 files changed, 193 insertions, 0 deletions
diff --git a/poll/os2/Makefile.in b/poll/os2/Makefile.in
new file mode 100755
index 000000000..8848b5621
--- /dev/null
+++ b/poll/os2/Makefile.in
@@ -0,0 +1,15 @@
+srcdir = @srcdir@
+VPATH = @srcdir@
+
+TARGETS = \
+ poll.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/poll/os2/poll.c b/poll/os2/poll.c
new file mode 100755
index 000000000..146e950ac
--- /dev/null
+++ b/poll/os2/poll.c
@@ -0,0 +1,178 @@
+/* ====================================================================
+ * The Apache Software License, Version 1.1
+ *
+ * Copyright (c) 2000-2002 The Apache Software Foundation. All rights
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * 3. The end-user documentation included with the redistribution,
+ * if any, must include the following acknowledgment:
+ * "This product includes software developed by the
+ * Apache Software Foundation (http://www.apache.org/)."
+ * Alternately, this acknowledgment may appear in the software itself,
+ * if and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "Apache" and "Apache Software Foundation" must
+ * not be used to endorse or promote products derived from this
+ * software without prior written permission. For written
+ * permission, please contact apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache",
+ * nor may "Apache" appear in their name, without prior written
+ * permission of the Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ */
+
+#include "networkio.h"
+#include "apr_network_io.h"
+#include "apr_general.h"
+#include "apr_portable.h"
+#include "apr_lib.h"
+#include <sys/time.h>
+#include <stdlib.h>
+
+/* OS/2 doesn't have a poll function, implement using OS/2 style select */
+
+APR_DECLARE(apr_status_t) apr_poll_setup(apr_pollfd_t **new, apr_int32_t num, apr_pool_t *cont)
+{
+ *new = (apr_pollfd_t *)apr_palloc(cont, sizeof(apr_pollfd_t));
+
+ if (*new == NULL) {
+ return APR_ENOMEM;
+ }
+
+ (*new)->socket_list = apr_palloc(cont, sizeof(int) * num);
+
+ if ((*new)->socket_list == NULL) {
+ return APR_ENOMEM;
+ }
+
+ (*new)->r_socket_list = apr_palloc(cont, sizeof(int) * num);
+
+ if ((*new)->r_socket_list == NULL) {
+ return APR_ENOMEM;
+ }
+
+ (*new)->cntxt = cont;
+ (*new)->num_total = 0;
+ (*new)->num_read = 0;
+ (*new)->num_write = 0;
+ (*new)->num_except = 0;
+
+ return APR_SUCCESS;
+}
+
+
+
+APR_DECLARE(apr_status_t) apr_poll_socket_add(apr_pollfd_t *aprset,
+ apr_socket_t *sock, apr_int16_t events)
+{
+ int i;
+
+ if (events & APR_POLLIN) {
+ for (i=aprset->num_total; i>aprset->num_read; i--)
+ aprset->socket_list[i] = aprset->socket_list[i-1];
+ aprset->socket_list[i] = sock->socketdes;
+ aprset->num_read++;
+ aprset->num_total++;
+ }
+
+ if (events & APR_POLLOUT) {
+ for (i=aprset->num_total; i>aprset->num_read + aprset->num_write; i--)
+ aprset->socket_list[i] = aprset->socket_list[i-1];
+ aprset->socket_list[i] = sock->socketdes;
+ aprset->num_write++;
+ aprset->num_total++;
+ }
+
+ if (events &APR_POLLPRI) {
+ aprset->socket_list[aprset->num_total] = sock->socketdes;
+ aprset->num_except++;
+ aprset->num_total++;
+ }
+ return APR_SUCCESS;
+}
+
+
+
+APR_DECLARE(apr_status_t) apr_poll(apr_pollfd_t *pollfdset, int num,
+ apr_int32_t *nsds,
+ apr_interval_time_t timeout)
+{
+ int i;
+ int rv = 0;
+ int num_read = 0, num_write = 0, num_except = 0;
+ int *socket_list;
+
+ for (i = 0; i < num; i++) {
+ int events = pollfdset[i].events;
+ int fd;
+
+ if (pollfdset[i].desc_type == APR_POLL_SOCKET) {
+ fd = pollfdset[i].desc.s->socketdes;
+ }
+ else if (pollfdset[i].desc_type == APR_POLL_FILE) {
+ fd = pollfdset[i].desc.f->filedes;
+ }
+
+ if (events & APR_POLLIN) {
+ socket_list[num_read] = fd;
+ num_read++;
+ }
+
+ if (events & APR_POLLOUT) {
+ socket_list[num_write] = fd;
+ num_write++;
+ }
+
+ if (events &APR_POLLPRI) {
+ socket_list[num_except] = fd;
+ num_except++;
+ }
+ }
+
+ rv = select(socket_list,
+ num_read,
+ num_write,
+ num_except,
+ timeout >= 0 ? timeout / 1000 : -1);
+
+ /* select() doesn't wipe the socket list in the case of a timeout or
+ * interrupt. This prevents false positives from revents_get
+ */
+ if (rv == 0) {
+ return timeout < 0 ? APR_EINTR : APR_TIMEUP;
+ }
+
+ (*nsds) = rv;
+ return rv < 0 ? APR_OS2_STATUS(sock_errno()) : APR_SUCCESS;
+}