You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by re...@apache.org on 2007/05/04 01:54:32 UTC
svn commit: r535030 - in
/tomcat/tc6.0.x/trunk/java/org/apache/catalina/connector:
CoyoteAdapter.java InputBuffer.java Request.java
Author: remm
Date: Thu May 3 16:54:31 2007
New Revision: 535030
URL: http://svn.apache.org/viewvc?view=rev&rev=535030
Log:
- Remove the didRead flag (an error checking hack).
- If there is a read event, do at least one read on the connector (the buffer is necessarily empty, otherwise
there would have been an error during the previous read event).
- Side effect: EOFs can be reported using the END event, and exceptions can be reported as ERROR.
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=535030&r1=535029&r2=535030
==============================================================================
--- 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 Thu May 3 16:54:31 2007
@@ -127,10 +127,24 @@
request.getEvent().setEventType(CometEvent.EventType.END);
request.getEvent().setEventSubType(null);
} else {
- request.getEvent().setEventType(CometEvent.EventType.READ);
- request.getEvent().setEventSubType(null);
- read = true;
- request.resetDidRead();
+ try {
+ // Fill the read buffer of the servlet layer
+ if (request.read()) {
+ read = true;
+ }
+ } catch (Exception e) {
+ error = true;
+ }
+ if (read) {
+ request.getEvent().setEventType(CometEvent.EventType.READ);
+ request.getEvent().setEventSubType(null);
+ } else if (error) {
+ request.getEvent().setEventType(CometEvent.EventType.ERROR);
+ request.getEvent().setEventSubType(CometEvent.EventSubType.CLIENT_DISCONNECT);
+ } else {
+ request.getEvent().setEventType(CometEvent.EventType.END);
+ request.getEvent().setEventSubType(null);
+ }
}
} else if (status == SocketStatus.DISCONNECT) {
request.getEvent().setEventType(CometEvent.EventType.ERROR);
@@ -170,7 +184,7 @@
}
if (response.isClosed() || !request.isComet()) {
res.action(ActionCode.ACTION_COMET_END, null);
- } else if (!error && read && (!request.didRead() || request.getAvailable())) {
+ } else if (!error && read && 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;
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=535030&r1=535029&r2=535030
==============================================================================
--- 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 Thu May 3 16:54:31 2007
@@ -99,12 +99,6 @@
/**
- * Flag which if a read was performed.
- */
- private boolean didRead = true;
-
-
- /**
* Byte chunk used to input bytes.
*/
private ByteChunk inputChunk = new ByteChunk();
@@ -274,28 +268,10 @@
coyoteRequest.action(ActionCode.ACTION_AVAILABLE, null);
available = (coyoteRequest.getAvailable() > 0) ? 1 : 0;
}
- if ((available == 0) && !didRead) {
- // This is a comet read and no read was done: at least one
- // read can be made without blocking (in very rare cases, it will
- // reach the end of the stream, for example if the bytes sent
- // were from a next request, or if the request content-length is
- // wrong)
- available = 1;
- }
return available;
}
- public boolean didRead() {
- return didRead;
- }
-
-
- public void resetDidRead() {
- didRead = false;
- }
-
-
// ------------------------------------------------- Bytes Handling Methods
@@ -317,7 +293,6 @@
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=535030&r1=535029&r2=535030
==============================================================================
--- 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 Thu May 3 16:54:31 2007
@@ -458,6 +458,15 @@
}
+ /**
+ * Clear cached encoders (to save memory for Comet requests).
+ */
+ public boolean read()
+ throws IOException {
+ return (inputBuffer.realReadBytes(null, 0, 0) > 0);
+ }
+
+
// -------------------------------------------------------- Request Methods
@@ -2248,16 +2257,6 @@
}
- public boolean didRead() {
- return inputBuffer.didRead();
- }
-
-
- public void resetDidRead() {
- inputBuffer.resetDidRead();
- }
-
-
// ------------------------------------------------------ Protected Methods
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org