natPlainSocketImplPosix.cc (read_helper): Handle count == 0 case.
authorDavid Daney <ddaney@avtrex.com>
Tue, 15 Mar 2005 16:46:51 +0000 (16:46 +0000)
committerDavid Daney <daney@gcc.gnu.org>
Tue, 15 Mar 2005 16:46:51 +0000 (16:46 +0000)
2005-03-15  David Daney  <ddaney@avtrex.com>

* gnu/java/net/natPlainSocketImplPosix.cc (read_helper): Handle
count == 0 case.

2005-03-15  David Daney  <ddaney@avtrex.com>

* java/io/BufferedInputStream.java (available): Use 'in' instead
of 'super' for underlying stream access.
(close): Ditto.
(read(byte[], int, int)): Ditto.
(refill): Ditto.
(skip): Call skip on underlying stream when possible.

From-SVN: r96516

libjava/ChangeLog
libjava/gnu/java/net/natPlainSocketImplPosix.cc
libjava/java/io/BufferedInputStream.java

index 8cf4b5361eed8cf30a1c3108f9f0e1422f9b502c..59db600596f6daeb2f8486e5183d87e0affa50ee 100644 (file)
@@ -1,3 +1,17 @@
+2005-03-15  David Daney  <ddaney@avtrex.com>
+
+       * gnu/java/net/natPlainSocketImplPosix.cc (read_helper): Handle
+       count == 0 case.
+
+2005-03-15  David Daney  <ddaney@avtrex.com>
+
+       * java/io/BufferedInputStream.java (available): Use 'in' instead
+       of 'super' for underlying stream access.
+       (close): Ditto.
+       (read(byte[], int, int)): Ditto.
+       (refill): Ditto.
+       (skip): Call skip on underlying stream when possible. 
+
 2005-03-12  Andreas Tobler  <a.tobler@schweiz.ch>
 
        * stacktrace.cc (GetCallerInfo): Return nothing in case of
index 46b56bb6efbf3cfb8f4ba278a93529d2cb8e2aa2..3f1dde9f5a2985b50b13d553d858f47219d54cb4 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (C) 2003, 2004  Free Software Foundation
+/* Copyright (C) 2003, 2004, 2005  Free Software Foundation
 
    This file is part of libgcj.
 
@@ -405,6 +405,11 @@ gnu::java::net::PlainSocketImpl$SocketInputStream::read(jbyteArray buffer, jint
 static jint
 read_helper (jint native_fd, jint timeout, jbyte *bytes, jint count)
 {
+  // If zero bytes were requested, short circuit so that recv
+  // doesn't signal EOF.
+  if (count == 0)
+    return 0;
+    
   // Do timeouts via select.
   if (timeout > 0 && native_fd >= 0 && native_fd < FD_SETSIZE)
     {
index bbb38c4371995c37be7994bb12c95077db56ab6b..ce166b337f4aed9eac9117b24de5b96f85c26696 100644 (file)
@@ -158,7 +158,7 @@ public class BufferedInputStream extends FilterInputStream
    */
   public synchronized int available() throws IOException
   {
-    return count - pos + super.available();
+    return count - pos + in.available();
   }
 
   /**
@@ -173,7 +173,7 @@ public class BufferedInputStream extends FilterInputStream
     buf = null;
     pos = count = 0;
     markpos = -1;
-    super.close();
+    in.close();
   }
 
   /**
@@ -273,7 +273,7 @@ public class BufferedInputStream extends FilterInputStream
     off += totalBytesRead;
     len -= totalBytesRead;
 
-    while (len > 0 && super.available() > 0 && refill())
+    while (len > 0 && in.available() > 0 && refill())
       {
        int remain = Math.min(count - pos, len);
        System.arraycopy(buf, pos, b, off, remain);
@@ -327,8 +327,18 @@ public class BufferedInputStream extends FilterInputStream
 
     while (n > 0L)
       {
-       if (pos >= count && !refill())
-          break;
+       if (pos >= count)
+          {
+            if (markpos == -1)
+              {
+                // Buffer is empty and no mark is set, skip on the
+                // underlying stream.
+                n -= in.skip(n);
+                break;
+              }
+            else if (!refill())
+              break;
+          }
 
        int numread = (int) Math.min((long) (count - pos), n);
        pos += numread;
@@ -369,7 +379,7 @@ public class BufferedInputStream extends FilterInputStream
        markpos = 0;
       }
 
-    int numread = super.read(buf, count, bufferSize);
+    int numread = in.read(buf, count, bufferSize);
 
     if (numread <= 0)  // EOF
       return false;