From c7c2c71935a684a7148c3736417d5b5861b91f38 Mon Sep 17 00:00:00 2001 From: Trustin Lee Date: Fri, 16 Oct 2009 04:39:20 +0000 Subject: [PATCH] Use proper buffer factory in OioDatagramWorker --- .../channel/socket/oio/OioDatagramWorker.java | 20 ++++++++----------- 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/src/main/java/org/jboss/netty/channel/socket/oio/OioDatagramWorker.java b/src/main/java/org/jboss/netty/channel/socket/oio/OioDatagramWorker.java index 702128953a..886e802fbf 100644 --- a/src/main/java/org/jboss/netty/channel/socket/oio/OioDatagramWorker.java +++ b/src/main/java/org/jboss/netty/channel/socket/oio/OioDatagramWorker.java @@ -22,10 +22,9 @@ import java.net.DatagramPacket; import java.net.MulticastSocket; import java.net.SocketAddress; import java.nio.ByteBuffer; -import java.nio.ByteOrder; import org.jboss.netty.buffer.ChannelBuffer; -import org.jboss.netty.buffer.ChannelBuffers; +import org.jboss.netty.buffer.ChannelBufferFactory; import org.jboss.netty.channel.Channel; import org.jboss.netty.channel.ChannelFuture; import org.jboss.netty.channel.ReceiveBufferSizePredictor; @@ -67,6 +66,9 @@ class OioDatagramWorker implements Runnable { ReceiveBufferSizePredictor predictor = channel.getConfig().getReceiveBufferSizePredictor(); + ChannelBufferFactory bufferFactory = + channel.getConfig().getBufferFactory(); + byte[] buf = new byte[predictor.nextReceiveBufferSize()]; DatagramPacket packet = new DatagramPacket(buf, buf.length); @@ -83,16 +85,10 @@ class OioDatagramWorker implements Runnable { break; } - ChannelBuffer buffer; - ByteOrder endianness = channel.getConfig().getBufferFactory().getDefaultOrder(); - int readBytes = packet.getLength(); - if (readBytes == buf.length) { - buffer = ChannelBuffers.wrappedBuffer(endianness, buf); - } else { - buffer = ChannelBuffers.wrappedBuffer(endianness, buf, 0, readBytes); - } - - fireMessageReceived(channel, buffer, packet.getSocketAddress()); + fireMessageReceived( + channel, + bufferFactory.getBuffer(buf, 0, packet.getLength()), + packet.getSocketAddress()); } // Setting the workerThread to null will prevent any channel