commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mt...@apache.org
Subject svn commit: r1131319 - in /commons/sandbox/runtime/trunk/src/main: java/org/apache/commons/runtime/ java/org/apache/commons/runtime/io/ java/org/apache/commons/runtime/net/ native/shared/ test/org/apache/commons/runtime/
Date Sat, 04 Jun 2011 05:51:28 GMT
Author: mturk
Date: Sat Jun  4 05:51:27 2011
New Revision: 1131319

URL: http://svn.apache.org/viewvc?rev=1131319&view=rev
Log:
Misc tweaks

Added:
    commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/Utils.java
  (with props)
Modified:
    commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Errno.java
    commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/Local.java
    commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/AbstractAddress.java
    commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/InetSocketAddress.java
    commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/Local.java
    commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/LocalEndpoint.java
    commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/LocalServerEndpoint.java
    commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/SocketEndpoint.java
    commons/sandbox/runtime/trunk/src/main/native/shared/error.c
    commons/sandbox/runtime/trunk/src/main/test/org/apache/commons/runtime/TestSelectionKey.java

Modified: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Errno.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Errno.java?rev=1131319&r1=1131318&r2=1131319&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Errno.java (original)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Errno.java Sat
Jun  4 05:51:27 2011
@@ -16,6 +16,7 @@
 
 package org.apache.commons.runtime;
 
+import java.io.IOException;
 /**
  * Errno class.
  *
@@ -332,4 +333,27 @@ public final class Errno
      */
     public static native String msg();
 
+    public static native void throw0(int errno, String msg)
+        throws Exception;
+    public static native void throw1(int errno)
+        throws Exception;
+
+    /**
+     * Throws an exception according to the error code.
+     */
+    public static void throwException(int errno, String msg)
+        throws Exception
+    {
+        throw0(errno, msg);
+    }
+
+    /**
+     * Throws an exception according to the error code.
+     */
+    public static void throwException(int errno)
+        throws Exception
+    {
+        throw1(errno);
+    }
+    
 }

Modified: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/Local.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/Local.java?rev=1131319&r1=1131318&r2=1131319&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/Local.java (original)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/Local.java Sat
Jun  4 05:51:27 2011
@@ -17,6 +17,7 @@
 
 
 package org.apache.commons.runtime.io;
+
 import org.apache.commons.runtime.util.StringManager;
 
 /** Io package private constants
@@ -30,4 +31,5 @@ class Local
     static {
         sm = StringManager.getManager(Package);
     }
+
 }

Modified: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/AbstractAddress.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/AbstractAddress.java?rev=1131319&r1=1131318&r2=1131319&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/AbstractAddress.java
(original)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/AbstractAddress.java
Sat Jun  4 05:51:27 2011
@@ -23,11 +23,11 @@ package org.apache.commons.runtime.net;
  */
 final class AbstractAddress extends EndpointAddress
 {
-    public static final int            SALEN;
-    private static native int           size0();
+    public  static final  int   SIZE;
+    private static native int   size0();
 
     static {
-        SALEN = size0();
+        SIZE = size0();
     }
 
     /**
@@ -58,4 +58,9 @@ final class AbstractAddress extends Endp
         return e.sa;
     }
 
+    public static byte[] alloc()
+    {
+        return new byte[SIZE];
+    }
+
 }

Modified: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/InetSocketAddress.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/InetSocketAddress.java?rev=1131319&r1=1131318&r2=1131319&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/InetSocketAddress.java
(original)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/InetSocketAddress.java
Sat Jun  4 05:51:27 2011
@@ -59,7 +59,7 @@ public class InetSocketAddress extends S
     {        
         if (port < 0 || port > 65535)
             throw new InvalidRangeException(Local.sm.get("port.ERANGE"));
-        int salen = AbstractAddress.SALEN;
+        int salen = AbstractAddress.SIZE;
         byte[] sa = AbstractSocketAddress.getnameinfo(AddressFamily.UNSPEC, hostname, null,
port);
         int naddr = sa.length / salen;
         SocketAddress[] a = new SocketAddress[naddr];

Modified: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/Local.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/Local.java?rev=1131319&r1=1131318&r2=1131319&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/Local.java
(original)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/Local.java
Sat Jun  4 05:51:27 2011
@@ -17,6 +17,7 @@
 
 
 package org.apache.commons.runtime.net;
+
 import org.apache.commons.runtime.util.StringManager;
 
 /** Net package private constants
@@ -30,4 +31,5 @@ class Local
     static {
         sm = StringManager.getManager(Package);
     }
+
 }

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=1131319&r1=1131318&r2=1131319&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
Sat Jun  4 05:51:27 2011
@@ -25,8 +25,10 @@ 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.OverflowException;
+import org.apache.commons.runtime.Errno;
 import org.apache.commons.runtime.Status;
+import org.apache.commons.runtime.OverflowException;
+import org.apache.commons.runtime.TimeoutException;
 
 /**
  * This class represents a local endpoint.
@@ -77,8 +79,12 @@ public class LocalEndpoint extends Endpo
         if (sd.closed())
             sd.create(SocketType.STREAM);
         int rc = connect0(sd.fd(), endpoint.sockaddr(), timeout);
-        if (rc != 0)
-            throw new IOException(Status.describe(rc));
+        if (rc != 0) {
+            if (Status.IS_TIMEUP(rc))
+                throw new TimeoutException();
+            else
+                throw new IOException(Status.describe(rc));
+        }
     }
 
     public final void connect(EndpointAddress endpoint)
@@ -114,7 +120,7 @@ public class LocalEndpoint extends Endpo
             return sd;
         int rc = nonblock0(sd.fd(), block);
         if (rc != 0)
-            throw new SocketException(Status.describe(rc));
+            throw new IOException(Status.describe(rc));
         blocking = block;
         return sd;
     }
@@ -157,7 +163,6 @@ public class LocalEndpoint extends Endpo
                OverflowException,
                IOException
     {
-        ops = ops & 0x000f;
         if (sd.closed())
             throw new ClosedDescriptorException();
         AbstractSelector sel = (AbstractSelector)selector;
@@ -171,7 +176,7 @@ public class LocalEndpoint extends Endpo
             throw new IllegalSelectorException();
         if (att != null)
             key.attach(att);
-        return key.queue(ops);
+        return key.queue(ops & 0x000f);
     }
 
 }

Modified: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/LocalServerEndpoint.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/LocalServerEndpoint.java?rev=1131319&r1=1131318&r2=1131319&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/LocalServerEndpoint.java
(original)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/LocalServerEndpoint.java
Sat Jun  4 05:51:27 2011
@@ -177,7 +177,7 @@ public class LocalServerEndpoint extends
     {
         if (sd.closed())
             throw new ClosedDescriptorException();
-        byte[] addr = new byte[AbstractAddress.SALEN];
+        byte[] addr = AbstractAddress.alloc();
 
         int fd = accept0(sd.fd(), addr);
         LocalDescriptor ad = new LocalDescriptor(fd);

Modified: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/SocketEndpoint.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/SocketEndpoint.java?rev=1131319&r1=1131318&r2=1131319&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/SocketEndpoint.java
(original)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/SocketEndpoint.java
Sat Jun  4 05:51:27 2011
@@ -146,7 +146,6 @@ public class SocketEndpoint extends Endp
                OverflowException,
                IOException
     {
-        ops = ops & 0x000f;
         if (sd.closed())
             throw new ClosedDescriptorException();
         AbstractSelector sel = (AbstractSelector)selector;
@@ -160,7 +159,7 @@ public class SocketEndpoint extends Endp
             throw new IllegalSelectorException();
         if (att != null)
             key.attach(att);
-        return key.queue(ops);
+        return key.queue(ops &  0x000f);
     }
 
 }

Added: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/Utils.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/Utils.java?rev=1131319&view=auto
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/Utils.java
(added)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/Utils.java
Sat Jun  4 05:51:27 2011
@@ -0,0 +1,30 @@
+/*
+ * 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.
+ */
+
+
+package org.apache.commons.runtime.net;
+
+import java.io.IOException;
+
+public final class Utils
+{
+    private Utils()
+    {
+        // No instance.
+    }
+
+}

Propchange: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/Utils.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: commons/sandbox/runtime/trunk/src/main/native/shared/error.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/shared/error.c?rev=1131319&r1=1131318&r2=1131319&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/shared/error.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/shared/error.c Sat Jun  4 05:51:27 2011
@@ -751,6 +751,7 @@ void
 AcrThrowByError(JNI_STDENV, int def, int err, const char *msg)
 {
     int cls = def;
+    const char *str = 0;
 
     if (ACR_STATUS_IS_EEXIST(err))
         cls = ACR_EX_EEXIST;
@@ -782,7 +783,11 @@ AcrThrowByError(JNI_STDENV, int def, int
         cls = ACR_EX_EBADF;
     else if (err == ACR_EOVERFLOW)
         cls = ACR_EX_EOVERFLOW;
-    AcrThrow(env, cls, msg);
+    else if (err == ACR_ETIMEDOUT)
+        cls = ACR_EX_TIMEOUT;
+    else
+        str = msg;
+    AcrThrow(env, cls, str);
 }
 
 ACR_JNI_EXPORT(jint, Status, init0)(JNI_STDARGS)
@@ -931,7 +936,7 @@ ACR_JNI_EXPORT(jboolean, Status, is0)(JN
                 rv = JNI_TRUE;
         break;
         case 7:
-            if (ACR_STATUS_IS_TIMEUP(err))
+            if (ACR_STATUS_IS_TIMEUP(err) || err == ACR_ETIMEDOUT)
                 rv = JNI_TRUE;
         break;
         default:
@@ -952,3 +957,19 @@ ACR_JNI_EXPORT(jstring, Errno, msg)(JNI_
     _cr_strerror_r(AcrGetThreadError(), buf, ACR_MBUFF_SIZ);
     return AcrNewJavaStringA(env, buf);
 }
+
+ACR_JNI_EXPORT(void, Errno, throw0)(JNI_STDARGS, jint err, jstring msg)
+{
+    WITH_CSTR(msg) {
+        AcrThrowByError(env, ACR_EX_ESYS, err, J2S(msg));
+    } DONE_WITH_STR(msg);
+
+}
+
+ACR_JNI_EXPORT(void, Errno, throw1)(JNI_STDARGS, jint err)
+{
+    char msg[ACR_MBUFF_SIZ] = "";
+
+    _cr_strerror_r(err, msg, ACR_MBUFF_SIZ);
+    AcrThrowByError(env, ACR_EX_ESYS, err, msg);
+}

Modified: commons/sandbox/runtime/trunk/src/main/test/org/apache/commons/runtime/TestSelectionKey.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/test/org/apache/commons/runtime/TestSelectionKey.java?rev=1131319&r1=1131318&r2=1131319&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/test/org/apache/commons/runtime/TestSelectionKey.java
(original)
+++ commons/sandbox/runtime/trunk/src/main/test/org/apache/commons/runtime/TestSelectionKey.java
Sat Jun  4 05:51:27 2011
@@ -20,6 +20,7 @@ import java.io.IOException;
 import java.net.SocketException;
 import org.testng.annotations.*;
 import org.testng.Assert;
+import org.apache.commons.runtime.Errno;
 
 public class TestSelectionKey extends Assert
 {



Mime
View raw message