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

View File

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