From 5ae0adbfaa56d49f62fba97c9ff88ed7b27f13e1 Mon Sep 17 00:00:00 2001 From: Trustin Lee Date: Mon, 15 Jun 2009 07:26:05 +0000 Subject: [PATCH] Made sure composite buffer consolidation happens only once by converting CompositeChannelBuffer to an ordinary buffer --- .../netty/channel/socket/nio/NioWorker.java | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/main/java/org/jboss/netty/channel/socket/nio/NioWorker.java b/src/main/java/org/jboss/netty/channel/socket/nio/NioWorker.java index 93a6fd8c06..bb038dc343 100644 --- a/src/main/java/org/jboss/netty/channel/socket/nio/NioWorker.java +++ b/src/main/java/org/jboss/netty/channel/socket/nio/NioWorker.java @@ -44,9 +44,11 @@ import java.util.concurrent.locks.ReentrantReadWriteLock; import org.jboss.netty.buffer.ChannelBuffer; import org.jboss.netty.buffer.ChannelBufferFactory; +import org.jboss.netty.buffer.CompositeChannelBuffer; import org.jboss.netty.channel.Channel; import org.jboss.netty.channel.ChannelException; import org.jboss.netty.channel.ChannelFuture; +import org.jboss.netty.channel.DownstreamMessageEvent; import org.jboss.netty.channel.MessageEvent; import org.jboss.netty.channel.ReceiveBufferSizePredictor; import org.jboss.netty.logging.InternalLogger; @@ -408,6 +410,7 @@ class NioWorker implements Runnable { break; } + evt = consolidateComposite(evt); buf = (ChannelBuffer) evt.getMessage(); bufIdx = buf.readerIndex(); } else { @@ -467,6 +470,20 @@ class NioWorker implements Runnable { } } + private static MessageEvent consolidateComposite(MessageEvent e) { + // Convert a composite buffer into a simple buffer to save memory + // bandwidth on full write buffer. + // This method should be eliminated once gathering write works. + Object m = e.getMessage(); + if (m instanceof CompositeChannelBuffer) { + e = new DownstreamMessageEvent( + e.getChannel(), e.getFuture(), + ((CompositeChannelBuffer) m).copy(), + e.getRemoteAddress()); + } + return e; + } + private static void setOpWrite(NioSocketChannel channel) { NioWorker worker = channel.worker; Selector selector = worker.selector;