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/06/09 07:29:26 UTC
svn commit: r1133657 - in /commons/sandbox/runtime/trunk/src/main:
java/org/apache/commons/runtime/io/ java/org/apache/commons/runtime/net/
native/include/acr/ native/shared/
Author: mturk
Date: Thu Jun 9 05:29:25 2011
New Revision: 1133657
URL: http://svn.apache.org/viewvc?rev=1133657&view=rev
Log:
Add Descriptor attachment. Might be go off in later versions
Modified:
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/Descriptor.java
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/LocalDescriptor.java
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/LocalEndpoint.java
commons/sandbox/runtime/trunk/src/main/native/include/acr/descriptor.h
commons/sandbox/runtime/trunk/src/main/native/shared/descriptor.c
Modified: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/Descriptor.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/Descriptor.java?rev=1133657&r1=1133656&r2=1133657&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/Descriptor.java (original)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/Descriptor.java Thu Jun 9 05:29:25 2011
@@ -38,7 +38,10 @@ public abstract class Descriptor impleme
/** Operating system descriptor.
*/
- protected int fd;
+ protected int fd;
+ /** Descriptor context.
+ */
+ protected Object ad;
/**
* Creates a new object.
@@ -46,6 +49,7 @@ public abstract class Descriptor impleme
protected Descriptor()
{
fd = -1;
+ ad = null;
}
private static native void init0();
@@ -146,6 +150,28 @@ public abstract class Descriptor impleme
}
/**
+ * Get this descriptor's context.
+ * @return descriptor context.
+ */
+ public final Object attachment()
+ {
+ return ad;
+ }
+
+ /**
+ * Attaches the given object to this descriptor.
+ *
+ * @return the previously attached descriptor context, if any,
+ * otherwise {@code null}.
+ */
+ public final Object attach(Object ctx)
+ {
+ Object org = ad;
+ ad = ctx;
+ return org;
+ }
+
+ /**
* Compares this {@code Descriptor} to the specified object.
*
* @param other a {@code Descriptor}
Modified: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/LocalDescriptor.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/LocalDescriptor.java?rev=1133657&r1=1133656&r2=1133657&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/LocalDescriptor.java (original)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/LocalDescriptor.java Thu Jun 9 05:29:25 2011
@@ -44,7 +44,7 @@ final class LocalDescriptor extends Desc
private static native boolean isBlocking0(int fd)
throws IOException;
- private boolean xclosed = false;
+ private boolean xclosed = false;
public LocalDescriptor()
{
Modified: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/LocalEndpoint.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/LocalEndpoint.java?rev=1133657&r1=1133656&r2=1133657&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/LocalEndpoint.java (original)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/LocalEndpoint.java Thu Jun 9 05:29:25 2011
@@ -25,6 +25,8 @@ import java.io.SyncFailedException;
import java.net.SocketException;
import org.apache.commons.runtime.io.ClosedDescriptorException;
import org.apache.commons.runtime.io.Descriptor;
+import org.apache.commons.runtime.io.OperationInProgressException;
+import org.apache.commons.runtime.io.OperationWouldBlockException;
import org.apache.commons.runtime.Errno;
import org.apache.commons.runtime.Status;
import org.apache.commons.runtime.OverflowException;
@@ -78,8 +80,13 @@ public class LocalEndpoint extends Endpo
sd.create(SocketType.STREAM);
int rc = connect0(sd.fd(), endpoint.sockaddr(), timeout);
if (rc != 0) {
+ // XXX: Should exception throwing go inside native?
if (Status.IS_TIMEUP(rc))
throw new TimeoutException();
+ else if (Status.IS_EAGAIN(rc))
+ throw new OperationWouldBlockException();
+ else if (Status.IS_EINPROGRESS(rc))
+ throw new OperationInProgressException();
else
throw new IOException(Status.describe(rc));
}
Modified: commons/sandbox/runtime/trunk/src/main/native/include/acr/descriptor.h
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/include/acr/descriptor.h?rev=1133657&r1=1133656&r2=1133657&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/include/acr/descriptor.h (original)
+++ commons/sandbox/runtime/trunk/src/main/native/include/acr/descriptor.h Thu Jun 9 05:29:25 2011
@@ -27,6 +27,10 @@ int
AcrGetDescriptorFd(JNI_STDARGS);
int
AcrSetDescriptorFd(JNI_STDARGS, int fd);
+jobject
+AcrGetDescriptorCtx(JNI_STDARGS);
+int
+AcrSetDescriptorCtx(JNI_STDARGS, jobject ob);
#ifdef __cplusplus
}
Modified: commons/sandbox/runtime/trunk/src/main/native/shared/descriptor.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/shared/descriptor.c?rev=1133657&r1=1133656&r2=1133657&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/shared/descriptor.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/shared/descriptor.c Thu Jun 9 05:29:25 2011
@@ -40,6 +40,14 @@ J_DECLARE_F_ID(0000) = {
"I"
};
+J_DECLARE_F_ID(0001) = {
+ INVALID_FIELD_OFFSET,
+ INVALID_FIELD_OFFSET,
+ 0,
+ "ad",
+ "Ljava/lang/Object;"
+};
+
ACR_IO_EXPORT(void, Descriptor, init0)(JNI_STDARGS)
{
@@ -47,7 +55,9 @@ ACR_IO_EXPORT(void, Descriptor, init0)(J
if (_clazzn.i == 0)
return;
V_LOAD_IFIELD(0000);
+ V_LOAD_IFIELD(0001);
UNSAFE_IFIELD(0000);
+ UNSAFE_IFIELD(0001);
_clazzn.u = 1;
}
@@ -88,3 +98,41 @@ AcrSetDescriptorFd(JNI_STDARGS, int fd)
}
return rc;
}
+
+jobject
+AcrGetDescriptorCtx(JNI_STDARGS)
+{
+ jobject ob = 0;
+
+ if (J4FLD_OFF(0001) != INVALID_FIELD_OFFSET) {
+ char *oa = *(char **)obj;
+ if (oa != 0) {
+ char *fa = (oa + J4FLD_PTR(0001));
+ ob = *((jobject *)fa);
+ }
+ }
+ else if (CLAZZ_LOADED) {
+ ob = GET_IFIELD_O(0001, obj);
+ }
+ return ob;
+}
+
+int
+AcrSetDescriptorCtx(JNI_STDARGS, jobject ob)
+{
+ int rc = ACR_EBADF;
+
+ if (J4FLD_OFF(0001) != INVALID_FIELD_OFFSET) {
+ char *oa = *(char **)obj;
+ if (oa != 0) {
+ char *fa = (oa + J4FLD_PTR(0001));
+ *((jobject *)fa) = ob;
+ rc = 0;
+ }
+ }
+ else if (CLAZZ_LOADED) {
+ SET_IFIELD_O(0001, obj, ob);
+ rc = 0;
+ }
+ return rc;
+}