You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by ma...@apache.org on 2013/08/30 21:28:34 UTC
svn commit: r1519052 -
/tomcat/trunk/java/org/apache/coyote/ajp/AjpAprProcessor.java
Author: markt
Date: Fri Aug 30 19:28:34 2013
New Revision: 1519052
URL: http://svn.apache.org/r1519052
Log:
More non-blocking IO plumbing for the AJP APR/native connector.
This will allow reads to be non-blocking between messages (if desired) but remain blocking once a message starts. A more sophisticated approach to non-blocking could be taken but this approach is similar to how NIO does it and, depending on how mod_jk writes and reads data, may be all that is realistic.
Modified:
tomcat/trunk/java/org/apache/coyote/ajp/AjpAprProcessor.java
Modified: tomcat/trunk/java/org/apache/coyote/ajp/AjpAprProcessor.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/coyote/ajp/AjpAprProcessor.java?rev=1519052&r1=1519051&r2=1519052&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/coyote/ajp/AjpAprProcessor.java (original)
+++ tomcat/trunk/java/org/apache/coyote/ajp/AjpAprProcessor.java Fri Aug 30 19:28:34 2013
@@ -341,10 +341,23 @@ public class AjpAprProcessor extends Abs
/**
* Read at least the specified amount of bytes, and place them
- * in the input buffer.
+ * in the input buffer. Note that if any data is available to read then this
+ * method will always block until at least the specified number of bytes
+ * have been read.
+ *
+ * @param n The minimum number of bytes to read
+ * @param block If there is no data available to read when this method is
+ * called, should this call block until data becomes available?
+ * @return
+ * @throws IOException
*/
- protected boolean read(int n)
- throws IOException {
+ protected boolean read(int n, boolean block) throws IOException {
+
+ boolean nextReadBlocks = block;
+
+ if (!block && inputBuffer.remaining() > 0) {
+ nextReadBlocks = true;
+ }
if (inputBuffer.capacity() - inputBuffer.limit() <=
n - inputBuffer.remaining()) {
@@ -355,9 +368,14 @@ public class AjpAprProcessor extends Abs
int nRead;
while (inputBuffer.remaining() < n) {
nRead = readSocket(inputBuffer.limit(),
- inputBuffer.capacity() - inputBuffer.limit(), true);
- if (nRead > 0) {
+ inputBuffer.capacity() - inputBuffer.limit(),
+ nextReadBlocks);
+ if (nRead == 0) {
+ // Must be a non-blocking read
+ return false;
+ } else if (nRead > 0) {
inputBuffer.limit(inputBuffer.limit() + nRead);
+ nextReadBlocks = true;
} else {
throw new IOException(sm.getString("ajpprocessor.failedread"));
}
@@ -499,7 +517,7 @@ public class AjpAprProcessor extends Abs
return false;
}
} else {
- read(headerLength);
+ read(headerLength, true);
}
inputBuffer.get(message.getBuffer(), 0, headerLength);
int messageLength = message.processHeader(true);
@@ -521,7 +539,7 @@ public class AjpAprProcessor extends Abs
Integer.valueOf(messageLength),
Integer.valueOf(message.getBuffer().length)));
}
- read(messageLength);
+ read(messageLength, true);
inputBuffer.get(message.getBuffer(), headerLength, messageLength);
return true;
}
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org