From 009f8176a189dba9f783a00217a0b1ffc44ff554 Mon Sep 17 00:00:00 2001 From: Greg Wilkins Date: Wed, 28 Dec 2011 23:09:33 +1100 Subject: [PATCH] JETTY-1467 close half closed when idle --- .../org/eclipse/jetty/embedded/LikeJettyXml.java | 8 ++++++++ .../jetty/server/BlockingHttpConnection.java | 7 +++++++ .../server/nio/BlockingChannelConnector.java | 16 ++++++++++++++++ 3 files changed, 31 insertions(+) diff --git a/example-jetty-embedded/src/main/java/org/eclipse/jetty/embedded/LikeJettyXml.java b/example-jetty-embedded/src/main/java/org/eclipse/jetty/embedded/LikeJettyXml.java index 899c682bc08..778c9b0b234 100644 --- a/example-jetty-embedded/src/main/java/org/eclipse/jetty/embedded/LikeJettyXml.java +++ b/example-jetty-embedded/src/main/java/org/eclipse/jetty/embedded/LikeJettyXml.java @@ -29,6 +29,7 @@ import org.eclipse.jetty.server.handler.DefaultHandler; import org.eclipse.jetty.server.handler.HandlerCollection; import org.eclipse.jetty.server.handler.RequestLogHandler; import org.eclipse.jetty.server.handler.StatisticsHandler; +import org.eclipse.jetty.server.nio.BlockingChannelConnector; import org.eclipse.jetty.server.nio.SelectChannelConnector; import org.eclipse.jetty.server.ssl.SslSelectChannelConnector; import org.eclipse.jetty.server.ssl.SslSocketConnector; @@ -68,6 +69,13 @@ public class LikeJettyXml server.setConnectors(new Connector[] { connector }); + + BlockingChannelConnector bConnector = new BlockingChannelConnector(); + bConnector.setPort(8888); + bConnector.setMaxIdleTime(30000); + bConnector.setConfidentialPort(8443); + bConnector.setAcceptors(1); + server.addConnector(bConnector); SslSelectChannelConnector ssl_connector = new SslSelectChannelConnector(); ssl_connector.setPort(8443); diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/BlockingHttpConnection.java b/jetty-server/src/main/java/org/eclipse/jetty/server/BlockingHttpConnection.java index ec15289f914..6b5c8284da4 100644 --- a/jetty-server/src/main/java/org/eclipse/jetty/server/BlockingHttpConnection.java +++ b/jetty-server/src/main/java/org/eclipse/jetty/server/BlockingHttpConnection.java @@ -110,6 +110,13 @@ public class BlockingHttpConnection extends AbstractHttpConnection _endp.shutdownOutput(); } } + + // If we don't have a committed response and we are not suspended + if (_endp.isInputShutdown() && _generator.isIdle() && !_request.getAsyncContinuation().isSuspended()) + { + // then no more can happen, so close. + _endp.close(); + } } } diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/nio/BlockingChannelConnector.java b/jetty-server/src/main/java/org/eclipse/jetty/server/nio/BlockingChannelConnector.java index 98716285b71..8e331142e6a 100644 --- a/jetty-server/src/main/java/org/eclipse/jetty/server/nio/BlockingChannelConnector.java +++ b/jetty-server/src/main/java/org/eclipse/jetty/server/nio/BlockingChannelConnector.java @@ -17,6 +17,7 @@ import java.io.IOException; import java.net.InetSocketAddress; import java.net.Socket; import java.nio.channels.ByteChannel; +import java.nio.channels.SelectionKey; import java.nio.channels.ServerSocketChannel; import java.nio.channels.SocketChannel; import java.util.Set; @@ -341,5 +342,20 @@ public class BlockingChannelConnector extends AbstractNIOConnector } } } + + /* ------------------------------------------------------------ */ + @Override + public String toString() + { + return String.format("BCEP@%x{l(%s)<->r(%s),open=%b,ishut=%b,oshut=%b}-{%s}", + hashCode(), + _socket.getRemoteSocketAddress(), + _socket.getLocalSocketAddress(), + isOpen(), + isInputShutdown(), + isOutputShutdown(), + _connection); + } + } }