hadoop-common-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rang...@apache.org
Subject svn commit: r701476 - in /hadoop/core/trunk: CHANGES.txt src/core/org/apache/hadoop/net/SocketInputStream.java src/test/org/apache/hadoop/net/TestSocketIOWithTimeout.java
Date Fri, 03 Oct 2008 18:17:58 GMT
Author: rangadi
Date: Fri Oct  3 11:17:57 2008
New Revision: 701476

URL: http://svn.apache.org/viewvc?rev=701476&view=rev
Log:
HADOOP-4325. SocketInputStream.read() should return -1 in case EOF.
(Raghu Angadi)

Modified:
    hadoop/core/trunk/CHANGES.txt
    hadoop/core/trunk/src/core/org/apache/hadoop/net/SocketInputStream.java
    hadoop/core/trunk/src/test/org/apache/hadoop/net/TestSocketIOWithTimeout.java

Modified: hadoop/core/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/hadoop/core/trunk/CHANGES.txt?rev=701476&r1=701475&r2=701476&view=diff
==============================================================================
--- hadoop/core/trunk/CHANGES.txt (original)
+++ hadoop/core/trunk/CHANGES.txt Fri Oct  3 11:17:57 2008
@@ -44,6 +44,9 @@
     HADOOP-4207. Update derby jar file to release 10.4.2 release.
     (Prasad Chakka via dhruba)
 
+    HADOOP-4325. SocketInputStream.read() should return -1 in case EOF.
+    (Raghu Angadi)
+
 Release 0.19.0 - Unreleased
 
   INCOMPATIBLE CHANGES

Modified: hadoop/core/trunk/src/core/org/apache/hadoop/net/SocketInputStream.java
URL: http://svn.apache.org/viewvc/hadoop/core/trunk/src/core/org/apache/hadoop/net/SocketInputStream.java?rev=701476&r1=701475&r2=701476&view=diff
==============================================================================
--- hadoop/core/trunk/src/core/org/apache/hadoop/net/SocketInputStream.java (original)
+++ hadoop/core/trunk/src/core/org/apache/hadoop/net/SocketInputStream.java Fri Oct  3 11:17:57
2008
@@ -113,10 +113,15 @@
      * probably no need to optimize or encourage single byte read.
      */
     byte[] buf = new byte[1];
-    if (read(buf, 0, 1) > 0) {
+    int ret = read(buf, 0, 1);
+    if (ret > 0) {
       return (byte)buf[0];
     }
-    throw new IOException("Could not read from stream");
+    if (ret != -1) {
+      // unexpected
+      throw new IOException("Could not read from stream");
+    }
+    return ret;
   }
 
   public int read(byte[] b, int off, int len) throws IOException {

Modified: hadoop/core/trunk/src/test/org/apache/hadoop/net/TestSocketIOWithTimeout.java
URL: http://svn.apache.org/viewvc/hadoop/core/trunk/src/test/org/apache/hadoop/net/TestSocketIOWithTimeout.java?rev=701476&r1=701475&r2=701476&view=diff
==============================================================================
--- hadoop/core/trunk/src/test/org/apache/hadoop/net/TestSocketIOWithTimeout.java (original)
+++ hadoop/core/trunk/src/test/org/apache/hadoop/net/TestSocketIOWithTimeout.java Fri Oct
 3 11:17:57 2008
@@ -132,12 +132,16 @@
       //make sure the channels are still open
       assertTrue(source.isOpen());
       assertTrue(sink.isOpen());
+
+      out.close();
+      assertFalse(sink.isOpen());
+      
+      // close sink and expect -1 from source.read()
+      assertEquals(-1, in.read());
       
       // make sure close() closes the underlying channel.
       in.close();
       assertFalse(source.isOpen());
-      out.close();
-      assertFalse(sink.isOpen());
       
     } finally {
       if (source != null) {



Mime
View raw message