Author: remm
Date: Fri Apr 27 15:03:57 2007
New Revision: 533240
URL: http://svn.apache.org/viewvc?view=rev&rev=533240
Log:
- Add code to check that at least one read is made that goes down to the
connector for each read event.
- It is an error to not read bytes as long as some are reported as available.
- Generate a read event if bytes are available after processing the begin event
(for API lawyers out there).
- Not tested yet, sorry. In theory, previously working code shouldn't have to
be modified at all.
Modified:
tomcat/tc6.0.x/trunk/java/org/apache/catalina/connector/CoyoteAdapter.java
tomcat/tc6.0.x/trunk/java/org/apache/catalina/connector/InputBuffer.java
tomcat/tc6.0.x/trunk/java/org/apache/catalina/connector/Request.java
Modified:
tomcat/tc6.0.x/trunk/java/org/apache/catalina/connector/CoyoteAdapter.java
URL:
http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/java/org/apache/catalina/connector/CoyoteAdapter.java?view=diff&rev=533240&r1=533239&r2=533240
==============================================================================
--- tomcat/tc6.0.x/trunk/java/org/apache/catalina/connector/CoyoteAdapter.java
(original)
+++ tomcat/tc6.0.x/trunk/java/org/apache/catalina/connector/CoyoteAdapter.java
Fri Apr 27 15:03:57 2007
@@ -118,6 +118,7 @@
if (request.getWrapper() != null) {
boolean error = false;
+ boolean read = false;
try {
if (status == SocketStatus.OPEN) {
if (response.isClosed()) {
@@ -128,6 +129,8 @@
} else {
request.getEvent().setEventType(CometEvent.EventType.READ);
request.getEvent().setEventSubType(null);
+ read = true;
+ request.resetDidRead();
}
} else if (status == SocketStatus.DISCONNECT) {
request.getEvent().setEventType(CometEvent.EventType.ERROR);
@@ -167,6 +170,11 @@
}
if (response.isClosed() || !request.isComet()) {
res.action(ActionCode.ACTION_COMET_END, null);
+ } else if (!error && read && (!request.didRead() ||
request.getAvailable())) {
+ // If this was a read and not all bytes have been read, or
if no data
+ // was read from the connector, then it is an error
+ error = true;
+ log.error(sm.getString("coyoteAdapter.read"));
}
return (!error);
} catch (Throwable t) {
@@ -240,8 +248,16 @@
if (request.isComet()) {
if (!response.isClosed() && !response.isError()) {
- comet = true;
- res.action(ActionCode.ACTION_COMET_BEGIN, null);
+ if (request.getAvailable()) {
+ // Invoke a read event right away if there are
available bytes
+ if (event(req, res, SocketStatus.OPEN)) {
+ comet = true;
+ res.action(ActionCode.ACTION_COMET_BEGIN,
null);
+ }
+ } else {
+ comet = true;
+ res.action(ActionCode.ACTION_COMET_BEGIN, null);
+ }
} else {
// Clear the filter chain, as otherwise it will not be
reset elsewhere
// since this is a Comet request
Modified:
tomcat/tc6.0.x/trunk/java/org/apache/catalina/connector/InputBuffer.java
URL:
http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/java/org/apache/catalina/connector/InputBuffer.java?view=diff&rev=533240&r1=533239&r2=533240
==============================================================================
--- tomcat/tc6.0.x/trunk/java/org/apache/catalina/connector/InputBuffer.java
(original)
+++ tomcat/tc6.0.x/trunk/java/org/apache/catalina/connector/InputBuffer.java
Fri Apr 27 15:03:57 2007
@@ -99,6 +99,12 @@
/**
+ * Flag which if a read was performed.
+ */
+ private boolean didRead = false;
+
+
+ /**
* Byte chunk used to input bytes.
*/
private ByteChunk inputChunk = new ByteChunk();
@@ -257,8 +263,7 @@
}
- public int available()
- throws IOException {
+ public int available() {
int available = 0;
if (state == BYTE_STATE) {
available = bb.getLength();
@@ -273,6 +278,16 @@
}
+ public boolean didRead() {
+ return didRead();
+ }
+
+
+ public void resetDidRead() {
+ didRead = false;
+ }
+
+
// ------------------------------------------------- Bytes Handling Methods
@@ -294,6 +309,7 @@
return -1;
state = BYTE_STATE;
+ didRead = true;
int result = coyoteRequest.doRead(bb);
Modified: tomcat/tc6.0.x/trunk/java/org/apache/catalina/connector/Request.java
URL:
http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/java/org/apache/catalina/connector/Request.java?view=diff&rev=533240&r1=533239&r2=533240
==============================================================================
--- tomcat/tc6.0.x/trunk/java/org/apache/catalina/connector/Request.java
(original)
+++ tomcat/tc6.0.x/trunk/java/org/apache/catalina/connector/Request.java Fri
Apr 27 15:03:57 2007
@@ -2240,6 +2240,24 @@
}
+ /**
+ * Return true if bytes are available.
+ */
+ public boolean getAvailable() {
+ return (inputBuffer.available() > 0);
+ }
+
+
+ public boolean didRead() {
+ return inputBuffer.didRead();
+ }
+
+
+ public void resetDidRead() {
+ inputBuffer.resetDidRead();
+ }
+
+
// ------------------------------------------------------ Protected Methods
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]