You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by mt...@apache.org on 2011/05/27 16:42:13 UTC
svn commit: r1128327 - in /commons/sandbox/runtime/trunk/src/main:
java/org/apache/commons/runtime/net/
java/org/apache/commons/runtime/platform/unix/ native/os/unix/ native/shared/
Author: mturk
Date: Fri May 27 14:42:12 2011
New Revision: 1128327
URL: http://svn.apache.org/viewvc?rev=1128327&view=rev
Log:
Rename Pollset to Selector
Added:
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/Selector.java
- copied, changed from r1128218, commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/Pollset.java
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/platform/unix/SelectorImpl.java
- copied, changed from r1128218, commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/platform/unix/PollsetImpl.java
Removed:
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/Pollset.java
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/platform/unix/PollsetImpl.java
Modified:
commons/sandbox/runtime/trunk/src/main/native/os/unix/arch_defs.h
commons/sandbox/runtime/trunk/src/main/native/os/unix/poll.c
commons/sandbox/runtime/trunk/src/main/native/shared/array.c
Copied: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/Selector.java (from r1128218, commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/Pollset.java)
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/Selector.java?p2=commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/Selector.java&p1=commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/Pollset.java&r1=1128218&r2=1128327&rev=1128327&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/Pollset.java (original)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/Selector.java Fri May 27 14:42:12 2011
@@ -25,16 +25,16 @@ import org.apache.commons.runtime.io.Inv
/**
* Wait for some event on set of socket descriptors.
*/
-public abstract class Pollset
+public abstract class Selector
{
- protected Pollset()
+ protected Selector()
{
// No instance
}
- private static final int maxSize;
- private static native int nmax0();
- private static native Pollset new0(int size)
+ private static final int maxSize;
+ private static native int nmax0();
+ private static native Selector new0(int size)
throws OutOfMemoryError;
static {
maxSize = nmax0();
@@ -43,7 +43,7 @@ public abstract class Pollset
/**
* Creates a new pollset instance.
*/
- public static Pollset newInstance(int size)
+ public static Selector newInstance(int size)
throws OutOfMemoryError
{
if (size == 0)
Copied: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/platform/unix/SelectorImpl.java (from r1128218, commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/platform/unix/PollsetImpl.java)
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/platform/unix/SelectorImpl.java?p2=commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/platform/unix/SelectorImpl.java&p1=commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/platform/unix/PollsetImpl.java&r1=1128218&r2=1128327&rev=1128327&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/platform/unix/PollsetImpl.java (original)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/platform/unix/SelectorImpl.java Fri May 27 14:42:12 2011
@@ -15,8 +15,8 @@
*/
package org.apache.commons.runtime.platform.unix;
-import org.apache.commons.runtime.net.Poll;
-import org.apache.commons.runtime.net.Pollset;
+import org.apache.commons.runtime.net.SelectionEvent;
+import org.apache.commons.runtime.net.Selector;
import org.apache.commons.runtime.AlreadyExistsException;
import org.apache.commons.runtime.InvalidArgumentException;
import org.apache.commons.runtime.NoSuchObjectException;
@@ -24,16 +24,16 @@ import org.apache.commons.runtime.Operat
import org.apache.commons.runtime.SystemException;
/**
- * Pollset implementation class.
+ * Selector implementation class.
* <p>
* </p>
*
* @since Runtime 1.0
*/
-final class PollsetImpl extends Pollset
+final class SelectorImpl extends Selector
{
- private PollsetImpl()
+ private SelectorImpl()
{
// No Instance
}
@@ -46,7 +46,7 @@ final class PollsetImpl extends Pollset
SystemException;
private static native void wakeup0(long pollset);
- private PollsetImpl(int size)
+ private SelectorImpl(int size)
{
pollset = create0(size);
revents = new short[size];
Modified: commons/sandbox/runtime/trunk/src/main/native/os/unix/arch_defs.h
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/unix/arch_defs.h?rev=1128327&r1=1128326&r2=1128327&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/unix/arch_defs.h (original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/unix/arch_defs.h Fri May 27 14:42:12 2011
@@ -134,4 +134,11 @@ typedef struct stat struct_stat_
#endif /* F_DUPFD */
+#if 1
+# define POLLSET_USE_POLL 1
+#else
+# define POLLSET_USE_POLL 0
+#endif
+
+
#endif /* _ACR_ARCH_DEFS_H_ */
Modified: commons/sandbox/runtime/trunk/src/main/native/os/unix/poll.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/unix/poll.c?rev=1128327&r1=1128326&r2=1128327&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/unix/poll.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/unix/poll.c Fri May 27 14:42:12 2011
@@ -20,12 +20,14 @@
#include "acr/port.h"
#include "acr/time.h"
#include "acr/iodefs.h"
+#include "acr/misc.h"
#include "arch_opts.h"
#include <poll.h>
#if HAVE_SYS_RESOURCE_H
# include <sys/resource.h>
#endif
+#if POLLSET_USE_POLL
/* pollset operation states */
#define PSS_DESTROY 1
#define PSS_POLL 2
@@ -54,7 +56,7 @@ J_DECLARE_CLAZZ = {
0,
0,
0,
- ACR_UNX_CP "PollsetImpl"
+ ACR_UNX_CP "SelectorImpl"
};
J_DECLARE_M_ID(0000) = {
@@ -63,6 +65,8 @@ J_DECLARE_M_ID(0000) = {
"(I)V"
};
+#endif
+
static short ieventt(int event)
{
short rv = 0;
@@ -101,7 +105,20 @@ static short reventt(short event)
return rv;
}
-ACR_NET_EXPORT(jint, Pollset, nmax0)(JNI_STDARGS)
+#if POLLSET_USE_POLL
+
+ACR_NET_EXPORT(jobject, Selector, new0)(JNI_STDARGS, jint size)
+{
+ if (_clazzn.u == 1)
+ return (*env)->NewObject(env, _clazzn.i, J4MID(0000), size);
+ if (AcrLoadClass(env, &_clazzn, 0) == JNI_FALSE)
+ return 0;
+ R_LOAD_METHOD(0000, 0);
+ _clazzn.u = 1;
+ return (*env)->NewObject(env, _clazzn.i, J4MID(0000), size);
+}
+
+ACR_NET_EXPORT(jint, Selector, nmax0)(JNI_STDARGS)
{
int nm = 0;
#if HAVE_SYS_RESOURCE_H
@@ -117,18 +134,7 @@ ACR_NET_EXPORT(jint, Pollset, nmax0)(JNI
return nm;
}
-ACR_NET_EXPORT(jobject, Pollset, new0)(JNI_STDARGS, jint size)
-{
- if (_clazzn.u == 1)
- return (*env)->NewObject(env, _clazzn.i, J4MID(0000), size);
- if (AcrLoadClass(env, &_clazzn, 0) == JNI_FALSE)
- return 0;
- R_LOAD_METHOD(0000, 0);
- _clazzn.u = 1;
- return (*env)->NewObject(env, _clazzn.i, J4MID(0000), size);
-}
-
-ACR_UNX_EXPORT(jlong, PollsetImpl, create0)(JNI_STDARGS, jint size)
+ACR_UNX_EXPORT(jlong, SelectorImpl, create0)(JNI_STDARGS, jint size)
{
int rc;
acr_pollset_t *ps;
@@ -180,7 +186,7 @@ cleanup:
return 0;
}
-ACR_UNX_EXPORT(void, PollsetImpl, destroy0)(JNI_STDARGS, jlong pollset)
+ACR_UNX_EXPORT(void, SelectorImpl, destroy0)(JNI_STDARGS, jlong pollset)
{
int i;
acr_pollset_t *ps = J2P(pollset, acr_pollset_t *);
@@ -219,8 +225,8 @@ ACR_UNX_EXPORT(void, PollsetImpl, destro
AcrFree(ps);
}
-ACR_UNX_EXPORT(jint, PollsetImpl, clear0)(JNI_STDARGS, jlong pollset,
- jobjectArray rs)
+ACR_UNX_EXPORT(jint, SelectorImpl, clear0)(JNI_STDARGS, jlong pollset,
+ jobject rsa)
{
int i;
int cnt = 0;
@@ -248,8 +254,12 @@ ACR_UNX_EXPORT(jint, PollsetImpl, clear0
return 0;
}
}
+ for (i = 1; i < ps->used; i++, cnt++) {
+ if (AcrArrayListAdd(env, rsa, ps->ooset[i].obj) != 0)
+ break;
+ }
for (i = 1; i < ps->used; i++) {
- (*env)->SetObjectArrayElement(env, rs, cnt++, ps->ooset[i].obj);
+ /* Unref the container. */
(*env)->DeleteGlobalRef(env, ps->ooset[i].obj);
}
ps->used = 1;
@@ -257,7 +267,7 @@ ACR_UNX_EXPORT(jint, PollsetImpl, clear0
return cnt;
}
-ACR_UNX_EXPORT(void, PollsetImpl, wakeup0)(JNI_STDARGS, jlong pollset)
+ACR_UNX_EXPORT(void, SelectorImpl, wakeup0)(JNI_STDARGS, jlong pollset)
{
acr_pollset_t *ps = J2P(pollset, acr_pollset_t *);
@@ -270,9 +280,9 @@ ACR_UNX_EXPORT(void, PollsetImpl, wakeup
pthread_mutex_unlock(&ps->mutex);
}
-ACR_UNX_EXPORT(jint, PollsetImpl, wait0)(JNI_STDARGS, jlong pollset, jobjectArray rs,
- jshortArray revents, jint timeout,
- jboolean rmsignaled)
+ACR_UNX_EXPORT(jint, SelectorImpl, wait0)(JNI_STDARGS, jlong pollset,
+ jobjectArray rs, jshortArray revents,
+ jint timeout, jboolean rmsignaled)
{
int i, ns, rc = 0;
int rv = 0;
@@ -428,8 +438,8 @@ ACR_UNX_EXPORT(jint, PollsetImpl, wait0)
return rv;
}
-ACR_UNX_EXPORT(jint, PollsetImpl, add0)(JNI_STDARGS, jlong pollset, jobject fo,
- jint f, jint events, jint ttlms)
+ACR_UNX_EXPORT(jint, SelectorImpl, add0)(JNI_STDARGS, jlong pollset, jobject fo,
+ jint f, jint events, jint ttlms)
{
int i, rc = 0;
acr_pollset_t *ps = J2P(pollset, acr_pollset_t *);
@@ -487,8 +497,8 @@ cleanup:
return rc;
}
-ACR_UNX_EXPORT(jint, PollsetImpl, del0)(JNI_STDARGS, jlong pollset, jobject fo,
- jint f)
+ACR_UNX_EXPORT(jint, SelectorImpl, del0)(JNI_STDARGS, jlong pollset,
+ jobject fo, jint f)
{
int i, rc = ACR_EOF;
acr_pollset_t *ps = J2P(pollset, acr_pollset_t *);
@@ -529,6 +539,8 @@ cleanup:
return rc;
}
+#endif /* POLLSET_USE_POLL */
+
ACR_NET_EXPORT(jint, Poll, wait0)(JNI_STDARGS, jintArray fdset,
jshortArray events, jshortArray revents,
jint nevents, jint timeout)
Modified: commons/sandbox/runtime/trunk/src/main/native/shared/array.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/shared/array.c?rev=1128327&r1=1128326&r2=1128327&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/shared/array.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/shared/array.c Fri May 27 14:42:12 2011
@@ -54,9 +54,13 @@ ACR_CLASS_DTOR(ArrayList)
int
AcrArrayListAdd(JNI_STDARGS, jobject e)
{
- int rv = 0;
+ int rv = ACR_EINIT;
if (CLAZZ_LOADED) {
- rv = CALL_METHOD1(Boolean, 0000, obj, e);
+ CALL_METHOD1(Boolean, 0000, obj, e);
+ if ((*env)->ExceptionCheck(env) == JNI_TRUE)
+ rv = ACR_EGENERAL;
+ else
+ rv = 0;
}
return rv;
}