diff --git a/jetty-client/src/main/java/org/eclipse/jetty/client/HttpDestination.java b/jetty-client/src/main/java/org/eclipse/jetty/client/HttpDestination.java index 3992a5cef5b..18a197ced6a 100644 --- a/jetty-client/src/main/java/org/eclipse/jetty/client/HttpDestination.java +++ b/jetty-client/src/main/java/org/eclipse/jetty/client/HttpDestination.java @@ -439,7 +439,9 @@ public class HttpDestination implements Dumpable public void returnIdleConnection(AbstractHttpConnection connection) { - connection.onIdleExpired(); + // TODO work out the real idle time; + long idleForMs=connection!=null&&connection.getEndPoint()!=null?connection.getEndPoint().getMaxIdleTime():-1; + connection.onIdleExpired(idleForMs); boolean startConnection = false; synchronized (this) diff --git a/jetty-client/src/main/java/org/eclipse/jetty/client/SelectConnector.java b/jetty-client/src/main/java/org/eclipse/jetty/client/SelectConnector.java index efb39f39f82..b3c93a7dee8 100644 --- a/jetty-client/src/main/java/org/eclipse/jetty/client/SelectConnector.java +++ b/jetty-client/src/main/java/org/eclipse/jetty/client/SelectConnector.java @@ -437,9 +437,9 @@ class SelectConnector extends AbstractLifeCycle implements HttpClient.Connector, _endp.setMaxIdleTime(timeMs); } - public void onIdleExpired() + public void onIdleExpired(long idleForMs) { - _endp.onIdleExpired(); + _endp.onIdleExpired(idleForMs); } public void setCheckForIdle(boolean check) diff --git a/jetty-io/src/main/java/org/eclipse/jetty/io/AbstractConnection.java b/jetty-io/src/main/java/org/eclipse/jetty/io/AbstractConnection.java index a6004a9e102..a9167eba32e 100644 --- a/jetty-io/src/main/java/org/eclipse/jetty/io/AbstractConnection.java +++ b/jetty-io/src/main/java/org/eclipse/jetty/io/AbstractConnection.java @@ -35,11 +35,11 @@ public abstract class AbstractConnection implements Connection return _endp; } - public void onIdleExpired() + public void onIdleExpired(long idleForMs) { try { - LOG.debug("onIdleExpired {} {}",this,_endp); + LOG.debug("onIdleExpired {}ms {} {}",idleForMs,this,_endp); if (_endp.isInputShutdown() || _endp.isOutputShutdown()) _endp.close(); else diff --git a/jetty-io/src/main/java/org/eclipse/jetty/io/AsyncEndPoint.java b/jetty-io/src/main/java/org/eclipse/jetty/io/AsyncEndPoint.java index 630fe1133ab..992ad7a195a 100644 --- a/jetty-io/src/main/java/org/eclipse/jetty/io/AsyncEndPoint.java +++ b/jetty-io/src/main/java/org/eclipse/jetty/io/AsyncEndPoint.java @@ -35,8 +35,9 @@ public interface AsyncEndPoint extends ConnectedEndPoint /** Callback when idle. *

An endpoint is idle if there has been no IO activity for * {@link #getMaxIdleTime()} and {@link #isCheckForIdle()} is true. + * @param idleForMs TODO */ - public void onIdleExpired(); + public void onIdleExpired(long idleForMs); /* ------------------------------------------------------------ */ /** Set if the endpoint should be checked for idleness diff --git a/jetty-io/src/main/java/org/eclipse/jetty/io/Connection.java b/jetty-io/src/main/java/org/eclipse/jetty/io/Connection.java index 6519905dae6..19cf3bee60e 100644 --- a/jetty-io/src/main/java/org/eclipse/jetty/io/Connection.java +++ b/jetty-io/src/main/java/org/eclipse/jetty/io/Connection.java @@ -54,6 +54,7 @@ public interface Connection /** * Called when the connection idle timeout expires + * @param idleForMs TODO */ - void onIdleExpired(); + void onIdleExpired(long idleForMs); } diff --git a/jetty-io/src/main/java/org/eclipse/jetty/io/nio/SelectChannelEndPoint.java b/jetty-io/src/main/java/org/eclipse/jetty/io/nio/SelectChannelEndPoint.java index cc698d5e4e7..39cd2205dc3 100644 --- a/jetty-io/src/main/java/org/eclipse/jetty/io/nio/SelectChannelEndPoint.java +++ b/jetty-io/src/main/java/org/eclipse/jetty/io/nio/SelectChannelEndPoint.java @@ -280,17 +280,22 @@ public class SelectChannelEndPoint extends ChannelEndPoint implements AsyncEndPo public void checkIdleTimestamp(long now) { long idleTimestamp=_idleTimestamp; - if (idleTimestamp!=0 && _maxIdleTime>0 && now>(idleTimestamp+_maxIdleTime)) + + if (idleTimestamp!=0 && _maxIdleTime>0) { - onIdleExpired(); - _idleTimestamp=now; + long idleForMs=now-idleTimestamp; + if (idleForMs>_maxIdleTime) + { + onIdleExpired(idleForMs); + _idleTimestamp=now; + } } } /* ------------------------------------------------------------ */ - public void onIdleExpired() + public void onIdleExpired(long idleForMs) { - _connection.onIdleExpired(); + _connection.onIdleExpired(idleForMs); } /* ------------------------------------------------------------ */ diff --git a/jetty-io/src/main/java/org/eclipse/jetty/io/nio/SslConnection.java b/jetty-io/src/main/java/org/eclipse/jetty/io/nio/SslConnection.java index 82d6fbeceb7..d8cee6277f5 100644 --- a/jetty-io/src/main/java/org/eclipse/jetty/io/nio/SslConnection.java +++ b/jetty-io/src/main/java/org/eclipse/jetty/io/nio/SslConnection.java @@ -237,16 +237,17 @@ public class SslConnection extends AbstractConnection implements AsyncConnection /* ------------------------------------------------------------ */ @Override - public void onIdleExpired() + public void onIdleExpired(long idleForMs) { try { + LOG.debug("onIdleExpired {}ms on {}",idleForMs,this); _sslEndPoint.shutdownOutput(); } catch (IOException e) { LOG.warn(e); - super.onIdleExpired(); + super.onIdleExpired(idleForMs); } } @@ -700,9 +701,9 @@ public class SslConnection extends AbstractConnection implements AsyncConnection _aEndp.scheduleWrite(); } - public void onIdleExpired() + public void onIdleExpired(long idleForMs) { - _aEndp.onIdleExpired(); + _aEndp.onIdleExpired(idleForMs); } public void setCheckForIdle(boolean check) diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/handler/ConnectHandler.java b/jetty-server/src/main/java/org/eclipse/jetty/server/handler/ConnectHandler.java index b1fb779f5b0..9ddd15bb252 100644 --- a/jetty-server/src/main/java/org/eclipse/jetty/server/handler/ConnectHandler.java +++ b/jetty-server/src/main/java/org/eclipse/jetty/server/handler/ConnectHandler.java @@ -667,7 +667,7 @@ public class ConnectHandler extends HandlerWrapper _endPoint.shutdownOutput(); } - public void onIdleExpired() + public void onIdleExpired(long idleForMs) { try { @@ -834,7 +834,7 @@ public class ConnectHandler extends HandlerWrapper _endPoint.shutdownOutput(); } - public void onIdleExpired() + public void onIdleExpired(long idleForMs) { try { diff --git a/jetty-websocket/src/main/java/org/eclipse/jetty/websocket/WebSocketConnectionD06.java b/jetty-websocket/src/main/java/org/eclipse/jetty/websocket/WebSocketConnectionD06.java index 7078d51b851..96c3415dd5a 100644 --- a/jetty-websocket/src/main/java/org/eclipse/jetty/websocket/WebSocketConnectionD06.java +++ b/jetty-websocket/src/main/java/org/eclipse/jetty/websocket/WebSocketConnectionD06.java @@ -192,7 +192,7 @@ public class WebSocketConnectionD06 extends AbstractConnection implements WebSoc /* ------------------------------------------------------------ */ @Override - public void onIdleExpired() + public void onIdleExpired(long idleForMs) { closeOut(WebSocketConnectionD06.CLOSE_NORMAL,"Idle"); } diff --git a/jetty-websocket/src/main/java/org/eclipse/jetty/websocket/WebSocketConnectionD08.java b/jetty-websocket/src/main/java/org/eclipse/jetty/websocket/WebSocketConnectionD08.java index 13294e03fa1..bbdb76a3123 100644 --- a/jetty-websocket/src/main/java/org/eclipse/jetty/websocket/WebSocketConnectionD08.java +++ b/jetty-websocket/src/main/java/org/eclipse/jetty/websocket/WebSocketConnectionD08.java @@ -242,10 +242,9 @@ public class WebSocketConnectionD08 extends AbstractConnection implements WebSoc /* ------------------------------------------------------------ */ @Override - public void onIdleExpired() + public void onIdleExpired(long idleForMs) { - long idle = System.currentTimeMillis()-((SelectChannelEndPoint)_endp).getIdleTimestamp(); - closeOut(WebSocketConnectionD08.CLOSE_NORMAL,"Idle for "+idle+"ms > "+_endp.getMaxIdleTime()+"ms"); + closeOut(WebSocketConnectionD08.CLOSE_NORMAL,"Idle for "+idleForMs+"ms > "+_endp.getMaxIdleTime()+"ms"); } /* ------------------------------------------------------------ */ diff --git a/jetty-websocket/src/main/java/org/eclipse/jetty/websocket/WebSocketConnectionD13.java b/jetty-websocket/src/main/java/org/eclipse/jetty/websocket/WebSocketConnectionD13.java index 3b1962a4024..c91c8376a13 100644 --- a/jetty-websocket/src/main/java/org/eclipse/jetty/websocket/WebSocketConnectionD13.java +++ b/jetty-websocket/src/main/java/org/eclipse/jetty/websocket/WebSocketConnectionD13.java @@ -271,10 +271,9 @@ public class WebSocketConnectionD13 extends AbstractConnection implements WebSoc /* ------------------------------------------------------------ */ @Override - public void onIdleExpired() + public void onIdleExpired(long idleForMs) { - long idle = System.currentTimeMillis()-((SelectChannelEndPoint)_endp).getIdleTimestamp(); - closeOut(WebSocketConnectionD13.CLOSE_NORMAL,"Idle for "+idle+"ms > "+_endp.getMaxIdleTime()+"ms"); + closeOut(WebSocketConnectionD13.CLOSE_NORMAL,"Idle for "+idleForMs+"ms > "+_endp.getMaxIdleTime()+"ms"); } /* ------------------------------------------------------------ */ diff --git a/jetty-websocket/src/test/java/org/eclipse/jetty/websocket/WebSocketMessageD08Test.java b/jetty-websocket/src/test/java/org/eclipse/jetty/websocket/WebSocketMessageD08Test.java index ee321cd032f..f1bd18c012b 100644 --- a/jetty-websocket/src/test/java/org/eclipse/jetty/websocket/WebSocketMessageD08Test.java +++ b/jetty-websocket/src/test/java/org/eclipse/jetty/websocket/WebSocketMessageD08Test.java @@ -569,29 +569,23 @@ public class WebSocketMessageD08Test // Send enough messages to fill receive buffer - long max=0; long start=System.currentTimeMillis(); String mesg="How Now Brown Cow"; for (int i=0;i1000); // was blocked + // if (duration<1500) + System.err.println("max="+duration); + assertTrue(duration>1500); // was blocked } @Test diff --git a/jetty-websocket/src/test/java/org/eclipse/jetty/websocket/WebSocketOverSSLTest.java b/jetty-websocket/src/test/java/org/eclipse/jetty/websocket/WebSocketOverSSLTest.java index a9e07a0b60d..fd73e6b43ff 100644 --- a/jetty-websocket/src/test/java/org/eclipse/jetty/websocket/WebSocketOverSSLTest.java +++ b/jetty-websocket/src/test/java/org/eclipse/jetty/websocket/WebSocketOverSSLTest.java @@ -175,7 +175,7 @@ public class WebSocketOverSSLTest for (int i = 0; i < count; ++i) _connection.sendMessage(message); - Assert.assertTrue(clientLatch.await(5, TimeUnit.SECONDS)); + Assert.assertTrue(clientLatch.await(20, TimeUnit.SECONDS)); // While messages may have all arrived, the SSL close alert // may be in the way so give some time for it to be processed.