src/jdk.incubator.httpclient/share/classes/jdk/incubator/http/internal/frame/FramesDecoder.java
branchhttp-client-branch
changeset 55950 5e1707e5a254
parent 55948 33ffdf2f703e
child 55973 4d9b002587db
--- a/src/jdk.incubator.httpclient/share/classes/jdk/incubator/http/internal/frame/FramesDecoder.java	Mon Dec 04 16:54:26 2017 +0000
+++ b/src/jdk.incubator.httpclient/share/classes/jdk/incubator/http/internal/frame/FramesDecoder.java	Tue Dec 05 10:07:50 2017 +0000
@@ -75,6 +75,7 @@
     private int frameType;
     private int frameFlags;
     private int frameStreamid;
+    private boolean closed;
 
     /**
      * Creates Frame Decoder
@@ -109,6 +110,12 @@
      * decoded and the FrameProcessor is invoked.
      */
     public void decode(ByteBuffer inBoundBuffer) throws IOException {
+        if (closed) {
+            DEBUG_LOGGER.log(Level.DEBUG, "closed: ignoring buffer (%s bytes)",
+                    inBoundBuffer.remaining());
+            inBoundBuffer.position(inBoundBuffer.limit());
+            return;
+        }
         int remaining = inBoundBuffer.remaining();
         DEBUG_LOGGER.log(Level.DEBUG, "decodes: %d", remaining);
         if (remaining > 0) {
@@ -290,6 +297,20 @@
         return res;
     }
 
+    public void close(String msg) {
+        closed = true;
+        tailBuffers.clear();
+        int bytes = tailSize;
+        ByteBuffer b = currentBuffer;
+        if (b != null) {
+            bytes += b.remaining();
+            b.position(b.limit());
+        }
+        tailSize = 0;
+        currentBuffer = null;
+        DEBUG_LOGGER.log(Level.DEBUG, "closed %s, ignoring %d bytes", msg, bytes);
+    }
+
     public void skipBytes(int bytecount) {
         while (bytecount > 0) {
             int remaining = currentBuffer.remaining();