Use proper buffer factory in OioWorker

Removed unnecessary local variables in OioDatagramWorker
This commit is contained in:
Trustin Lee 2009-10-16 04:41:33 +00:00
parent c7c2c71935
commit b859f120d8
2 changed files with 4 additions and 15 deletions

View File

@ -24,7 +24,6 @@ import java.net.SocketAddress;
import java.nio.ByteBuffer;
import org.jboss.netty.buffer.ChannelBuffer;
import org.jboss.netty.buffer.ChannelBufferFactory;
import org.jboss.netty.channel.Channel;
import org.jboss.netty.channel.ChannelFuture;
import org.jboss.netty.channel.ReceiveBufferSizePredictor;
@ -66,9 +65,6 @@ 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);
@ -87,7 +83,7 @@ class OioDatagramWorker implements Runnable {
fireMessageReceived(
channel,
bufferFactory.getBuffer(buf, 0, packet.getLength()),
channel.getConfig().getBufferFactory().getBuffer(buf, 0, packet.getLength()),
packet.getSocketAddress());
}

View File

@ -24,7 +24,6 @@ import java.nio.channels.ClosedChannelException;
import java.util.regex.Pattern;
import org.jboss.netty.buffer.ChannelBuffer;
import org.jboss.netty.buffer.ChannelBuffers;
import org.jboss.netty.channel.Channel;
import org.jboss.netty.channel.ChannelFuture;
@ -88,15 +87,9 @@ class OioWorker implements Runnable {
break;
}
ChannelBuffer buffer;
if (readBytes == buf.length) {
buffer = ChannelBuffers.wrappedBuffer(buf);
} else {
// A rare case, but it sometimes happen.
buffer = ChannelBuffers.wrappedBuffer(buf, 0, readBytes);
}
fireMessageReceived(channel, buffer);
fireMessageReceived(
channel,
channel.getConfig().getBufferFactory().getBuffer(buf, 0, readBytes));
}
// Setting the workerThread to null will prevent any channel