Author: remy.maucherat(a)jboss.com
Date: 2008-02-27 09:31:04 -0500 (Wed, 27 Feb 2008)
New Revision: 451
Modified:
trunk/java/org/apache/coyote/http11/Http11AprProcessor.java
trunk/java/org/apache/coyote/http11/Http11AprProtocol.java
trunk/java/org/apache/coyote/http11/InternalAprOutputBuffer.java
trunk/java/org/apache/tomcat/util/net/AprEndpoint.java
Log:
- Improve handling of resume (which would cause sending of a resume event, just like write
does), as it
is not practical to have to code around an event which may not be sent.
Modified: trunk/java/org/apache/coyote/http11/Http11AprProcessor.java
===================================================================
--- trunk/java/org/apache/coyote/http11/Http11AprProcessor.java 2008-02-26 15:01:53 UTC
(rev 450)
+++ trunk/java/org/apache/coyote/http11/Http11AprProcessor.java 2008-02-27 14:31:04 UTC
(rev 451)
@@ -327,6 +327,7 @@
protected int cometTimeout = -1;
protected boolean readNotifications = true;
protected boolean writeNotification = false;
+ protected boolean resumeNotification = false;
protected boolean nonBlocking = true;
protected boolean cometProcessing = false;
@@ -349,6 +350,11 @@
}
+ public boolean getResumeNotification() {
+ return resumeNotification;
+ }
+
+
public boolean getReadNotifications() {
return readNotifications;
}
@@ -785,6 +791,9 @@
// that the servlet is not going to be able to write bytes. This will be
handled properly,
// but is wasteful.
outputBuffer.flushLeftover();
+ } else if (status == SocketStatus.OPEN_CALLBACK) {
+ // The resume notification is now done
+ resumeNotification = false;
}
containerThread.set(Boolean.TRUE);
rp.setStage(org.apache.coyote.Constants.STAGE_SERVICE);
@@ -1272,11 +1281,15 @@
readNotifications = false;
} else if (actionCode == ActionCode.ACTION_COMET_RESUME) {
readNotifications = true;
- if (!cometProcessing) {
+ // An event is being processed already: adding for resume will be done
+ // when the socket gets back to the poller
+ if (cometProcessing) {
+ resumeNotification = true;
+ } else {
endpoint.getCometPoller().add(socket, timeout, false, false, true);
}
} else if (actionCode == ActionCode.ACTION_COMET_WRITE) {
- // An event is being processed already:adding for write will be done
+ // An event is being processed already: adding for write will be done
// when the socket gets back to the poller
if (cometProcessing) {
writeNotification = true;
Modified: trunk/java/org/apache/coyote/http11/Http11AprProtocol.java
===================================================================
--- trunk/java/org/apache/coyote/http11/Http11AprProtocol.java 2008-02-26 15:01:53 UTC
(rev 450)
+++ trunk/java/org/apache/coyote/http11/Http11AprProtocol.java 2008-02-27 14:31:04 UTC
(rev 451)
@@ -566,7 +566,7 @@
} else {
if (proto.endpoint.isRunning()) {
proto.endpoint.getCometPoller().add(socket,
result.getCometTimeout(),
- result.getReadNotifications(),
result.getWriteNotification(), false);
+ result.getReadNotifications(),
result.getWriteNotification(), result.getResumeNotification());
}
}
result.endProcessing();
Modified: trunk/java/org/apache/coyote/http11/InternalAprOutputBuffer.java
===================================================================
--- trunk/java/org/apache/coyote/http11/InternalAprOutputBuffer.java 2008-02-26 15:01:53
UTC (rev 450)
+++ trunk/java/org/apache/coyote/http11/InternalAprOutputBuffer.java 2008-02-27 14:31:04
UTC (rev 451)
@@ -769,6 +769,8 @@
// FIXME: the fact that it's a container thread was already
tested in doWrite
if (Http11AprProcessor.containerThread.get() == Boolean.TRUE) {
Socket.optSet(socket, Socket.APR_SO_NONBLOCK, 0);
+ // Also use the usual timeout
+ Socket.timeoutSet(socket, 20000*1000);
// Send leftover bytes
res = Socket.send(socket, leftover.getBuffer(),
leftover.getOffset(), leftover.getEnd());
// Send current buffer
@@ -776,6 +778,7 @@
res = Socket.sendbb(socket, 0, bbuf.position());
}
Socket.optSet(socket, Socket.APR_SO_NONBLOCK, 1);
+ Socket.timeoutSet(socket, 0);
} else {
throw new IOException("Backlog");
}
Modified: trunk/java/org/apache/tomcat/util/net/AprEndpoint.java
===================================================================
--- trunk/java/org/apache/tomcat/util/net/AprEndpoint.java 2008-02-26 15:01:53 UTC (rev
450)
+++ trunk/java/org/apache/tomcat/util/net/AprEndpoint.java 2008-02-27 14:31:04 UTC (rev
451)
@@ -1527,28 +1527,35 @@
SocketInfo info = localAddList.get();
while (info != null) {
if (info.read || info.write) {
- // Store timeout
- timeouts.add(info.socket, System.currentTimeMillis() +
info.timeout);
- if (comet) {
+ if (info.resume) {
+ // Resume event
+ timeouts.remove(info.socket);
removeFromPoller(info.socket);
- }
- // Windows only: check status code and loop over the
other pollers
- int events = 0;
- if (info.read) {
- events = Poll.APR_POLLIN;
- }
- if (info.write) {
- events = events | Poll.APR_POLLOUT;
- }
- if (!addToPoller(info.socket, events)) {
- // Can't do anything: close the socket right
away
+ processSocket(info.socket,
SocketStatus.OPEN_CALLBACK);
+ } else {
+ // Store timeout
+ timeouts.add(info.socket, System.currentTimeMillis()
+ info.timeout);
if (comet) {
- processSocket(info.socket, SocketStatus.ERROR);
+ removeFromPoller(info.socket);
+ }
+ // Windows only: check status code and loop over the
other pollers
+ int events = 0;
+ if (info.read) {
+ events = Poll.APR_POLLIN;
+ }
+ if (info.write) {
+ events = events | Poll.APR_POLLOUT;
+ }
+ if (!addToPoller(info.socket, events)) {
+ // Can't do anything: close the socket right
away
+ if (comet) {
+ processSocket(info.socket,
SocketStatus.ERROR);
+ } else {
+ Socket.destroy(info.socket);
+ }
} else {
- Socket.destroy(info.socket);
+ keepAliveCount++;
}
- } else {
- keepAliveCount++;
}
} else {
// This is either a resume or a suspend.