- 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
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);
}
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;
/**
- * Flag which if a read was performed.
- */
- private boolean didRead = true;
-
-
- /**
* Byte chunk used to input bytes.
*/
private ByteChunk inputChunk = new ByteChunk();
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
return -1;
state = BYTE_STATE;
- didRead = true;
int result = coyoteRequest.doRead(bb);
}
+ /**
+ * Clear cached encoders (to save memory for Comet requests).
+ */
+ public boolean read()
+ throws IOException {
+ return (inputBuffer.realReadBytes(null, 0, 0) > 0);
+ }
+
+
// -------------------------------------------------------- Request Methods
}
- public boolean didRead() {
- return inputBuffer.didRead();
- }
-
-
- public void resetDidRead() {
- inputBuffer.resetDidRead();
- }
-
-
// ------------------------------------------------------ Protected Methods