Author: remy.maucherat(a)jboss.com
Date: 2008-03-20 21:39:06 -0400 (Thu, 20 Mar 2008)
New Revision: 533
Modified:
trunk/java/org/apache/catalina/connector/CoyoteAdapter.java
trunk/java/org/apache/catalina/connector/CoyoteReader.java
trunk/java/org/apache/catalina/connector/InputBuffer.java
trunk/java/org/apache/catalina/connector/Request.java
trunk/java/org/jboss/web/comet/CometEvent.java
trunk/test/org/apache/jboss/web/comet/CometServletTest1.java
trunk/webapps/docs/aio.xml
trunk/webapps/docs/changelog.xml
Log:
- Improve a bit timeouts.
- Add new EOF event (it is otherwise difficult to detect EOFs), as requested by Bill.
Modified: trunk/java/org/apache/catalina/connector/CoyoteAdapter.java
===================================================================
--- trunk/java/org/apache/catalina/connector/CoyoteAdapter.java 2008-03-21 01:07:47 UTC
(rev 532)
+++ trunk/java/org/apache/catalina/connector/CoyoteAdapter.java 2008-03-21 01:39:06 UTC
(rev 533)
@@ -141,6 +141,7 @@
boolean error = false;
boolean read = false;
+ boolean eof = false;
boolean close = false;
try {
if (response.isClosed()) {
@@ -159,8 +160,11 @@
} else {
try {
// Fill the read buffer of the servlet layer
- if (request.read()) {
+ int n = request.read();
+ if (n > 0) {
read = true;
+ } else if (n < 0) {
+ eof = true;
}
} catch (IOException e) {
error = true;
@@ -169,6 +173,8 @@
request.getEvent().setType(CometEvent.EventType.READ);
} else if (error) {
request.getEvent().setType(CometEvent.EventType.ERROR);
+ } else if (eof) {
+ request.getEvent().setType(CometEvent.EventType.EOF);
} else {
// Data was present on the socket, but it did not translate
into actual
// entity body bytes
@@ -235,6 +241,15 @@
error = true;
connector.getContainer().getPipeline().getFirst().event(request,
response, request.getEvent());
}
+ if (!error && !eof && (status == SocketStatus.OPEN_READ)
&& request.isClosed()) {
+ // Send an EOF event
+ request.getEvent().setType(CometEvent.EventType.EOF);
+ eof = true;
+ connector.getContainer().getPipeline().getFirst().event(request,
response, request.getEvent());
+ }
+ if (!error && request.isClosed()) {
+ request.suspend();
+ }
if (error || close) {
response.finishResponse();
}
Modified: trunk/java/org/apache/catalina/connector/CoyoteReader.java
===================================================================
--- trunk/java/org/apache/catalina/connector/CoyoteReader.java 2008-03-21 01:07:47 UTC
(rev 532)
+++ trunk/java/org/apache/catalina/connector/CoyoteReader.java 2008-03-21 01:39:06 UTC
(rev 533)
@@ -119,7 +119,7 @@
public boolean markSupported() {
- return true;
+ return ib.markSupported();
}
Modified: trunk/java/org/apache/catalina/connector/InputBuffer.java
===================================================================
--- trunk/java/org/apache/catalina/connector/InputBuffer.java 2008-03-21 01:07:47 UTC (rev
532)
+++ trunk/java/org/apache/catalina/connector/InputBuffer.java 2008-03-21 01:39:06 UTC (rev
533)
@@ -264,6 +264,14 @@
}
+ /**
+ * Returns if the request is closed.
+ */
+ public boolean isClosed() {
+ return closed;
+ }
+
+
public int available() {
int available = 0;
if (state == BYTE_STATE) {
@@ -321,7 +329,11 @@
state = BYTE_STATE;
try {
- return coyoteRequest.doRead(bb);
+ int n = coyoteRequest.doRead(bb);
+ if (n < 0) {
+ closed = true;
+ }
+ return n;
} catch (IOException e) {
// An IOException on a read is almost always due to
// the remote client aborting the request or a timeout occurring.
Modified: trunk/java/org/apache/catalina/connector/Request.java
===================================================================
--- trunk/java/org/apache/catalina/connector/Request.java 2008-03-21 01:07:47 UTC (rev
532)
+++ trunk/java/org/apache/catalina/connector/Request.java 2008-03-21 01:39:06 UTC (rev
533)
@@ -466,12 +466,21 @@
/**
* Read bytes into the low level buffer.
*/
- public boolean read()
+ public int read()
throws IOException {
- return (inputBuffer.realReadBytes(null, 0, 0) > 0);
+ return (inputBuffer.realReadBytes(null, 0, 0));
}
+ /**
+ * Read bytes into the low level buffer.
+ */
+ public boolean isClosed()
+ throws IOException {
+ return (inputBuffer.isClosed());
+ }
+
+
// -------------------------------------------------------- Request Methods
Modified: trunk/java/org/jboss/web/comet/CometEvent.java
===================================================================
--- trunk/java/org/jboss/web/comet/CometEvent.java 2008-03-21 01:07:47 UTC (rev 532)
+++ trunk/java/org/jboss/web/comet/CometEvent.java 2008-03-21 01:39:06 UTC (rev 533)
@@ -44,6 +44,10 @@
* not synchronized, so when they are accessed by multiple threads adequate
* synchronization is needed. After processing the initial event, the request
* is considered to be committed.</li>
+ * <li>EOF - The end of file of the input has been reached, and no further data
is
+ * available. This event is sent because it can be difficult to detect otherwise.
+ * Following the processing of this event and the processing of any subsequent
+ * event, the event will be suspended.</li>
* <li>END - End may be called to end the processing of the request. Fields
that have
* been initialized in the begin method should be reset. After this event has
* been processed, the request and response objects, as well as all their dependent
@@ -79,7 +83,7 @@
* method always returns true.</li>
* </ul>
*/
- public enum EventType { BEGIN, END, ERROR, EVENT, READ, TIMEOUT, WRITE }
+ public enum EventType { BEGIN, END, ERROR, EVENT, READ, EOF, TIMEOUT, WRITE }
/**
Modified: trunk/test/org/apache/jboss/web/comet/CometServletTest1.java
===================================================================
--- trunk/test/org/apache/jboss/web/comet/CometServletTest1.java 2008-03-21 01:07:47 UTC
(rev 532)
+++ trunk/test/org/apache/jboss/web/comet/CometServletTest1.java 2008-03-21 01:39:06 UTC
(rev 533)
@@ -39,7 +39,7 @@
int count = 0;
public void event(CometEvent event) throws IOException, ServletException {
- System.out.println("[" +
event.getHttpServletRequest().getSession(true).getId() + "] " +
event.getType());
+ System.out.println((new java.util.Date()) + " [" +
event.getHttpServletRequest().getSession(true).getId() + "] " +
event.getType());
switch (event.getType()) {
case BEGIN:
//event.suspend();
Modified: trunk/webapps/docs/aio.xml
===================================================================
--- trunk/webapps/docs/aio.xml 2008-03-21 01:07:47 UTC (rev 532)
+++ trunk/webapps/docs/aio.xml 2008-03-21 01:39:06 UTC (rev 533)
@@ -82,6 +82,10 @@
this event will be called if the HTTP session associated with the connection
times out, if the web application is reloaded, if the server is shutdown, or
if the Comet connection was closed asynchronously.</li>
+ <li>EventType.EOF - The end of file of the input has been reached, and no further
data is
+ available. This event is sent because it can be difficult to detect otherwise.
+ Following the processing of this event and the processing of any subsequent
+ event, the event will be automatically suspended.</li>
<li>EventType.ERROR - Error will be called by the container in the case where an
IO exception
or a similar unrecoverable error occurs on the connection. Fields that have
been initialized in the begin method should be reset. After this event has
Modified: trunk/webapps/docs/changelog.xml
===================================================================
--- trunk/webapps/docs/changelog.xml 2008-03-21 01:07:47 UTC (rev 532)
+++ trunk/webapps/docs/changelog.xml 2008-03-21 01:39:06 UTC (rev 533)
@@ -29,6 +29,9 @@
Add 3 system properties to StandardHost to allow hardcoding safe default values
for the
auto deployer when JBoss Web is embedded inside AS. (remm)
</fix>
+ <update>
+ Add Comet EOF event when the end of the stream is reached without an error.
(remm)
+ </update>
</changelog>
</subsection>
<subsection name="Coyote">
@@ -36,6 +39,12 @@
<fix>
Better fix for cookie path quoting scenario. (markt)
</fix>
+ <fix>
+ Possible NPE on shutdown if Comet is used. (remm)
+ </fix>
+ <fix>
+ Improve accuracy of typical timeout values. (remm)
+ </fix>
</changelog>
</subsection>
</section>