if (request.getWrapper() != null) {
boolean error = false;
+ boolean read = false;
try {
if (status == SocketStatus.OPEN) {
if (response.isClosed()) {
} 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);
}
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) {
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
/**
+ * Flag which if a read was performed.
+ */
+ private boolean didRead = false;
+
+
+ /**
* Byte chunk used to input bytes.
*/
private ByteChunk inputChunk = new ByteChunk();
}
- public int available()
- throws IOException {
+ public int available() {
int available = 0;
if (state == BYTE_STATE) {
available = bb.getLength();
}
+ 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);
}
+ /**
+ * 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