commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mt...@apache.org
Subject svn commit: r1098553 - in /commons/sandbox/runtime/trunk/src/main: java/org/apache/commons/runtime/net/SocketInstance.java native/shared/psock.c native/shared/ssock.c
Date Mon, 02 May 2011 13:20:32 GMT
Author: mturk
Date: Mon May  2 13:20:32 2011
New Revision: 1098553

URL: http://svn.apache.org/viewvc?rev=1098553&view=rev
Log:
Add native socket descriptor setter

Modified:
    commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/SocketInstance.java
    commons/sandbox/runtime/trunk/src/main/native/shared/psock.c
    commons/sandbox/runtime/trunk/src/main/native/shared/ssock.c

Modified: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/SocketInstance.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/SocketInstance.java?rev=1098553&r1=1098552&r2=1098553&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/SocketInstance.java
(original)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/SocketInstance.java
Mon May  2 13:20:32 2011
@@ -42,6 +42,8 @@ public final class SocketInstance
     private static native FileDescriptor fd1(ServerSocket s);
     private static native int            nd0(Socket s);
     private static native int            nd1(ServerSocket s);
+    private static native int            sd0(Socket s, int d);
+    private static native int            sd1(ServerSocket s, int d);
     private static native int            nb0(Socket s, boolean on);
     private static native int            nb1(ServerSocket s, boolean on);
 
@@ -77,6 +79,26 @@ public final class SocketInstance
         return nd1(s);
     }
 
+    public static void setNativeDescriptor(Socket s, int desc)
+        throws IllegalArgumentException, IOException
+    {
+        if (s == null)
+            throw new IllegalArgumentException();
+        int rc = sd0(s, desc);
+        if (rc != 0)
+            throw new IOException(Status.describe(rc));
+    }
+
+    public static void setNativeDescriptor(ServerSocket s, int desc)
+        throws IllegalArgumentException, IOException
+    {
+        if (s == null)
+            throw new IllegalArgumentException();
+        int rc = sd1(s, desc);
+        if (rc != 0)
+            throw new IOException(Status.describe(rc));
+    }
+
     public static void configureBlocking(Socket s, boolean on)
         throws IllegalArgumentException, IOException
     {

Modified: commons/sandbox/runtime/trunk/src/main/native/shared/psock.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/shared/psock.c?rev=1098553&r1=1098552&r2=1098553&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/shared/psock.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/shared/psock.c Mon May  2 13:20:32 2011
@@ -104,6 +104,27 @@ ACR_NET_EXPORT(jint, SocketInstance, nd0
     return -1;
 }
 
+ACR_NET_EXPORT(jint, SocketInstance, sd0)(JNI_STDARGS, jobject sock, jint sd)
+{
+    jobject impl = 0;
+    jobject fd;
+
+    if (J4FLD_OFF(0000) != INVALID_FIELD_OFFSET) {
+        char *oa = *(char **)sock;
+        if (oa != 0)
+            impl = (jobject)(oa + J4FLD_PTR(0000));
+    }
+    else if (CLAZZ_LOADED) {
+        impl = GET_IFIELD_O(0000, sock);
+    }
+    if (impl != 0) {
+        fd = AcrGetSocketImplFd(env, impl);
+        if (fd != 0)
+            return AcrSetFileDescriptorFd(env, fd, sd);
+    }
+    return ACR_EBADF;
+}
+
 ACR_NET_EXPORT(jint, SocketInstance, nb0)(JNI_STDARGS, jobject sock, jboolean on)
 {
     jobject impl = 0;

Modified: commons/sandbox/runtime/trunk/src/main/native/shared/ssock.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/shared/ssock.c?rev=1098553&r1=1098552&r2=1098553&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/shared/ssock.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/shared/ssock.c Mon May  2 13:20:32 2011
@@ -95,6 +95,27 @@ ACR_NET_EXPORT(jint, SocketInstance, nd1
     return -1;
 }
 
+ACR_NET_EXPORT(jint, SocketInstance, sd1)(JNI_STDARGS, jobject sock, jint sd)
+{
+    jobject impl = 0;
+    jobject fd;
+
+    if (J4FLD_OFF(0000) != INVALID_FIELD_OFFSET) {
+        char *oa = *(char **)sock;
+        if (oa != 0)
+            impl = (jobject)(oa + J4FLD_PTR(0000));
+    }
+    else if (CLAZZ_LOADED) {
+        impl = GET_IFIELD_O(0000, sock);
+    }
+    if (impl != 0) {
+        fd = AcrGetSocketImplFd(env, impl);
+        if (fd != 0)
+            return AcrSetFileDescriptorFd(env, fd, sd);
+    }
+    return ACR_EBADF;
+}
+
 ACR_NET_EXPORT(jint, SocketInstance, nb1)(JNI_STDARGS, jobject sock, jboolean on)
 {
     jobject impl = 0;



Mime
View raw message