commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mt...@apache.org
Subject svn commit: r1098498 - in /commons/sandbox/runtime/trunk/src/main: java/org/apache/commons/runtime/net/ native/ native/os/unix/ native/os/win32/ native/shared/ test/org/apache/commons/runtime/
Date Mon, 02 May 2011 06:40:27 GMT
Author: mturk
Date: Mon May  2 06:40:27 2011
New Revision: 1098498

URL: http://svn.apache.org/viewvc?rev=1098498&view=rev
Log:
Allow setting Socket to non-blocking mode

Added:
    commons/sandbox/runtime/trunk/src/main/native/os/unix/usock.c   (with props)
Modified:
    commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/DatagramSocketInstance.java
    commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/SocketInstance.java
    commons/sandbox/runtime/trunk/src/main/native/Makefile.unx.in
    commons/sandbox/runtime/trunk/src/main/native/os/unix/util.c
    commons/sandbox/runtime/trunk/src/main/native/os/win32/arch_opts.h
    commons/sandbox/runtime/trunk/src/main/native/os/win32/util.c
    commons/sandbox/runtime/trunk/src/main/native/shared/dsock.c
    commons/sandbox/runtime/trunk/src/main/native/shared/psock.c
    commons/sandbox/runtime/trunk/src/main/native/shared/ssock.c
    commons/sandbox/runtime/trunk/src/main/test/org/apache/commons/runtime/TestString.java

Modified: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/DatagramSocketInstance.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/DatagramSocketInstance.java?rev=1098498&r1=1098497&r2=1098498&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/DatagramSocketInstance.java
(original)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/DatagramSocketInstance.java
Mon May  2 06:40:27 2011
@@ -23,6 +23,7 @@ import java.io.IOException;
 import java.net.DatagramSocket;
 import java.net.DatagramSocketImpl;
 import java.net.SocketException;
+import org.apache.commons.runtime.Status;
 
 public final class DatagramSocketInstance
 {
@@ -38,6 +39,7 @@ public final class DatagramSocketInstanc
 
     private static native FileDescriptor fd0(DatagramSocket s);
     private static native int            nd0(DatagramSocket s);
+    private static native int            nb0(DatagramSocket s, boolean on);
 
     public static FileDescriptor getFileDescriptor(DatagramSocket s)
         throws NullPointerException
@@ -55,4 +57,14 @@ public final class DatagramSocketInstanc
         return nd0(s);
     }
 
+    public static void configureBlocking(DatagramSocket s, boolean on)
+        throws NullPointerException, IOException
+    {
+        if (s == null)
+            throw new NullPointerException();
+        int rc = nb0(s, !on);
+        if (rc != 0)
+            throw new IOException(Status.describe(rc));
+    }
+
 }

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=1098498&r1=1098497&r2=1098498&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 06:40:27 2011
@@ -24,6 +24,7 @@ import java.net.Socket;
 import java.net.SocketImpl;
 import java.net.ServerSocket;
 import java.net.SocketException;
+import org.apache.commons.runtime.Status;
 
 public final class SocketInstance
 {
@@ -41,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            nb0(Socket s, boolean on);
+    private static native int            nb1(ServerSocket s, boolean on);
 
     public static FileDescriptor getFileDescriptor(Socket s)
         throws NullPointerException
@@ -74,4 +77,24 @@ public final class SocketInstance
         return nd1(s);
     }
 
+    public static void configureBlocking(Socket s, boolean on)
+        throws NullPointerException, IOException
+    {
+        if (s == null)
+            throw new NullPointerException();
+        int rc = nb0(s, !on);
+        if (rc != 0)
+            throw new IOException(Status.describe(rc));
+    }
+
+    public static void configureBlocking(ServerSocket s, boolean on)
+        throws NullPointerException, IOException
+    {
+        if (s == null)
+            throw new NullPointerException();
+        int rc = nb1(s, !on);
+        if (rc != 0)
+            throw new IOException(Status.describe(rc));
+    }
+
 }

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=1098498&r1=1098497&r2=1098498&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/Makefile.unx.in (original)
+++ commons/sandbox/runtime/trunk/src/main/native/Makefile.unx.in Mon May  2 06:40:27 2011
@@ -70,6 +70,7 @@ UNIX_SOURCES=\
 	$(TOPDIR)/os/unix/shmem.c \
 	$(TOPDIR)/os/unix/semaphore.c \
 	$(TOPDIR)/os/unix/time.c \
+	$(TOPDIR)/os/unix/usock.c \
 	$(TOPDIR)/os/unix/util.c
 
 BSDX_SOURCES=\

Added: commons/sandbox/runtime/trunk/src/main/native/os/unix/usock.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/unix/usock.c?rev=1098498&view=auto
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/unix/usock.c (added)
+++ commons/sandbox/runtime/trunk/src/main/native/os/unix/usock.c Mon May  2 06:40:27 2011
@@ -0,0 +1,25 @@
+/* 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/error.h"
+#include "acr/iodefs.h"
+#include "acr/socks.h"
+#include "acr/clazz.h"
+#include "acr/iofd.h"
+#include "acr/unsafe.h"
+#include "arch_opts.h"
+#include <poll.h>
+

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

Modified: commons/sandbox/runtime/trunk/src/main/native/os/unix/util.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/unix/util.c?rev=1098498&r1=1098497&r2=1098498&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/unix/util.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/unix/util.c Mon May  2 06:40:27 2011
@@ -121,7 +121,7 @@ AcrNonblock(int fd, int on)
         return ACR_GET_OS_ERROR();
     }
     forg = mode;
-    if (on)
+    if (on != 0)
         mode |=  O_NONBLOCK;
     else
         mode &= ~O_NONBLOCK;

Modified: commons/sandbox/runtime/trunk/src/main/native/os/win32/arch_opts.h
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/win32/arch_opts.h?rev=1098498&r1=1098497&r2=1098498&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/win32/arch_opts.h (original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/win32/arch_opts.h Mon May  2 06:40:27
2011
@@ -235,6 +235,7 @@ ACR_INLINE(void) MsecTimeToFileTime(LPFI
 
 HANDLE  AcrNullPipe(int flags, int fd);
 int     AcrPipePair(HANDLE *rd, HANDLE *wr, int flags, char *name);
+int     AcrNonblock(int sd, int on);
 size_t  wcslcpy(wchar_t *dst, const wchar_t *src, size_t siz);
 size_t  wcslcat(wchar_t *dst, const wchar_t *src, size_t siz);
 const wchar_t *basename_w(const wchar_t *path);

Modified: commons/sandbox/runtime/trunk/src/main/native/os/win32/util.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/win32/util.c?rev=1098498&r1=1098497&r2=1098498&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/win32/util.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/win32/util.c Mon May  2 06:40:27 2011
@@ -319,3 +319,15 @@ AcrPipePair(HANDLE *rd, HANDLE *wr, int 
     return 0;
 }
 
+int
+AcrNonblock(int sd, int on)
+{
+    u_long set = on;
+
+    if (sd == -1)
+        return ACR_EBADF;
+    if (ioctlsocket((SOCKET)sd, FIONBIO, &set) == SOCKET_ERROR)
+        return ACR_GET_NET_ERROR();
+    else
+        return 0;
+}

Modified: commons/sandbox/runtime/trunk/src/main/native/shared/dsock.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/shared/dsock.c?rev=1098498&r1=1098497&r2=1098498&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/shared/dsock.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/shared/dsock.c Mon May  2 06:40:27 2011
@@ -23,6 +23,7 @@
 #include "acr/clazz.h"
 #include "acr/iofd.h"
 #include "acr/unsafe.h"
+#include "arch_opts.h"
 
 J_DECLARE_CLAZZ = {
     INVALID_FIELD_OFFSET,
@@ -32,12 +33,6 @@ J_DECLARE_CLAZZ = {
     "java/net/DatagramSocket"
 };
 
-J_DECLARE_M_ID(0000) = {
-    0,
-    "getImpl",
-    "()Ljava/net/DatagramSocketImpl;"
-};
-
 J_DECLARE_F_ID(0000) = {
     INVALID_FIELD_OFFSET,
     INVALID_FIELD_OFFSET,
@@ -51,7 +46,6 @@ ACR_CLASS_CTOR(DatagramSocket)
     if (AcrLoadClass(env, &_clazzn, 0) == JNI_FALSE)
         return JNI_FALSE;
     J_LOAD_IFIELD(0000);
-    J_LOAD_METHOD(0000);
     UNSAFE_IFIELD(0000);
     _clazzn.u = 1;
     return JNI_TRUE;
@@ -69,12 +63,6 @@ ACR_NET_EXPORT(jboolean, DatagramSocketI
     return JNI_TRUE;
 }
 
-ACR_NET_EXPORT(jobject, DatagramSocketInstance, getImpl0)(JNI_STDARGS, jobject sock)
-{
-    return CALL_METHOD0(Object, 0000, sock);
-
-}
-
 ACR_NET_EXPORT(jobject, DatagramSocketInstance, fd0)(JNI_STDARGS, jobject sock)
 {
     jobject impl = 0;
@@ -113,3 +101,26 @@ ACR_NET_EXPORT(jint, DatagramSocketInsta
     }
     return -1;
 }
+
+ACR_NET_EXPORT(jint, DatagramSocketInstance, nb0)(JNI_STDARGS, jobject sock, jboolean on)
+{
+    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 = AcrGetDatagramSocketImplFd(env, impl);
+        if (fd != 0) {
+            /* Set socket to nonblocking mode if on == JNI_TRUE*/
+            return AcrNonblock(AcrGetFileDescriptorFd(env, fd), on);
+        }
+    }
+    return ACR_EBADF;
+}

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=1098498&r1=1098497&r2=1098498&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 06:40:27 2011
@@ -23,6 +23,7 @@
 #include "acr/clazz.h"
 #include "acr/iofd.h"
 #include "acr/unsafe.h"
+#include "arch_opts.h"
 
 J_DECLARE_CLAZZ = {
     INVALID_FIELD_OFFSET,
@@ -103,3 +104,25 @@ ACR_NET_EXPORT(jint, SocketInstance, nd0
     return -1;
 }
 
+ACR_NET_EXPORT(jint, SocketInstance, nb0)(JNI_STDARGS, jobject sock, jboolean on)
+{
+    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) {
+            /* Set socket to nonblocking mode if on == JNI_TRUE*/
+            return AcrNonblock(AcrGetFileDescriptorFd(env, fd), on);
+        }
+    }
+    return ACR_EBADF;
+}

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=1098498&r1=1098497&r2=1098498&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 06:40:27 2011
@@ -23,6 +23,7 @@
 #include "acr/clazz.h"
 #include "acr/iofd.h"
 #include "acr/unsafe.h"
+#include "arch_opts.h"
 
 J_DECLARE_CLAZZ = {
     INVALID_FIELD_OFFSET,
@@ -93,3 +94,26 @@ ACR_NET_EXPORT(jint, SocketInstance, nd1
     }
     return -1;
 }
+
+ACR_NET_EXPORT(jint, SocketInstance, nb1)(JNI_STDARGS, jobject sock, jboolean on)
+{
+    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) {
+            /* Set socket to nonblocking mode if on == JNI_TRUE*/
+            return AcrNonblock(AcrGetFileDescriptorFd(env, fd), on);
+        }
+    }
+    return ACR_EBADF;
+}

Modified: commons/sandbox/runtime/trunk/src/main/test/org/apache/commons/runtime/TestString.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/test/org/apache/commons/runtime/TestString.java?rev=1098498&r1=1098497&r2=1098498&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/test/org/apache/commons/runtime/TestString.java
(original)
+++ commons/sandbox/runtime/trunk/src/main/test/org/apache/commons/runtime/TestString.java
Mon May  2 06:40:27 2011
@@ -62,8 +62,6 @@ public class TestString extends Assert
         throws Exception
     {
         final char[] ca = Unsafe.getStringChars("string");
-        // bytes 0 .. 3 contains integer[1] (2)
-        // ### Assertion works on LSB machines only
         assertEquals((int)ca[0], 's');
         assertEquals((int)ca[1], 't');
         assertEquals((int)ca[2], 'r');



Mime
View raw message