commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mt...@apache.org
Subject svn commit: r1138809 - in /commons/sandbox/runtime/trunk/src/main/native: Makefile.msc.in Makefile.unx.in os/unix/selectset.c shared/select.c
Date Thu, 23 Jun 2011 10:10:45 GMT
Author: mturk
Date: Thu Jun 23 10:10:45 2011
New Revision: 1138809

URL: http://svn.apache.org/viewvc?rev=1138809&view=rev
Log:
Add shared select native impl

Added:
    commons/sandbox/runtime/trunk/src/main/native/os/unix/selectset.c   (with props)
    commons/sandbox/runtime/trunk/src/main/native/shared/select.c   (with props)
Modified:
    commons/sandbox/runtime/trunk/src/main/native/Makefile.msc.in
    commons/sandbox/runtime/trunk/src/main/native/Makefile.unx.in

Modified: commons/sandbox/runtime/trunk/src/main/native/Makefile.msc.in
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/Makefile.msc.in?rev=1138809&r1=1138808&r2=1138809&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/Makefile.msc.in (original)
+++ commons/sandbox/runtime/trunk/src/main/native/Makefile.msc.in Thu Jun 23 10:10:45 2011
@@ -127,6 +127,7 @@ LIBSOURCES=\
 	$(TOPDIR)\shared\observer.c \
 	$(TOPDIR)\shared\reflect.c \
 	$(TOPDIR)\shared\sbuf.c \
+	$(TOPDIR)\shared\select.c \
 	$(TOPDIR)\shared\selectkey.c \
 	$(TOPDIR)\shared\sliceptr.c \
 	$(TOPDIR)\shared\ssock.c \

Modified: commons/sandbox/runtime/trunk/src/main/native/Makefile.unx.in
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/Makefile.unx.in?rev=1138809&r1=1138808&r2=1138809&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/Makefile.unx.in (original)
+++ commons/sandbox/runtime/trunk/src/main/native/Makefile.unx.in Thu Jun 23 10:10:45 2011
@@ -71,7 +71,7 @@ UNIX_SOURCES=\
 	$(TOPDIR)/os/unix/posixapi.c \
 	$(TOPDIR)/os/unix/procmutex.c \
 	$(TOPDIR)/os/unix/shmem.c \
-	$(TOPDIR)/os/unix/select.c \
+	$(TOPDIR)/os/unix/selectset.c \
 	$(TOPDIR)/os/unix/semaphore.c \
 	$(TOPDIR)/os/unix/time.c \
 	$(TOPDIR)/os/unix/usock.c \
@@ -124,6 +124,7 @@ LIBSOURCES=\
 	$(TOPDIR)/shared/reflect.c \
 	$(TOPDIR)/shared/sbuf.c \
 	$(TOPDIR)/shared/sliceptr.c \
+	$(TOPDIR)/shared/select.c \
 	$(TOPDIR)/shared/selectkey.c \
 	$(TOPDIR)/shared/ssock.c \
 	$(TOPDIR)/shared/string.c \

Added: commons/sandbox/runtime/trunk/src/main/native/os/unix/selectset.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/unix/selectset.c?rev=1138809&view=auto
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/unix/selectset.c (added)
+++ commons/sandbox/runtime/trunk/src/main/native/os/unix/selectset.c Thu Jun 23 10:10:45
2011
@@ -0,0 +1,71 @@
+/* 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 "acr/clazz.h"
+#include "acr/memory.h"
+#include "acr/jniapi.h"
+#include "acr/port.h"
+#include "acr/time.h"
+#include "acr/iodefs.h"
+#include "acr/netapi.h"
+#include "arch_opts.h"
+#if HAVE_SYS_RESOURCE_H
+# include <sys/resource.h>
+#endif
+
+/* pollset operation states */
+#define PSS_DESTROY     1
+#define PSS_POLL        2
+#define PSS_WAIT        3
+#define PSS_WAKEUP      4
+
+ACR_NET_EXPORT(jint, SocketSelectorFactory, type0)(JNI_STDARGS)
+{
+    return PS_DEFAULT_TYPE;
+}
+
+ACR_NET_EXPORT(jint, LocalSelectorFactory, type0)(JNI_STDARGS)
+{
+    return PS_DEFAULT_LOCAL;
+}
+
+static int rlimit_nofile(void)
+{
+    int nm = 65536;
+#if HAVE_SYS_RESOURCE_H
+    struct rlimit rl;
+
+    if (getrlimit(RLIMIT_NOFILE, &rl) == 0 && rl.rlim_max != RLIM_INFINITY)
+        nm = (int)rl.rlim_max;
+    else
+#endif
+        nm = (int)sysconf(_SC_OPEN_MAX);
+    if (nm > 1)
+        --nm;
+    else
+        nm = 1023;
+    return nm;
+}
+
+ACR_NET_EXPORT(jint, SocketSelectorFactory, size0)(JNI_STDARGS)
+{
+    return rlimit_nofile();
+}
+
+ACR_NET_EXPORT(jint, LocalSelectorFactory, size0)(JNI_STDARGS)
+{
+    return rlimit_nofile();
+}

Propchange: commons/sandbox/runtime/trunk/src/main/native/os/unix/selectset.c
------------------------------------------------------------------------------
    svn:eol-style = native

Added: commons/sandbox/runtime/trunk/src/main/native/shared/select.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/shared/select.c?rev=1138809&view=auto
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/shared/select.c (added)
+++ commons/sandbox/runtime/trunk/src/main/native/shared/select.c Thu Jun 23 10:10:45 2011
@@ -0,0 +1,199 @@
+/* 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 "acr/clazz.h"
+#include "acr/memory.h"
+#include "acr/jniapi.h"
+#include "acr/port.h"
+#include "acr/time.h"
+#include "acr/iodefs.h"
+#include "acr/netapi.h"
+#include "arch_opts.h"
+
+ACR_NET_EXPORT(jint, Select, wait0)(JNI_STDARGS, jlongArray fdset,
+                                    jshortArray events, jshortArray revents,
+                                    jint nevents, jint timeout)
+{
+    int ns, i;
+    int nmax = -1;
+#if !defined(WINDOWS)
+    acr_time_t tmx = 0;
+#endif
+    acr_fd_t  *fd;
+    struct timeval  tv;
+    struct timeval *tp = 0;
+    fd_set rdset, wrset, exset;
+    jshort *pevents;
+    jlong  *pfdset;
+
+#if defined(FD_SETSIZE)
+    if (nevents > FD_SETSIZE) {
+        ACR_THROW_NET_ERROR(ACR_EOVERFLOW);
+        return 0;
+    }
+#endif
+    FD_ZERO(&rdset);
+    FD_ZERO(&wrset);
+    FD_ZERO(&exset);
+
+    pfdset  = JARRAY_CRITICAL(jlong,  fdset);
+    pevents = JARRAY_CRITICAL(jshort, events);
+    for (i = 0; i < nevents; i++) {
+        fd = J2P(pfdset[i], acr_fd_t *);
+#if defined(FD_SETSIZE)
+# if !defined(WINDOWS)
+        if (fd->u.s > FD_SETSIZE) {
+            RELEASE_CRITICAL(events, pevents);
+            RELEASE_CRITICAL(fdset,  pfdset);
+            ACR_THROW_NET_ERROR(ACR_ERANGE);
+            return 0;
+        }
+# endif
+#endif
+        if (pevents[i] & ACR_OP_INP) {
+            FD_SET(fd->u.s, &rdset);
+        }
+        if (pevents[i] & ACR_OP_OUT) {
+            FD_SET(fd->u.s, &wrset);
+        }
+        if (pevents[i] & ~(ACR_OP_INP | ACR_OP_OUT)) {
+            FD_SET(fd->u.s, &exset);
+        }
+        if (fd->u.f > nmax)
+            nmax = fd->u.f;
+    }
+    RELEASE_CRITICAL(events, pevents);
+    if (timeout > 0) {
+#if !defined(WINDOWS)
+        tmx = AcrTimeNow() +  AcrTimeFromMsec(timeout);
+#endif
+        tp  = &tv;
+    }
+    for (;;) {
+        if (timeout > 0) {
+            acr_time_t us = AcrTimeFromMsec(timeout);
+            tv.tv_sec  = (long)AcrTimeSec(us);
+            tv.tv_usec = (long)AcrTimeUsec(us);
+        }
+        ns = select(nmax + 1, &rdset, &wrset, &exset, tp);
+#if !defined(WINDOWS)
+        if (ns == -1 && errno == EINTR) {
+            if (timeout >= 0) {
+                timeout = tmx - AcrTimeNow();
+                if (timeout <= 0) {
+                    ns = 0;
+                    break;
+                }
+            }
+        }
+        else
+#endif
+        break;
+    }
+    if (ns == -1) {
+        ACR_THROW_NET_ERRNO();
+        RELEASE_CRITICAL(fdset,  pfdset);
+        return 0;
+    }
+    pevents = JARRAY_CRITICAL(jshort, revents);
+    for (i = 0; i < nevents; i++) {
+        fd = J2P(pfdset[i], acr_fd_t *);
+        pevents[i] = 0;
+        if (FD_ISSET(fd->u.s, &rdset)) {
+            pevents[i] |= ACR_OP_INP;
+        }
+        if (FD_ISSET(fd->u.s, &wrset)) {
+            pevents[i] |= ACR_OP_OUT;
+        }
+        if (FD_ISSET(fd->u.s, &exset)) {
+            pevents[i] |= ACR_OP_ERROR;
+        }
+    }
+    RELEASE_CRITICAL(revents, pevents);
+    RELEASE_CRITICAL(fdset,   pfdset);    
+    return ns;
+}
+
+ACR_NET_EXPORT(jshort, Select, wait1)(JNI_STDARGS, jlong fp,
+                                      jshort events, jint timeout)
+{
+    int ns;
+#if !defined(WINDOWS)
+    acr_time_t tmx = 0;
+#endif
+    acr_fd_t  *fd  = J2P(fp, acr_fd_t *);
+    struct timeval  tv;
+    struct timeval *tp = 0;
+    fd_set rdset, wrset, exset;
+
+    FD_ZERO(&rdset);
+    FD_ZERO(&wrset);
+    FD_ZERO(&exset);
+
+    if (events & ACR_OP_INP) {
+        FD_SET(fd->u.s, &rdset);
+    }
+    if (events & ACR_OP_OUT) {
+        FD_SET(fd->u.s, &wrset);
+    }
+    if (events & ~(ACR_OP_INP | ACR_OP_OUT)) {
+        FD_SET(fd->u.s, &exset);
+    }    
+    if (timeout > 0) {
+#if !defined(WINDOWS)
+        tmx = AcrTimeNow() +  AcrTimeFromMsec(timeout);
+#endif
+        tp  = &tv;
+    }
+    for (;;) {
+        if (timeout > 0) {
+            acr_time_t us = AcrTimeFromMsec(timeout);
+            tv.tv_sec  = (long)AcrTimeSec(us);
+            tv.tv_usec = (long)AcrTimeUsec(us);
+        }
+        ns = select(fd->u.s + 1, &rdset, &wrset, &exset, tp);
+#if !defined(WINDOWS)
+        if (ns == -1 && errno == EINTR) {
+            if (timeout >= 0) {
+                timeout = tmx - AcrTimeNow();
+                if (timeout <= 0) {
+                    ns = 0;
+                    break;
+                }
+            }
+        }
+        else
+#endif
+        break;
+    }
+    if (ns == -1) {
+        ACR_THROW_NET_ERRNO();
+        return 0;
+    }
+    else {
+        jshort rv = 0;
+        if (FD_ISSET(fd->u.s, &rdset)) {
+            rv |= ACR_OP_INP;
+        }
+        if (FD_ISSET(fd->u.s, &wrset)) {
+            rv |= ACR_OP_OUT;
+        }
+        if (FD_ISSET(fd->u.s, &exset)) {
+            rv |= ACR_OP_ERROR;
+        }
+        return rv;
+    }
+}

Propchange: commons/sandbox/runtime/trunk/src/main/native/shared/select.c
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message