Author: remy.maucherat(a)jboss.com
Date: 2014-10-03 10:57:36 -0400 (Fri, 03 Oct 2014)
New Revision: 2513
Modified:
branches/7.5.x/src/main/java/org/apache/coyote/http11/InternalNioOutputBuffer.java
Log:
Add a sync and use remaining() instead of something more convoluted which could fail.
Modified:
branches/7.5.x/src/main/java/org/apache/coyote/http11/InternalNioOutputBuffer.java
===================================================================
---
branches/7.5.x/src/main/java/org/apache/coyote/http11/InternalNioOutputBuffer.java 2014-10-01
11:58:54 UTC (rev 2512)
+++
branches/7.5.x/src/main/java/org/apache/coyote/http11/InternalNioOutputBuffer.java 2014-10-03
14:57:36 UTC (rev 2513)
@@ -867,26 +867,26 @@
if (leftover.getLength() > Constants.ASYNC_BUFFER_SIZE) {
response.setLastWrite(0);
}
- }
- if (semaphore.tryAcquire()) {
- // Calculate the number of bytes that fit in the buffer
- int n = Math.min(leftover.getLength(), bbuf.capacity() -
bbuf.position());
- bbuf.put(leftover.getBuffer(), leftover.getOffset(), n).flip();
- leftover.setOffset(leftover.getOffset() + n);
- boolean writeNotification = processor.getWriteNotification();
- processor.setWriteNotification(false);
- try {
- channel.write(bbuf, writeTimeout, TimeUnit.MILLISECONDS, channel,
completionHandler);
- } catch (Exception e) {
- processor.getResponse().setErrorException(e);
- if (CoyoteLogger.HTTP_LOGGER.isDebugEnabled()) {
- CoyoteLogger.HTTP_LOGGER.errorWithNonBlockingWrite(e);
+ if (semaphore.tryAcquire()) {
+ // Calculate the number of bytes that fit in the buffer
+ int n = Math.min(leftover.getLength(), bbuf.remaining());
+ bbuf.put(leftover.getBuffer(), leftover.getOffset(), n).flip();
+ leftover.setOffset(leftover.getOffset() + n);
+ boolean writeNotification = processor.getWriteNotification();
+ processor.setWriteNotification(false);
+ try {
+ channel.write(bbuf, writeTimeout, TimeUnit.MILLISECONDS,
channel, completionHandler);
+ } catch (Exception e) {
+ processor.getResponse().setErrorException(e);
+ if (CoyoteLogger.HTTP_LOGGER.isDebugEnabled()) {
+ CoyoteLogger.HTTP_LOGGER.errorWithNonBlockingWrite(e);
+ }
}
- }
- if (semaphore.availablePermits() == 0) {
- // Write did not complete inline, possible write notification
- if (writeNotification) {
- processor.setWriteNotification(true);
+ if (semaphore.availablePermits() == 0) {
+ // Write did not complete inline, possible write
notification
+ if (writeNotification) {
+ processor.setWriteNotification(true);
+ }
}
}
}
Show replies by date