Correctly determine if a buffer has data or not
authorfhanik <fhanik@13f79535-47bb-0310-9956-ffa450edef68>
Tue, 1 Mar 2011 19:58:55 +0000 (19:58 +0000)
committerfhanik <fhanik@13f79535-47bb-0310-9956-ffa450edef68>
Tue, 1 Mar 2011 19:58:55 +0000 (19:58 +0000)
git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@1076004 13f79535-47bb-0310-9956-ffa450edef68

java/org/apache/tomcat/util/net/SecureNioChannel.java

index c3a9eac..eea9640 100644 (file)
@@ -220,10 +220,10 @@ public class SecureNioChannel extends NioChannel  {
      */
     public void rehandshake(long timeout) throws IOException {
         //validate the network buffers are empty
-        if (netInBuffer.position() > 0) throw new IOException("Network input buffer still contains data. Handshake will fail.");
-        if (netOutBuffer.position() > 0) throw new IOException("Network output buffer still contains data. Handshake will fail.");
-        if (getBufHandler().getReadBuffer().position()>0) throw new IOException("Aplication input buffer still contains data. Data would have been lost.");
-        if (getBufHandler().getWriteBuffer().position()>0) throw new IOException("Aplication output buffer still contains data. Data would have been lost.");
+        if (netInBuffer.position() > 0 && netInBuffer.position()<netInBuffer.limit()) throw new IOException("Network input buffer still contains data. Handshake will fail.");
+        if (netOutBuffer.position() > 0 && netOutBuffer.position()<netOutBuffer.limit()) throw new IOException("Network output buffer still contains data. Handshake will fail.");
+        if (getBufHandler().getReadBuffer().position()>0 && getBufHandler().getReadBuffer().position()<getBufHandler().getReadBuffer().limit()) throw new IOException("Aplication input buffer still contains data. Data would have been lost.");
+        if (getBufHandler().getWriteBuffer().position()>0 && getBufHandler().getWriteBuffer().position()<getBufHandler().getWriteBuffer().limit()) throw new IOException("Aplication output buffer still contains data. Data would have been lost.");
         reset();
         boolean isReadable = true;
         boolean isWriteable = true;