Author: remy.maucherat(a)jboss.com
Date: 2014-06-02 11:36:05 -0400 (Mon, 02 Jun 2014)
New Revision: 2435
Modified:
branches/7.4.x/src/main/java/org/apache/coyote/http11/AbstractInternalInputBuffer.java
branches/7.4.x/src/main/java/org/apache/coyote/http11/InternalAprInputBuffer.java
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:
- BZ1103596: Does not fix the real cause, but avoid loop.
- Improve on notifications and input.
Modified:
branches/7.4.x/src/main/java/org/apache/coyote/http11/AbstractInternalInputBuffer.java
===================================================================
---
branches/7.4.x/src/main/java/org/apache/coyote/http11/AbstractInternalInputBuffer.java 2014-05-30
14:36:37 UTC (rev 2434)
+++
branches/7.4.x/src/main/java/org/apache/coyote/http11/AbstractInternalInputBuffer.java 2014-06-02
15:36:05 UTC (rev 2435)
@@ -242,7 +242,7 @@
request.recycle();
// Copy leftover bytes to the beginning of the buffer
- if (lastValid - pos > 0) {
+ if (lastValid - pos > 0 && pos > 0) {
int npos = 0;
int opos = pos;
while (lastValid - opos > opos - npos) {
Modified:
branches/7.4.x/src/main/java/org/apache/coyote/http11/InternalAprInputBuffer.java
===================================================================
---
branches/7.4.x/src/main/java/org/apache/coyote/http11/InternalAprInputBuffer.java 2014-05-30
14:36:37 UTC (rev 2434)
+++
branches/7.4.x/src/main/java/org/apache/coyote/http11/InternalAprInputBuffer.java 2014-06-02
15:36:05 UTC (rev 2435)
@@ -329,7 +329,7 @@
request.recycle();
// Copy leftover bytes to the beginning of the buffer
- if (lastValid - pos > 0) {
+ if (lastValid - pos > 0 && pos > 0) {
int npos = 0;
int opos = pos;
while (lastValid - opos > opos - npos) {
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 2014-05-30
14:36:37 UTC (rev 2434)
+++
branches/7.4.x/src/main/java/org/apache/coyote/http11/InternalNioInputBuffer.java 2014-06-02
15:36:05 UTC (rev 2435)
@@ -129,7 +129,9 @@
bbuf.get(buf, pos, nBytes);
lastValid = pos + nBytes;
semaphore.release();
- if (!processor.isProcessing() && processor.getReadNotifications()) {
+ if (/*!processor.isProcessing() && */processor.getReadNotifications()
+ && available) {
+ available = false;
if (!endpoint.processChannel(attachment, SocketStatus.OPEN_READ)) {
endpoint.closeChannel(attachment);
}
@@ -430,26 +432,39 @@
// Reading from client
if (nonBlocking) {
if (semaphore.tryAcquire()) {
- // Prepare the internal input buffer for reading
- prepare();
- try {
- channel.read(bbuf, readTimeout, TimeUnit.MILLISECONDS, channel,
this.completionHandler);
- } catch (Exception e) {
- processor.getResponse().setErrorException(e);
- if (CoyoteLogger.HTTP_LOGGER.isDebugEnabled()) {
- CoyoteLogger.HTTP_LOGGER.errorWithNonBlockingRead(e);
+ synchronized (completionHandler) {
+ // Prepare the internal input buffer for reading
+ prepare();
+ boolean available0 = available;
+ available = false;
+ try {
+ channel.read(bbuf, readTimeout, TimeUnit.MILLISECONDS, channel,
this.completionHandler);
+ } catch (Exception e) {
+ processor.getResponse().setErrorException(e);
+ if (CoyoteLogger.HTTP_LOGGER.isDebugEnabled()) {
+ CoyoteLogger.HTTP_LOGGER.errorWithNonBlockingRead(e);
+ }
}
+ nRead = lastValid - pos;
+ if (nRead > 0) {
+ available = false;
+ } else {
+ available = available0;
+ }
}
- nRead = lastValid - pos;
- } else if (nRead == 0 && !available) {
- // If there's nothing and flow control is not used, autoblock
- try {
- if (semaphore.tryAcquire(readTimeout, unit))
- semaphore.release();
- } catch (InterruptedException e) {
- // Ignore
+ } else {
+ synchronized (completionHandler) {
+ if (nRead == 0 && !available) {
+ // If there's nothing and flow control is not used, autoblock
+ try {
+ if (semaphore.tryAcquire(readTimeout, unit))
+ semaphore.release();
+ } catch (InterruptedException e) {
+ // Ignore
+ }
+ nRead = lastValid - pos;
+ }
}
- nRead = lastValid - pos;
}
} else {
// Prepare the internal input buffer for reading
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 2014-05-30
14:36:37 UTC (rev 2434)
+++
branches/7.4.x/src/main/java/org/apache/coyote/http11/InternalNioOutputBuffer.java 2014-06-02
15:36:05 UTC (rev 2435)
@@ -209,7 +209,7 @@
response.setLastWrite(nBytes);
leftover.recycle();
semaphore.release();
- if (!processor.isProcessing() &&
processor.getWriteNotification()) {
+ if (/*!processor.isProcessing() &&
*/processor.getWriteNotification()) {
if (!endpoint.processChannel(attachment,
SocketStatus.OPEN_WRITE)) {
endpoint.closeChannel(attachment);
}
@@ -822,6 +822,8 @@
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) {
@@ -830,6 +832,10 @@
CoyoteLogger.HTTP_LOGGER.errorWithNonBlockingWrite(e);
}
}
+ if (writeNotification && bbuf.hasRemaining()) {
+ // Write did not complete inline, possible write
notification
+ processor.setWriteNotification(writeNotification);
+ }
}
}
} else {
Show replies by date