* This method should not be called asynchronously, as that will have no effect.
* @param request The HTTP servlet request instance
* @param response The HTTP servlet response instance
- * @param timeout The timeout in milliseconds for this connection
+ * @param timeout The timeout in milliseconds for this connection, must be a positive value, larger than 0
* @throws IOException An IOException may be thrown to indicate an IO error,
* or that the EOF has been reached on the connection
* @throws ServletException An exception has occurred, as specified by the root
SelectionKey key = socket.keyFor(endpoint.getPoller().getSelector());\r
if ( key != null ) {\r
NioEndpoint.KeyAttachment attach = (NioEndpoint.KeyAttachment) key.attachment();\r
- if ( attach!=null ) attach.setComet(comet);\r
+ if ( attach!=null ) {\r
+ attach.setComet(comet);\r
+ Integer comettimeout = (Integer)request.getAttribute("org.apache.tomcat.comet.timeout");\r
+ if ( comettimeout != null ) attach.setTimeout(comettimeout.longValue());\r
+ }\r
}\r
\r
} catch (InterruptedIOException e) {\r
SelectionKey key = socket.keyFor(endpoint.getPoller().getSelector());\r
if (key != null) {\r
NioEndpoint.KeyAttachment attach = (NioEndpoint.KeyAttachment) key.attachment();\r
- if (attach != null) attach.setComet(comet);\r
+ if (attach != null) {\r
+ attach.setComet(comet);\r
+ Integer comettimeout = (Integer) request.getAttribute("org.apache.tomcat.comet.timeout");\r
+ if (comettimeout != null) attach.setTimeout(comettimeout.longValue());\r
+ }\r
}\r
} catch (InterruptedIOException e) {\r
error = true;\r
\r
// Advertise comet support through a request attribute\r
request.setAttribute("org.apache.tomcat.comet.support", Boolean.TRUE);\r
+ // Advertise comet timeout support\r
+ request.setAttribute("org.apache.tomcat.comet.timeout.support", Boolean.TRUE);\r
\r
}\r
\r
}//while\r
\r
//timeout\r
- Set keys = selector.keys();\r
+ Set<SelectionKey> keys = selector.keys();\r
long now = System.currentTimeMillis();\r
- for (Iterator iter = keys.iterator(); iter.hasNext(); ) {\r
- SelectionKey key = (SelectionKey) iter.next();\r
+ for (Iterator<SelectionKey> iter = keys.iterator(); iter.hasNext(); ) {\r
+ SelectionKey key = iter.next();\r
try {\r
if (key.interestOps() == SelectionKey.OP_READ) {\r
//only timeout sockets that we are waiting for a read from\r
KeyAttachment ka = (KeyAttachment) key.attachment();\r
long delta = now - ka.getLastAccess();\r
- if (delta > (long) soTimeout) {\r
+ boolean isTimedout = (ka.getTimeout()==-1)?(delta > (long) soTimeout):(delta>ka.getTimeout());\r
+ if (isTimedout) {\r
cancelledKey(key);\r
}\r
}\r
public boolean getWakeUp() { return wakeUp; }\r
public void setWakeUp(boolean wakeUp) { this.wakeUp = wakeUp; }\r
public Object getMutex() {return mutex;}\r
+ public void setTimeout(long timeout) {this.timeout = timeout;}\r
+ public long getTimeout() {return this.timeout;}\r
protected Object mutex = new Object();\r
protected boolean wakeUp = false;\r
protected long lastAccess = System.currentTimeMillis();\r
protected boolean currentAccess = false;\r
protected boolean comet = false;\r
+ protected long timeout = -1;\r
\r
}\r
\r