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/09/02 15:17:26 UTC
svn commit: r1519431 - in /tomcat/trunk/java/org/apache/coyote/ajp:
AjpNioProcessor.java AjpProcessor.java
Author: markt
Date: Mon Sep 2 13:17:26 2013
New Revision: 1519431
URL: http://svn.apache.org/r1519431
Log:
Aligning the readMessage() method implementation and the read() method signature between BIO and NIo to aid future refactoring
Modified:
tomcat/trunk/java/org/apache/coyote/ajp/AjpNioProcessor.java
tomcat/trunk/java/org/apache/coyote/ajp/AjpProcessor.java
Modified: tomcat/trunk/java/org/apache/coyote/ajp/AjpNioProcessor.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/coyote/ajp/AjpNioProcessor.java?rev=1519431&r1=1519430&r2=1519431&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/coyote/ajp/AjpNioProcessor.java (original)
+++ tomcat/trunk/java/org/apache/coyote/ajp/AjpNioProcessor.java Mon Sep 2 13:17:26 2013
@@ -141,7 +141,7 @@ public class AjpNioProcessor extends Abs
/**
* Read the specified amount of bytes, and place them in the input buffer.
*/
- protected int read(byte[] buf, int pos, int n, boolean blockFirstRead)
+ protected boolean read(byte[] buf, int pos, int n, boolean blockFirstRead)
throws IOException {
int read = 0;
@@ -153,13 +153,13 @@ public class AjpNioProcessor extends Abs
if (res > 0) {
read += res;
} else if (res == 0 && !block) {
- break;
+ return false;
} else {
throw new IOException(sm.getString("ajpprocessor.failedread"));
}
block = true;
}
- return read;
+ return true;
}
@@ -205,13 +205,6 @@ public class AjpNioProcessor extends Abs
}
- /**
- * Read an AJP message.
- *
- * @return <code>true</code> if a message was read, otherwise false
- *
- * @throws IOException any other failure, including incomplete reads
- */
@Override
protected boolean readMessage(AjpMessage message, boolean blockFirstRead)
throws IOException {
@@ -219,9 +212,7 @@ public class AjpNioProcessor extends Abs
byte[] buf = message.getBuffer();
int headerLength = message.getHeaderLength();
- int bytesRead = read(buf, 0, headerLength, blockFirstRead);
-
- if (bytesRead == 0) {
+ if (!read(buf, 0, headerLength, blockFirstRead)) {
return false;
}
Modified: tomcat/trunk/java/org/apache/coyote/ajp/AjpProcessor.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/coyote/ajp/AjpProcessor.java?rev=1519431&r1=1519430&r2=1519431&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/coyote/ajp/AjpProcessor.java (original)
+++ tomcat/trunk/java/org/apache/coyote/ajp/AjpProcessor.java Mon Sep 2 13:17:26 2013
@@ -124,8 +124,20 @@ public class AjpProcessor extends Abstra
/**
* Read at least the specified amount of bytes, and place them
* in the input buffer.
+ *
+ * @param buf Buffer to read data into
+ * @param pos Start position
+ * @param n Number of bytes to read
+ * @param blockFirstRead Should the first read block?
+ *
+ * @return If blockFirstRead is false, the connector supports non-blocking
+ * IO and the first read does not return any data, this method
+ * reads no data into the buffer returns false. Otherwise, blocking
+ * reads are used read the specified number of bytes into the
+ * buffer.
+ * @throws IOException
*/
- protected boolean read(byte[] buf, int pos, int n)
+ protected boolean read(byte[] buf, int pos, int n, boolean blockFirstRead)
throws IOException {
int read = 0;
@@ -143,23 +155,16 @@ public class AjpProcessor extends Abstra
}
- /**
- * Read an AJP message.
- *
- * @param message The message to populate
- * @param ignored Not used in BIO
- * @return true if the message has been read, false if the short read
- * didn't return anything
- * @throws IOException any other failure, including incomplete reads
- */
@Override
- protected boolean readMessage(AjpMessage message, boolean ignored)
+ protected boolean readMessage(AjpMessage message, boolean block)
throws IOException {
byte[] buf = message.getBuffer();
int headerLength = message.getHeaderLength();
- read(buf, 0, headerLength);
+ if (!read(buf, 0, headerLength, block)) {
+ return false;
+ }
int messageLength = message.processHeader(true);
if (messageLength < 0) {
@@ -180,7 +185,7 @@ public class AjpProcessor extends Abstra
Integer.valueOf(messageLength),
Integer.valueOf(buf.length)));
}
- read(buf, headerLength, messageLength);
+ read(buf, headerLength, messageLength, true);
return true;
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org