harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mloe...@apache.org
Subject svn commit: r427074 - in /incubator/harmony/enhanced/classlib/trunk/modules: luni/src/main/java/org/apache/harmony/luni/util/ luni/src/main/native/luni/shared/ nio/src/main/java/org/apache/harmony/nio/internal/
Date Mon, 31 Jul 2006 11:27:32 GMT
Author: mloenko
Date: Mon Jul 31 04:27:32 2006
New Revision: 427074

URL: http://svn.apache.org/viewvc?rev=427074&view=rev
Log:
fixes for HARMONY-815
[classlib][nio] Refine implConfigureBlocking(boolean) method of DatagramChannel and SocketChannel

Added:
    incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/util/ErrorCodeException.java
Modified:
    incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/native/luni/shared/nethelp.c
    incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/org/apache/harmony/nio/internal/DatagramChannelImpl.java
    incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/org/apache/harmony/nio/internal/SocketChannelImpl.java

Added: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/util/ErrorCodeException.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/util/ErrorCodeException.java?rev=427074&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/util/ErrorCodeException.java
(added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/util/ErrorCodeException.java
Mon Jul 31 04:27:32 2006
@@ -0,0 +1,32 @@
+/* Copyright 2006 The Apache Software Foundation or its licensors, as applicable
+ * 
+ * Licensed 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.harmony.luni.util;
+
+public class ErrorCodeException extends Exception {
+
+    private static final long serialVersionUID = -8716868971626579265L;
+   
+    private int errorCode;
+  
+    public ErrorCodeException(int errorCode){
+        this.errorCode = errorCode;
+    }
+    
+    public int getErrorCode(){
+        return errorCode;
+    }
+
+}

Modified: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/native/luni/shared/nethelp.c
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/native/luni/shared/nethelp.c?rev=427074&r1=427073&r2=427074&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/native/luni/shared/nethelp.c
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/native/luni/shared/nethelp.c
Mon Jul 31 04:27:32 2006
@@ -351,7 +351,33 @@
   /* the error message lookup should be done before the FindClass
    * call, because the FindClass call may reset the error number that
    * is used in hysock_error_message */
+  jclass socketExClass,errorCodeExClass;
+  jmethodID errorCodeExConstructor, socketExConstructor,socketExCauseMethod;
+  jobject errorCodeEx,socketEx;
   char *errorMessage = netLookupErrorString (env, errorNumber);
+  if (HYPORT_ERROR_SOCKET_WOULDBLOCK == errorNumber){
+  	   errorCodeExClass = (*env)->FindClass (env, "org/apache/harmony/luni/util/ErrorCodeException");
+  	   if (!errorCodeExClass){
+  	           return;
+  	   }
+  	   errorCodeExConstructor = (*env)->GetMethodID(env,errorCodeExClass,"init","(I)V");
+       if (!errorCodeExConstructor){
+               return;
+       }
+       errorCodeEx = (*env)->NewObject(env, errorCodeExClass,errorCodeExConstructor,errorNumber);
+       socketExClass = (*env)->FindClass (env, "java/net/SocketException");
+  	   if (!socketExClass) {
+  	           return;
+  	   }
+  	   socketExConstructor = (*env)->GetMethodID(env,socketExClass,"init","(Ljava/lang/String;)V");
+       if (!socketExConstructor) {
+               return;
+       }
+       socketEx = (*env)->NewObject(env, socketExClass,errorCodeExConstructor,errorMessage);

+       socketExCauseMethod = (*env)->GetMethodID(env,socketExClass,"initCause","(Ljava/lang/Throwable;)Ljava/lang/Throwable;");
+       (*env)->CallObjectMethod(env,socketEx,socketExCauseMethod,errorCodeEx);
+       (*env)->Throw(env,socketEx);
+  }
   throwNewExceptionByName(env, "java/net/SocketException", errorMessage);
 }
 

Modified: incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/org/apache/harmony/nio/internal/DatagramChannelImpl.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/org/apache/harmony/nio/internal/DatagramChannelImpl.java?rev=427074&r1=427073&r2=427074&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/org/apache/harmony/nio/internal/DatagramChannelImpl.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/org/apache/harmony/nio/internal/DatagramChannelImpl.java
Mon Jul 31 04:27:32 2006
@@ -37,6 +37,7 @@
 import org.apache.harmony.luni.platform.FileDescriptorHandler;
 import org.apache.harmony.luni.platform.INetworkSystem;
 import org.apache.harmony.luni.platform.Platform;
+import org.apache.harmony.luni.util.ErrorCodeException;
 
 
 
@@ -56,10 +57,8 @@
 
     // default timeout used to nonblocking mode.
     private static final int DEFAULT_TIMEOUT = 1;
-
-    // error messages, for native dependent.
-    private static final String ERRMSG_TIMEOUT = "The operation timed out";
-
+    
+    private static final int ERRCODE_SOCKET_NONBLOCKING_WOULD_BLOCK = -211;
 
     // -------------------------------------------------------------------
     // Instance variables
@@ -445,11 +444,8 @@
             }
             return readCount;
         } catch (InterruptedIOException e) {
-            // FIXME improve native code.
-            if (e.getMessage().equals(ERRMSG_TIMEOUT)) {
-                return 0;
-            }
-            throw e;
+            // InterruptedIOException will be thrown when timeout.
+            return 0;
         } finally {
             end(readCount > 0);
         }
@@ -522,6 +518,14 @@
                     length, isBound);
             buf.position(oldposition + result);
             return result;
+        } catch (SocketException e){
+            if (e.getCause() instanceof ErrorCodeException) {
+                if (ERRCODE_SOCKET_NONBLOCKING_WOULD_BLOCK == ((ErrorCodeException) e
+                        .getCause()).getErrorCode()) {
+                    return result;
+                }
+            }
+            throw e;   
         } finally {
             end(result > 0);
         }

Modified: incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/org/apache/harmony/nio/internal/SocketChannelImpl.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/org/apache/harmony/nio/internal/SocketChannelImpl.java?rev=427074&r1=427073&r2=427074&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/org/apache/harmony/nio/internal/SocketChannelImpl.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/org/apache/harmony/nio/internal/SocketChannelImpl.java
Mon Jul 31 04:27:32 2006
@@ -43,6 +43,7 @@
 import org.apache.harmony.luni.platform.FileDescriptorHandler;
 import org.apache.harmony.luni.platform.INetworkSystem;
 import org.apache.harmony.luni.platform.Platform;
+import org.apache.harmony.luni.util.ErrorCodeException;
 import org.apache.harmony.luni.util.Msg;
 
 
@@ -59,7 +60,7 @@
 
     private static final int EOF = -1;
 
-    private static final String ERRMSG_SOCKET_NONBLOCKING_WOULD_BLOCK = "The socket is marked
as nonblocking operation would block";
+    private static final int ERRCODE_SOCKET_NONBLOCKING_WOULD_BLOCK = -211;
 
     // The singleton to do the native network operation.
     static final INetworkSystem networkSystem = Platform.getNetworkSystem();
@@ -277,6 +278,10 @@
                 result = networkSystem.connectWithTimeout(fd, 0, trafficClass,
                         inetSocketAddress.getAddress(), inetSocketAddress
                                 .getPort(), HY_SOCK_STEP_START, connectContext);
+                // set back to nonblocking to work around with a bug in portlib
+                if (!this.isBlocking()){
+                    networkSystem.setNonBlocking(fd, true);
+                }
             }
             finished = (CONNECT_SUCCESS == result);
             isBound = finished;
@@ -501,7 +506,6 @@
         }
         int writeCount = 0;
         try {
-            networkSystem.setNonBlocking(fd, !this.isBlocking());
             int pos = source.position();
             int length = source.remaining();
             if (isBlocking()){
@@ -517,9 +521,13 @@
             }
             source.position(pos + writeCount);
         } catch (SocketException e) {
-            if (!ERRMSG_SOCKET_NONBLOCKING_WOULD_BLOCK.equals(e.getMessage())) {
-                throw e;
-            }            
+            if (e.getCause() instanceof ErrorCodeException) {
+                if (ERRCODE_SOCKET_NONBLOCKING_WOULD_BLOCK == ((ErrorCodeException) e
+                        .getCause()).getErrorCode()) {
+                    return writeCount;
+                }
+            }
+            throw e;
         } finally {
             if (isBlocking()){
                 end(writeCount >= 0);



Mime
View raw message