From 9b3f47524495725a922b335111d5cfb89ce541c4 Mon Sep 17 00:00:00 2001 From: remm Date: Thu, 3 May 2007 23:54:31 +0000 Subject: [PATCH] - 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. git-svn-id: https://svn.apache.org/repos/asf/tomcat/tc6.0.x/trunk@535030 13f79535-47bb-0310-9956-ffa450edef68 --- .../apache/catalina/connector/CoyoteAdapter.java | 24 ++++++++++++++++----- .../org/apache/catalina/connector/InputBuffer.java | 25 ---------------------- java/org/apache/catalina/connector/Request.java | 19 ++++++++-------- 3 files changed, 28 insertions(+), 40 deletions(-) diff --git a/java/org/apache/catalina/connector/CoyoteAdapter.java b/java/org/apache/catalina/connector/CoyoteAdapter.java index 808f1c76f..42d4af812 100644 --- a/java/org/apache/catalina/connector/CoyoteAdapter.java +++ b/java/org/apache/catalina/connector/CoyoteAdapter.java @@ -127,10 +127,24 @@ public class CoyoteAdapter 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 @@ public class CoyoteAdapter } 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; diff --git a/java/org/apache/catalina/connector/InputBuffer.java b/java/org/apache/catalina/connector/InputBuffer.java index ca188a4bc..f176a3dd2 100644 --- a/java/org/apache/catalina/connector/InputBuffer.java +++ b/java/org/apache/catalina/connector/InputBuffer.java @@ -99,12 +99,6 @@ public class InputBuffer extends Reader /** - * 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 @@ public class InputBuffer extends Reader 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 @@ public class InputBuffer extends Reader return -1; state = BYTE_STATE; - didRead = true; int result = coyoteRequest.doRead(bb); diff --git a/java/org/apache/catalina/connector/Request.java b/java/org/apache/catalina/connector/Request.java index b0a84e95c..80709c353 100644 --- a/java/org/apache/catalina/connector/Request.java +++ b/java/org/apache/catalina/connector/Request.java @@ -458,6 +458,15 @@ public class Request } + /** + * 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 class Request } - public boolean didRead() { - return inputBuffer.didRead(); - } - - - public void resetDidRead() { - inputBuffer.resetDidRead(); - } - - // ------------------------------------------------------ Protected Methods -- 2.11.0