Socket InputStream.available may return a positive value after shutdown

Jing LV lvjing at linux.vnet.ibm.com
Wed Apr 27 03:13:59 PDT 2011


于 2011-2-22 17:38, Alan Bateman 写道:
> Jing LV wrote:
>> Thanks Alan - any luck till now?
>>
> Yes, it's there:
>
> http://bugs.sun.com/view_bug.do?bug_id=7014860
Hello,

     Currently I don't see any patch available so I am trying to create 
one by myself. I see the problem occurs in 
AbstractPlainSocketImpl.available() and it seems it is design to return 
0 when meed a closed socket - this may not be correct according to the 
spec, thus change it like this. Would someone review please?

diff --git a/src/share/classes/java/net/AbstractPlainSocketImpl.java 
b/src/share/classes/java/net/AbstractPlainSocketImpl.java
index 8b2cc70..ac8cb9b 100644
--- a/src/share/classes/java/net/AbstractPlainSocketImpl.java
+++ b/src/share/classes/java/net/AbstractPlainSocketImpl.java
@@ -457,11 +457,11 @@ abstract class AbstractPlainSocketImpl extends 
SocketImpl
          }

          /*
-         * If connection has been reset then return 0 to indicate
+         * If connection has been reset then return -1 to indicate
           * there are no buffered bytes.
           */
          if (isConnectionReset()) {
-            return 0;
+            return -1;
          }

          /*
@@ -476,6 +476,7 @@ abstract class AbstractPlainSocketImpl extends 
SocketImpl
              n = socketAvailable();
              if (n == 0 && isConnectionResetPending()) {
                  setConnectionReset();
+                n = -1;
              }
          } catch (ConnectionResetException exc1) {
              setConnectionResetPending();
@@ -483,6 +484,7 @@ abstract class AbstractPlainSocketImpl extends 
SocketImpl
                  n = socketAvailable();
                  if (n == 0) {
                      setConnectionReset();
+                    n = -1;
                  }
              } catch (ConnectionResetException exc2) {
              }

-- 
Best Regards,
Jimmy, Jing LV





More information about the net-dev mailing list