From d79b5115072f99ded95fb71fc19e771a6f9f6d2a Mon Sep 17 00:00:00 2001 From: Simone Bordet Date: Mon, 30 Jan 2012 20:35:51 +0100 Subject: [PATCH] Notifying onConnect(Session) from the SPDY connection on first call to handle(). --- .../jetty/spdy/nio/AsyncSPDYConnection.java | 4 +- .../jetty/spdy/nio/SPDYServerConnector.java | 44 ++++++++++++++++--- .../jetty/spdy/SSLSPDYSynReplyTest.java | 9 ++++ 3 files changed, 48 insertions(+), 9 deletions(-) diff --git a/src/main/java/org/eclipse/jetty/spdy/nio/AsyncSPDYConnection.java b/src/main/java/org/eclipse/jetty/spdy/nio/AsyncSPDYConnection.java index 4799e56fefe..e026580910c 100644 --- a/src/main/java/org/eclipse/jetty/spdy/nio/AsyncSPDYConnection.java +++ b/src/main/java/org/eclipse/jetty/spdy/nio/AsyncSPDYConnection.java @@ -40,10 +40,8 @@ public class AsyncSPDYConnection extends AbstractConnection implements AsyncConn boolean progress = true; while (endPoint.isOpen() && progress) { - progress = false; - int filled = fill(); - progress |= filled > 0; + progress = filled > 0; logger.debug("Filled {} from {}", filled, endPoint); int flushed = flush(); diff --git a/src/main/java/org/eclipse/jetty/spdy/nio/SPDYServerConnector.java b/src/main/java/org/eclipse/jetty/spdy/nio/SPDYServerConnector.java index 26dd099d018..0c5ece333d8 100644 --- a/src/main/java/org/eclipse/jetty/spdy/nio/SPDYServerConnector.java +++ b/src/main/java/org/eclipse/jetty/spdy/nio/SPDYServerConnector.java @@ -1,5 +1,6 @@ package org.eclipse.jetty.spdy.nio; +import java.io.IOException; import java.nio.channels.SocketChannel; import java.util.Arrays; import java.util.List; @@ -7,6 +8,8 @@ import javax.net.ssl.SSLEngine; import javax.net.ssl.SSLException; import org.eclipse.jetty.io.AsyncEndPoint; +import org.eclipse.jetty.io.Connection; +import org.eclipse.jetty.io.EndPoint; import org.eclipse.jetty.io.nio.AsyncConnection; import org.eclipse.jetty.io.nio.SslConnection; import org.eclipse.jetty.npn.NextProtoNego; @@ -14,6 +17,7 @@ import org.eclipse.jetty.server.nio.SelectChannelConnector; import org.eclipse.jetty.spdy.CompressionFactory; import org.eclipse.jetty.spdy.StandardCompressionFactory; import org.eclipse.jetty.spdy.StandardSession; +import org.eclipse.jetty.spdy.api.Session; import org.eclipse.jetty.spdy.api.server.ServerSessionFrameListener; import org.eclipse.jetty.spdy.generator.Generator; import org.eclipse.jetty.spdy.parser.Parser; @@ -129,17 +133,45 @@ public class SPDYServerConnector extends SelectChannelConnector Parser parser = new Parser(compressionFactory.newDecompressor()); Generator generator = new Generator(compressionFactory.newCompressor()); - AsyncSPDYConnection connection = new AsyncSPDYConnection(endPoint, parser); + ServerAsyncSPDYConnection connection = new ServerAsyncSPDYConnection(endPoint, parser, listener); endPoint.setConnection(connection); - StandardSession session = new StandardSession(connection, 2, listener, generator); + final StandardSession session = new StandardSession(connection, 2, listener, generator); parser.addListener(session); - - // NPE guard to support tests - if (listener != null) - listener.onConnect(session); + connection.setSession(session); return connection; } } + + private class ServerAsyncSPDYConnection extends AsyncSPDYConnection + { + private final ServerSessionFrameListener listener; + private volatile Session session; + + private ServerAsyncSPDYConnection(EndPoint endp, Parser parser, ServerSessionFrameListener listener) + { + super(endp, parser); + this.listener = listener; + } + + @Override + public Connection handle() throws IOException + { + final Session session = this.session; + if (session != null) + { + // NPE guard to support tests + if (listener != null) + listener.onConnect(session); + this.session = null; + } + return super.handle(); + } + + private void setSession(Session session) + { + this.session = session; + } + } } diff --git a/src/test/java/org/eclipse/jetty/spdy/SSLSPDYSynReplyTest.java b/src/test/java/org/eclipse/jetty/spdy/SSLSPDYSynReplyTest.java index 43387f1a51e..12cc8304d20 100644 --- a/src/test/java/org/eclipse/jetty/spdy/SSLSPDYSynReplyTest.java +++ b/src/test/java/org/eclipse/jetty/spdy/SSLSPDYSynReplyTest.java @@ -7,6 +7,7 @@ import org.eclipse.jetty.spdy.nio.SPDYClient; import org.eclipse.jetty.spdy.nio.SPDYServerConnector; import org.eclipse.jetty.util.ssl.SslContextFactory; import org.eclipse.jetty.util.thread.ThreadPool; +import org.junit.Assume; import org.junit.Before; public class SSLSPDYSynReplyTest extends SPDYSynReplyTest @@ -28,6 +29,14 @@ public class SSLSPDYSynReplyTest extends SPDYSynReplyTest @Before public void init() { + try + { + getClass().getClassLoader().loadClass("org.eclipse.jetty.npn.Agent"); + } + catch (ClassNotFoundException x) + { + Assume.assumeNoException(x); + } NextProtoNego.debug = true; } }