if (comettimeout != null) attach.setTimeout(comettimeout.longValue());
} else {
//reset the timeout
- if (keepAlive && keepAliveTimeout>0) {
+ if (keepAlive) {
attach.setTimeout(keepAliveTimeout);
} else {
attach.setTimeout(soTimeout);
long soTimeout = endpoint.getSoTimeout();
//reset the timeout
- if (keepAlive && keepAliveTimeout>0) {
+ if (keepAlive) {
attach.setTimeout(keepAliveTimeout);
} else {
attach.setTimeout(soTimeout);
openSocket = true;
// Check to see if we have read any of the request line yet
if (inputBuffer.getParsingRequestLinePhase() < 2) {
- // Haven't read the request line. Must be keep-alive
- // Make sure poller uses keepAlive from here onwards
- socket.setTimeout(endpoint.getKeepAliveTimeout());
+ if (socket.getLastAccess() > -1 || keptAlive) {
+ // Haven't read the request line and have previously processed a
+ // request. Must be keep-alive. Make sure poller uses keepAlive.
+ socket.setTimeout(endpoint.getKeepAliveTimeout());
+ }
} else {
// Started to read request line. Need to keep processor
// associated with socket
@Override
protected void setRequestLineReadTimeout() throws IOException {
- int standardTimeout = 0;
-
- if (keptAlive) {
- if (keepAliveTimeout > 0) {
- standardTimeout = keepAliveTimeout;
- } else if (endpoint.getSoTimeout() > 0) {
- standardTimeout = endpoint.getSoTimeout();
- }
- }
/*
* When there is no data in the buffer and this is not the first
* request on this connection and timeouts are being used the
* This is a little hacky but better than exposing the socket
* and the timeout info to the InputBuffer
*/
- if (inputBuffer.lastValid == 0 && socket.getLastAccess() > -1 &&
- standardTimeout > 0) {
-
- long queueTime = System.currentTimeMillis() - socket.getLastAccess();
+ if (inputBuffer.lastValid == 0 && socket.getLastAccess() > -1) {
int firstReadTimeout;
- if (queueTime >= standardTimeout) {
- // Queued for longer than timeout but there might be
- // data so use shortest possible timeout
- firstReadTimeout = 1;
+ if (keepAliveTimeout == -1) {
+ firstReadTimeout = 0;
} else {
- // Cast is safe since queueTime must be less than
- // standardTimeout which is an int
- firstReadTimeout = standardTimeout - (int) queueTime;
+ long queueTime =
+ System.currentTimeMillis() - socket.getLastAccess();
+
+ if (queueTime >= keepAliveTimeout) {
+ // Queued for longer than timeout but there might be
+ // data so use shortest possible timeout
+ firstReadTimeout = 1;
+ } else {
+ // Cast is safe since queueTime must be less than
+ // keepAliveTimeout which is an int
+ firstReadTimeout = keepAliveTimeout - (int) queueTime;
+ }
}
socket.getSocket().setSoTimeout(firstReadTimeout);
if (!inputBuffer.fill()) {
private BindState bindState = BindState.UNBOUND;
/**
- * Keepalive timeout, if lesser or equal to 0 then soTimeout will be used.
+ * Keepalive timeout, if not set the soTimeout is used.
*/
- private int keepAliveTimeout = -1;
- public int getKeepAliveTimeout() { return keepAliveTimeout;}
+ private Integer keepAliveTimeout = null;
+ public int getKeepAliveTimeout() {
+ if (keepAliveTimeout == null) {
+ return getSoTimeout();
+ } else {
+ return keepAliveTimeout.intValue();
+ }
+ }
public void setKeepAliveTimeout(int keepAliveTimeout) {
- this.keepAliveTimeout = keepAliveTimeout;
+ this.keepAliveTimeout = Integer.valueOf(keepAliveTimeout);
}
int size = getMaxConnections() / pollerThreadCount;
int keepAliveTimeout = getKeepAliveTimeout();
int socketTimeout = socketProperties.getSoTimeout();
- if (keepAliveTimeout > 0 && !comet) {
+ if (keepAliveTimeout != socketTimeout && !comet) {
separateKeepAlive = true;
}
connectionPollset = allocatePoller(size, pool, socketTimeout);
(ka.interestOps()&SelectionKey.OP_WRITE) == SelectionKey.OP_WRITE) {
//only timeout sockets that we are waiting for a read from
long delta = now - ka.getLastAccess();
- long timeout = (ka.getTimeout()==-1)?((long) socketProperties.getSoTimeout()):(ka.getTimeout());
+ long timeout = ka.getTimeout();
boolean isTimedout = timeout > 0 && delta > timeout;
if ( close ) {
key.interestOps(0);
key.interestOps(0);
ka.interestOps(0); //avoid duplicate timeout calls
cancelledKey(key, SocketStatus.TIMEOUT,true);
- } else {
+ } else if (timeout > -1) {
long nextTime = now+(timeout-delta);
nextExpiration = (nextTime < nextExpiration)?nextTime:nextExpiration;
}