harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From regi...@apache.org
Subject svn commit: r774685 - /harmony/enhanced/classlib/trunk/modules/nio/src/main/java/common/org/apache/harmony/nio/internal/SelectorImpl.java
Date Thu, 14 May 2009 08:39:07 GMT
Author: regisxu
Date: Thu May 14 08:39:07 2009
New Revision: 774685

URL: http://svn.apache.org/viewvc?rev=774685&view=rev
Log:
Apply patch for HARMONY-6085: [eut][classlib][nio] - modKey in SelectorImpl should set the
new index key to the changed selectionkey

Modified:
    harmony/enhanced/classlib/trunk/modules/nio/src/main/java/common/org/apache/harmony/nio/internal/SelectorImpl.java

Modified: harmony/enhanced/classlib/trunk/modules/nio/src/main/java/common/org/apache/harmony/nio/internal/SelectorImpl.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/common/org/apache/harmony/nio/internal/SelectorImpl.java?rev=774685&r1=774684&r2=774685&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/nio/src/main/java/common/org/apache/harmony/nio/internal/SelectorImpl.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/nio/src/main/java/common/org/apache/harmony/nio/internal/SelectorImpl.java
Thu May 14 08:39:07 2009
@@ -153,7 +153,7 @@
         }
     }
 
-    private void ensureCapacity(int c) {
+    private void ensureCommonCapacity(int c) {
         // TODO: rewrite array handling as some internal class
         if (c >= keys.length) {
             SelectionKey[] newKeys = new SelectionKey[(keys.length + 1) << 1];
@@ -175,13 +175,6 @@
             keysToWritableFDs = newKeysToWritableFDs;
         }
 
-        if (readableKeysCount >= readableFDs.length) {
-            FileDescriptor[] newReadableFDs = new FileDescriptor[(readableFDs.length + 1)
<< 1];
-            System.arraycopy(readableFDs, 0, newReadableFDs, 0,
-                    readableFDs.length);
-            readableFDs = newReadableFDs;
-        }
-
         if (readableKeysCount >= readableFDsToKeys.length) {
             int[] newReadableFDsToKeys = new int[(readableFDsToKeys.length + 1) <<
1];
             System.arraycopy(readableFDsToKeys, 0, newReadableFDsToKeys, 0,
@@ -189,19 +182,33 @@
             readableFDsToKeys = newReadableFDsToKeys;
         }
 
-        if (writableKeysCount >= writableFDs.length) {
-            FileDescriptor[] newWriteableFDs = new FileDescriptor[(writableFDs.length + 1)
<< 1];
-            System.arraycopy(writableFDs, 0, newWriteableFDs, 0,
-                    writableFDs.length);
-            writableFDs = newWriteableFDs;
-        }
-
         if (writableKeysCount >= writableFDsToKeys.length) {
             int[] newWritableFDsToKeys = new int[(writableFDsToKeys.length + 1) <<
1];
             System.arraycopy(writableFDsToKeys, 0, newWritableFDsToKeys, 0,
                     writableFDsToKeys.length);
             writableFDsToKeys = newWritableFDsToKeys;
         }
+
+    }
+
+    // prepare the space specified for the READ ops
+    private void ensureReadCapacity(int c) {
+        if (readableKeysCount >= readableFDs.length) {
+            FileDescriptor[] newReadableFDs = new FileDescriptor[(readableFDs.length + 1)
<< 1];
+            System.arraycopy(readableFDs, 0, newReadableFDs, 0,
+                    readableFDs.length);
+            readableFDs = newReadableFDs;
+        }
+    }
+
+    // prepare the space specified for the WRITE ops
+    private void ensureWriteCapacity(int c) {
+        if (writableKeysCount >= writableFDs.length) {
+            FileDescriptor[] newWriteableFDs = new FileDescriptor[(writableFDs.length + 1)
<< 1];
+            System.arraycopy(writableFDs, 0, newWriteableFDs, 0,
+                    writableFDs.length);
+            writableFDs = newWriteableFDs;
+        }
     }
 
     private void limitCapacity() {
@@ -221,7 +228,7 @@
         int c = lastKeyIndex;
 
         // make sure that enough space is available
-        ensureCapacity(c);
+        ensureCommonCapacity(c);
 
         // add to keys storage
         keys[c] = sk;
@@ -236,6 +243,7 @@
 
         // if readable operations requested
         if (((SelectionKey.OP_ACCEPT | SelectionKey.OP_READ) & ops) != 0) {
+            ensureReadCapacity(c);
             // save as readable FD
             readableFDs[readableKeysCount] = fd;
 
@@ -248,6 +256,7 @@
 
         // if writable operations requested
         if (((SelectionKey.OP_CONNECT | SelectionKey.OP_WRITE) & ops) != 0) {
+            ensureWriteCapacity(c);
             // save as writable FD
             writableFDs[writableKeysCount] = fd;
 
@@ -363,7 +372,8 @@
             synchronized (keysSet) {
                 synchronized (selectedKeys) {
                     delKey(sk);
-                    addKey(sk);
+                    int newIndex = addKey(sk);
+                    ((SelectionKeyImpl)sk).setIndex(newIndex);
                 }
             }
         }



Mime
View raw message