[#1920] Fix IndexOutOfBoundsException when using PooledByteBufAllocator with SCTP and NIO Datagram channels

This commit is contained in:
Norman Maurer 2013-10-16 09:53:26 +02:00
parent df442b9b6a
commit 53fcff2eab
2 changed files with 7 additions and 7 deletions

View File

@ -271,14 +271,14 @@ public class NioSctpChannel extends AbstractNioMessageChannel implements io.nett
ByteBuf buffer = allocHandle.allocate(config().getAllocator());
boolean free = true;
try {
ByteBuffer data = buffer.nioBuffer(buffer.writerIndex(), buffer.writableBytes());
ByteBuffer data = buffer.internalNioBuffer(buffer.writerIndex(), buffer.writableBytes());
int pos = data.position();
MessageInfo messageInfo = ch.receive(data, null, notificationHandler);
if (messageInfo == null) {
return 0;
}
data.flip();
buf.add(new SctpMessage(messageInfo, buffer.writerIndex(buffer.writerIndex() + data.remaining())));
buf.add(new SctpMessage(messageInfo, buffer.writerIndex(buffer.writerIndex() + (data.position() - pos))));
free = false;
return 1;
} catch (Throwable cause) {

View File

@ -204,14 +204,14 @@ public final class NioDatagramChannel
ByteBuf data = allocHandle.allocate(config.getAllocator());
boolean free = true;
try {
ByteBuffer nioData = data.nioBuffer(data.writerIndex(), data.writableBytes());
ByteBuffer nioData = data.internalNioBuffer(data.writerIndex(), data.writableBytes());
int pos = nioData.position();
InetSocketAddress remoteAddress = (InetSocketAddress) ch.receive(nioData);
if (remoteAddress == null) {
return 0;
}
int readBytes = nioData.position();
int readBytes = nioData.position() - pos;
data.writerIndex(data.writerIndex() + readBytes);
allocHandle.record(readBytes);