Use proper buffer factory in OioDatagramWorker
This commit is contained in:
parent
7a06c35238
commit
c7c2c71935
@ -22,10 +22,9 @@ import java.net.DatagramPacket;
|
|||||||
import java.net.MulticastSocket;
|
import java.net.MulticastSocket;
|
||||||
import java.net.SocketAddress;
|
import java.net.SocketAddress;
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
import java.nio.ByteOrder;
|
|
||||||
|
|
||||||
import org.jboss.netty.buffer.ChannelBuffer;
|
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.Channel;
|
||||||
import org.jboss.netty.channel.ChannelFuture;
|
import org.jboss.netty.channel.ChannelFuture;
|
||||||
import org.jboss.netty.channel.ReceiveBufferSizePredictor;
|
import org.jboss.netty.channel.ReceiveBufferSizePredictor;
|
||||||
@ -67,6 +66,9 @@ class OioDatagramWorker implements Runnable {
|
|||||||
|
|
||||||
ReceiveBufferSizePredictor predictor =
|
ReceiveBufferSizePredictor predictor =
|
||||||
channel.getConfig().getReceiveBufferSizePredictor();
|
channel.getConfig().getReceiveBufferSizePredictor();
|
||||||
|
ChannelBufferFactory bufferFactory =
|
||||||
|
channel.getConfig().getBufferFactory();
|
||||||
|
|
||||||
|
|
||||||
byte[] buf = new byte[predictor.nextReceiveBufferSize()];
|
byte[] buf = new byte[predictor.nextReceiveBufferSize()];
|
||||||
DatagramPacket packet = new DatagramPacket(buf, buf.length);
|
DatagramPacket packet = new DatagramPacket(buf, buf.length);
|
||||||
@ -83,16 +85,10 @@ class OioDatagramWorker implements Runnable {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
ChannelBuffer buffer;
|
fireMessageReceived(
|
||||||
ByteOrder endianness = channel.getConfig().getBufferFactory().getDefaultOrder();
|
channel,
|
||||||
int readBytes = packet.getLength();
|
bufferFactory.getBuffer(buf, 0, packet.getLength()),
|
||||||
if (readBytes == buf.length) {
|
packet.getSocketAddress());
|
||||||
buffer = ChannelBuffers.wrappedBuffer(endianness, buf);
|
|
||||||
} else {
|
|
||||||
buffer = ChannelBuffers.wrappedBuffer(endianness, buf, 0, readBytes);
|
|
||||||
}
|
|
||||||
|
|
||||||
fireMessageReceived(channel, buffer, packet.getSocketAddress());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Setting the workerThread to null will prevent any channel
|
// Setting the workerThread to null will prevent any channel
|
||||||
|
Loading…
Reference in New Issue
Block a user