diff --git a/src/main/java/org/jboss/netty/channel/socket/http/HttpTunnelWorker.java b/src/main/java/org/jboss/netty/channel/socket/http/HttpTunnelWorker.java index 66792f8c4d..935d7db249 100644 --- a/src/main/java/org/jboss/netty/channel/socket/http/HttpTunnelWorker.java +++ b/src/main/java/org/jboss/netty/channel/socket/http/HttpTunnelWorker.java @@ -32,6 +32,7 @@ import org.jboss.netty.channel.ChannelFuture; /** * @author The Netty Project (netty-dev@lists.jboss.org) * @author Andy Taylor (andy.taylor@jboss.org) + * @author Trustin Lee (tlee@redhat.com) * @version $Rev$, $Date$ */ final class HttpTunnelWorker implements Runnable { @@ -46,12 +47,12 @@ final class HttpTunnelWorker implements Runnable { channel.workerThread = Thread.currentThread(); while (channel.isOpen()) { - synchronized (this) { + synchronized (channel.interestOpsLock) { while (!channel.isReadable()) { try { // notify() is not called at all. // close() and setInterestOps() calls Thread.interrupt() - this.wait(); + channel.interestOpsLock.wait(); } catch (InterruptedException e) { if (!channel.isOpen()) { @@ -73,7 +74,11 @@ final class HttpTunnelWorker implements Runnable { } if (buf != null) { - fireMessageReceived(channel, ChannelBuffers.wrappedBuffer(buf)); + fireMessageReceived( + channel, + ChannelBuffers.wrappedBuffer( + channel.getConfig().getBufferFactory().getDefaultOrder(), + buf)); } } @@ -90,8 +95,10 @@ final class HttpTunnelWorker implements Runnable { Object message) { try { - channel.sendChunk((ChannelBuffer) message); + ChannelBuffer buf = (ChannelBuffer) message; + int writtenBytes = channel.sendChunk(buf); future.setSuccess(); + fireWriteComplete(channel, writtenBytes); } catch (Throwable t) { future.setFailure(t); @@ -120,14 +127,17 @@ final class HttpTunnelWorker implements Runnable { future.setSuccess(); if (changed) { - // Notify the worker so it stops or continues reading. - Thread currentThread = Thread.currentThread(); - Thread workerThread = channel.workerThread; - if (workerThread != null && currentThread != workerThread) { - workerThread.interrupt(); + synchronized (channel.interestOpsLock) { + channel.setInterestOpsNow(interestOps); + + // Notify the worker so it stops or continues reading. + Thread currentThread = Thread.currentThread(); + Thread workerThread = channel.workerThread; + if (workerThread != null && currentThread != workerThread) { + workerThread.interrupt(); + } } - channel.setInterestOpsNow(interestOps); fireChannelInterestChanged(channel); } } diff --git a/src/main/java/org/jboss/netty/channel/socket/http/HttpTunnelingChannelHandler.java b/src/main/java/org/jboss/netty/channel/socket/http/HttpTunnelingChannelHandler.java index d95b493f4b..e583aa5057 100644 --- a/src/main/java/org/jboss/netty/channel/socket/http/HttpTunnelingChannelHandler.java +++ b/src/main/java/org/jboss/netty/channel/socket/http/HttpTunnelingChannelHandler.java @@ -48,6 +48,7 @@ import org.jboss.netty.logging.InternalLoggerFactory; * * @author The Netty Project (netty-dev@lists.jboss.org) * @author Andy Taylor (andy.taylor@jboss.org) + * @author Trustin Lee (tlee@redhat.com) * @version $Rev$, $Date$ */ @ChannelPipelineCoverage("one") diff --git a/src/main/java/org/jboss/netty/channel/socket/http/HttpTunnelingClientSocketChannel.java b/src/main/java/org/jboss/netty/channel/socket/http/HttpTunnelingClientSocketChannel.java index 877d85b53e..b56b3cfc94 100644 --- a/src/main/java/org/jboss/netty/channel/socket/http/HttpTunnelingClientSocketChannel.java +++ b/src/main/java/org/jboss/netty/channel/socket/http/HttpTunnelingClientSocketChannel.java @@ -54,6 +54,7 @@ import org.jboss.netty.util.internal.LinkedTransferQueue; /** * @author The Netty Project (netty-dev@lists.jboss.org) * @author Andy Taylor (andy.taylor@jboss.org) + * @author Trustin Lee (tlee@redhat.com) * @version $Rev$, $Date$ */ class HttpTunnelingClientSocketChannel extends AbstractChannel @@ -67,6 +68,7 @@ class HttpTunnelingClientSocketChannel extends AbstractChannel volatile boolean awaitingInitialResponse = true; private final Object writeLock = new Object(); + final Object interestOpsLock = new Object(); volatile Thread workerThread; @@ -168,7 +170,7 @@ class HttpTunnelingClientSocketChannel extends AbstractChannel channel.write(ChannelBuffers.copiedBuffer(msg, "ASCII")); } - void sendChunk(ChannelBuffer a) { + int sendChunk(ChannelBuffer a) { int size = a.readableBytes(); String hex = Integer.toHexString(size) + HttpTunnelingClientSocketPipelineSink.LINE_TERMINATOR; @@ -179,6 +181,8 @@ class HttpTunnelingClientSocketChannel extends AbstractChannel ChannelBuffers.copiedBuffer(HttpTunnelingClientSocketPipelineSink.LINE_TERMINATOR, "ASCII"))); future.awaitUninterruptibly(); } + + return size + hex.length() + HttpTunnelingClientSocketPipelineSink.LINE_TERMINATOR.length(); } byte[] receiveChunk() { diff --git a/src/main/java/org/jboss/netty/channel/socket/http/HttpTunnelingClientSocketChannelFactory.java b/src/main/java/org/jboss/netty/channel/socket/http/HttpTunnelingClientSocketChannelFactory.java index a6c890b22d..88961e9763 100644 --- a/src/main/java/org/jboss/netty/channel/socket/http/HttpTunnelingClientSocketChannelFactory.java +++ b/src/main/java/org/jboss/netty/channel/socket/http/HttpTunnelingClientSocketChannelFactory.java @@ -33,6 +33,7 @@ import org.jboss.netty.util.internal.ExecutorUtil; /** * @author The Netty Project (netty-dev@lists.jboss.org) * @author Andy Taylor (andy.taylor@jboss.org) + * @author Trustin Lee (tlee@redhat.com) * @version $Rev$, $Date$ */ public class HttpTunnelingClientSocketChannelFactory implements ClientSocketChannelFactory { diff --git a/src/main/java/org/jboss/netty/channel/socket/http/HttpTunnelingClientSocketPipelineSink.java b/src/main/java/org/jboss/netty/channel/socket/http/HttpTunnelingClientSocketPipelineSink.java index 7ec122ce74..41d3efb28d 100644 --- a/src/main/java/org/jboss/netty/channel/socket/http/HttpTunnelingClientSocketPipelineSink.java +++ b/src/main/java/org/jboss/netty/channel/socket/http/HttpTunnelingClientSocketPipelineSink.java @@ -41,6 +41,7 @@ import org.jboss.netty.util.internal.IoWorkerRunnable; /** * @author The Netty Project (netty-dev@lists.jboss.org) * @author Andy Taylor (andy.taylor@jboss.org) + * @author Trustin Lee (tlee@redhat.com) * @version $Rev$, $Date$ */ final class HttpTunnelingClientSocketPipelineSink extends AbstractChannelSink { diff --git a/src/main/java/org/jboss/netty/channel/socket/http/HttpTunnelingServlet.java b/src/main/java/org/jboss/netty/channel/socket/http/HttpTunnelingServlet.java index c1b1163c69..e7eff7385d 100644 --- a/src/main/java/org/jboss/netty/channel/socket/http/HttpTunnelingServlet.java +++ b/src/main/java/org/jboss/netty/channel/socket/http/HttpTunnelingServlet.java @@ -42,6 +42,7 @@ import org.jboss.netty.channel.MessageEvent; * * @author The Netty Project (netty-dev@lists.jboss.org) * @author Andy Taylor (andy.taylor@jboss.org) + * @author Trustin Lee (tlee@redhat.com) * @version $Rev$, $Date$ */ public class HttpTunnelingServlet extends HttpServlet { diff --git a/src/main/java/org/jboss/netty/channel/socket/http/HttpTunnelingSessionListener.java b/src/main/java/org/jboss/netty/channel/socket/http/HttpTunnelingSessionListener.java index e0de8a744e..3213c346fb 100644 --- a/src/main/java/org/jboss/netty/channel/socket/http/HttpTunnelingSessionListener.java +++ b/src/main/java/org/jboss/netty/channel/socket/http/HttpTunnelingSessionListener.java @@ -42,6 +42,7 @@ import org.jboss.netty.channel.local.LocalAddress; * * @author The Netty Project (netty-dev@lists.jboss.org) * @author Andy Taylor (andy.taylor@jboss.org) + * @author Trustin Lee (tlee@redhat.com) * @version $Rev$, $Date$ */ public class HttpTunnelingSessionListener implements HttpSessionListener, ChannelHandler { @@ -69,11 +70,6 @@ public class HttpTunnelingSessionListener implements HttpSessionListener, Channe } } - /** - * @author The Netty Project (netty-dev@lists.jboss.org) - * @author Trustin Lee (tlee@redhat.com) - * @version $Rev$, $Date$ - */ private static final class HttpTunnelingChannelPipelineFactory implements ChannelPipelineFactory { private final HttpTunnelingChannelHandler handler; diff --git a/src/main/java/org/jboss/netty/channel/socket/http/package-info.java b/src/main/java/org/jboss/netty/channel/socket/http/package-info.java new file mode 100644 index 0000000000..962f4a9280 --- /dev/null +++ b/src/main/java/org/jboss/netty/channel/socket/http/package-info.java @@ -0,0 +1,29 @@ +/* + * JBoss, Home of Professional Open Source + * + * Copyright 2008, Red Hat Middleware LLC, and individual contributors + * by the @author tags. See the COPYRIGHT.txt in the distribution for a + * full listing of individual contributors. + * + * This is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. + */ + +/** + * An HTTP-based client-side {@link org.jboss.netty.channel.socket.SocketChannel} + * and its corresponding server-side Servlet implementation that make your + * existing Netty application work in a firewalled network. + */ +package org.jboss.netty.channel.socket.http;