incubator-deft-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jmee...@apache.org
Subject svn commit: r1165679 - /incubator/deft/sandbox/src/main/java/org/apache/deft/io/AsynchronousSocket.java
Date Tue, 06 Sep 2011 14:15:13 GMT
Author: jmeehan
Date: Tue Sep  6 14:15:12 2011
New Revision: 1165679

URL: http://svn.apache.org/viewvc?rev=1165679&view=rev
Log:
DEFT-170 - Close channel on EOF read/empty write.

Modified:
    incubator/deft/sandbox/src/main/java/org/apache/deft/io/AsynchronousSocket.java

Modified: incubator/deft/sandbox/src/main/java/org/apache/deft/io/AsynchronousSocket.java
URL: http://svn.apache.org/viewvc/incubator/deft/sandbox/src/main/java/org/apache/deft/io/AsynchronousSocket.java?rev=1165679&r1=1165678&r2=1165679&view=diff
==============================================================================
--- incubator/deft/sandbox/src/main/java/org/apache/deft/io/AsynchronousSocket.java (original)
+++ incubator/deft/sandbox/src/main/java/org/apache/deft/io/AsynchronousSocket.java Tue Sep
 6 14:15:12 2011
@@ -193,12 +193,8 @@ public class AsynchronousSocket implemen
     @Override
     public void handleRead(SelectionKey key) throws IOException {
         logger.debug("handle read...");
-        ByteBuffer buffer = ByteBuffer.allocate(DEFAULT_BYTEBUFFER_SIZE); // TODO
-                                                                          // RS
-                                                                          // 110723
-                                                                          // reuse
-                                                                          // byte
-                                                                          // buffers
+        ByteBuffer buffer = ByteBuffer.allocate(DEFAULT_BYTEBUFFER_SIZE);
+        // TODO RS 110723 reuse byte buffers
         int read = 0;
         try {
             read = channel.read(buffer);
@@ -212,6 +208,10 @@ public class AsynchronousSocket implemen
         if (read == -1) { // EOF
             reachedEOF = true;
             ioLoop.updateHandler(channel, interestOps &= ~SelectionKey.OP_READ);
+            if (writeBuffer.position() == 0) {
+                invokeCloseCallback();
+            }
+
             return;
         }
         buffer.flip();
@@ -287,13 +287,11 @@ public class AsynchronousSocket implemen
         readBuffer.flip();
         byte[] result = new byte[size];
         readBuffer.get(result, 0, size);
-        readBuffer.position(readBuffer.position() + advance); // ignore the
-                                                              // delimiter (if
-                                                              // it was a
-                                                              // readUntil(..)
-                                                              // call)
-        readBuffer.compact(); // "delete" the result data (data after result is
-                              // left intact and will not be overwritten)
+        // ignore the delimiter (if it was a readUntil(..) call)
+        readBuffer.position(readBuffer.position() + advance);
+        // "delete" the result data (data after result is left intact and will
+        // not be overwritten)
+        readBuffer.compact();
         logger.debug("readBuffer size: {}", readBuffer.position());
         return result;
     }
@@ -357,8 +355,8 @@ public class AsynchronousSocket implemen
             if (channel.isConnected()) {
                 writeBuffer.flip(); // prepare for write
                 written = channel.write(writeBuffer.getByteBuffer());
-                writeBuffer.compact(); // // make room for more data be "read"
-                                       // in
+                // make room for more data be "read" in
+                writeBuffer.compact(); 
             }
         } catch (IOException e) {
             logger.error("IOException during write: {}", e.getMessage());
@@ -376,4 +374,4 @@ public class AsynchronousSocket implemen
         }
     }
 
-}
+}
\ No newline at end of file



Mime
View raw message