[jbossweb-commits] JBossWeb SVN: r2283 - branches/7.4.x/src/main/java/org/apache/coyote/http11.

jbossweb-commits at lists.jboss.org jbossweb-commits at lists.jboss.org
Wed Oct 16 12:57:58 EDT 2013


Author: remy.maucherat at jboss.com
Date: 2013-10-16 12:57:58 -0400 (Wed, 16 Oct 2013)
New Revision: 2283

Modified:
   branches/7.4.x/src/main/java/org/apache/coyote/http11/InternalNioInputBuffer.java
   branches/7.4.x/src/main/java/org/apache/coyote/http11/InternalNioOutputBuffer.java
Log:
Some cleanups.

Modified: branches/7.4.x/src/main/java/org/apache/coyote/http11/InternalNioInputBuffer.java
===================================================================
--- branches/7.4.x/src/main/java/org/apache/coyote/http11/InternalNioInputBuffer.java	2013-10-16 12:46:56 UTC (rev 2282)
+++ branches/7.4.x/src/main/java/org/apache/coyote/http11/InternalNioInputBuffer.java	2013-10-16 16:57:58 UTC (rev 2283)
@@ -81,9 +81,9 @@
 	private CompletionHandler<Integer, NioChannel> completionHandler;
 
     /**
-     * Latch used for auto blocking.
+     * Lock used for auto blocking.
      */
-    private CountDownLatch latch = null;
+    private CountDownLatch latch = new CountDownLatch(0);
     
     /**
 	 * Create a new instance of {@code InternalNioInputBuffer}
@@ -419,11 +419,14 @@
         // Reading from client
         if (nonBlocking) {
             synchronized (completionHandler) {
-                // Prepare the internal input buffer for reading
-                this.prepare();
-                nonBlockingRead(bbuf, readTimeout, unit);
-                nRead = lastValid - pos;
+                if (latch.getCount() == 0) {
+                    // Prepare the internal input buffer for reading
+                    this.prepare();
+                    nonBlockingRead(readTimeout, unit);
+                    nRead = lastValid - pos;
+                }
             }
+            // If there's nothing and flow control is not used, autoblock 
             if (nRead == 0 && !available) {
                 try {
                     latch.await(readTimeout, unit);
@@ -435,7 +438,7 @@
         } else {
             // Prepare the internal input buffer for reading
             this.prepare();
-            nRead = blockingRead(bbuf, readTimeout, unit);
+            nRead = blockingRead(readTimeout, unit);
             if (nRead > 0) {
                 bbuf.flip();
                 if (nRead > (buf.length - end)) {
@@ -487,11 +490,10 @@
 	 *            the byte buffer which will contain the bytes read from the
 	 *            current channel
 	 */
-	private void nonBlockingRead(final ByteBuffer bb, long timeout, TimeUnit unit) {
-		final NioChannel ch = this.channel;
+	private void nonBlockingRead(long timeout, TimeUnit unit) {
 		try {
 		    latch = new CountDownLatch(1);
-			ch.read(bb, ch, this.completionHandler);
+		    channel.read(bbuf, channel, this.completionHandler);
 		} catch (Exception e) {
 		    processor.getResponse().setErrorException(e);
 			if (CoyoteLogger.HTTP_LOGGER.isDebugEnabled()) {
@@ -507,11 +509,11 @@
 	 * @return the number of bytes read or -1 if the end of the stream was
 	 *         reached
 	 */
-	private int blockingRead(ByteBuffer bb, long timeout, TimeUnit unit) {
+	private int blockingRead(long timeout, TimeUnit unit) {
 		int nr = 0;
 		try {
 			long readTimeout = timeout > 0 ? timeout : Integer.MAX_VALUE;
-			nr = this.channel.readBytes(bb, readTimeout, unit);
+			nr = this.channel.readBytes(bbuf, readTimeout, unit);
 			if (nr < 0) {
 				close(channel);
 			}

Modified: branches/7.4.x/src/main/java/org/apache/coyote/http11/InternalNioOutputBuffer.java
===================================================================
--- branches/7.4.x/src/main/java/org/apache/coyote/http11/InternalNioOutputBuffer.java	2013-10-16 12:46:56 UTC (rev 2282)
+++ branches/7.4.x/src/main/java/org/apache/coyote/http11/InternalNioOutputBuffer.java	2013-10-16 16:57:58 UTC (rev 2283)
@@ -300,6 +300,7 @@
 	 */
 	private void nonBlockingWrite(final long timeout, final TimeUnit unit) {
 		try {
+            latch = new CountDownLatch(1);
 		    // Calculate the number of bytes that fit in the buffer
 		    int n = Math.min(leftover.getLength(), bbuf.capacity() - bbuf.position());
 		    // put bytes in the buffer
@@ -307,7 +308,6 @@
 		    // Update the offset
 		    leftover.setOffset(leftover.getOffset() + n);
 		    // Perform the write operation
-		    latch = new CountDownLatch(1);
 		    this.channel.write(this.bbuf, timeout, unit, this.channel, this.completionHandler);
 		} catch (Throwable t) {
             processor.getResponse().setErrorException(t);
@@ -835,7 +835,7 @@
          */
         public int doWrite(ByteChunk chunk, Response res) throws IOException {
             if (nonBlocking) {
-                // Autoblocking if the buffer is already full
+                // If the buffer is growing and flow control is not used, autoblock if in a container thread 
                 if (leftover.getLength() > Constants.ASYNC_BUFFER_SIZE && response.getFlushLeftovers()
                         && Http11AbstractProcessor.containerThread.get() == Boolean.TRUE) {
                     try {



More information about the jbossweb-commits mailing list