< prev index next >

test/jdk/java/net/httpclient/http2/server/BodyOutputStream.java

Print this page

        

@@ -1,7 +1,7 @@
 /*
- * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
  * under the terms of the GNU General Public License version 2 only, as
  * published by the Free Software Foundation.

@@ -22,12 +22,10 @@
  */
 
 import java.io.*;
 import java.nio.ByteBuffer;
 
-import jdk.incubator.http.internal.common.ByteBufferReference;
-import jdk.incubator.http.internal.common.Queue;
 import jdk.incubator.http.internal.frame.DataFrame;
 
 /**
  * OutputStream. Incoming window updates handled by the main connection
  * reader thread.

@@ -36,11 +34,11 @@
 class BodyOutputStream extends OutputStream {
     final static byte[] EMPTY_BARRAY = new byte[0];
 
     final int streamid;
     int window;
-    boolean closed;
+    volatile boolean closed;
     boolean goodToGo = false; // not allowed to send until headers sent
     final Http2TestServerConnection conn;
     final Queue outputQ;
 
     BodyOutputStream(int streamid, int initialWindow, Http2TestServerConnection conn) {

@@ -98,11 +96,11 @@
     private void send(byte[] buf, int offset, int len, int flags) throws IOException {
         ByteBuffer buffer = ByteBuffer.allocate(len);
         buffer.put(buf, offset, len);
         buffer.flip();
         assert streamid != 0;
-        DataFrame df = new DataFrame(streamid, flags, ByteBufferReference.of(buffer));
+        DataFrame df = new DataFrame(streamid, flags, buffer);
         outputQ.put(df);
     }
 
     byte[] one = new byte[1];
 

@@ -116,14 +114,15 @@
         closed = true;
     }
 
     @Override
     public void close() {
-        if (closed) {
-            return;
-        }
+        if (closed) return;
+        synchronized (this) {
+            if (closed) return;
         closed = true;
+        }
         try {
             send(EMPTY_BARRAY, 0, 0, DataFrame.END_STREAM);
         } catch (IOException ex) {
             System.err.println("TestServer: OutputStream.close exception: " + ex);
             ex.printStackTrace();
< prev index next >