[#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()); ByteBuf buffer = allocHandle.allocate(config().getAllocator());
boolean free = true; boolean free = true;
try { 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); MessageInfo messageInfo = ch.receive(data, null, notificationHandler);
if (messageInfo == null) { if (messageInfo == null) {
return 0; return 0;
} }
buf.add(new SctpMessage(messageInfo, buffer.writerIndex(buffer.writerIndex() + (data.position() - pos))));
data.flip();
buf.add(new SctpMessage(messageInfo, buffer.writerIndex(buffer.writerIndex() + data.remaining())));
free = false; free = false;
return 1; return 1;
} catch (Throwable cause) { } catch (Throwable cause) {

View File

@ -204,14 +204,14 @@ public final class NioDatagramChannel
ByteBuf data = allocHandle.allocate(config.getAllocator()); ByteBuf data = allocHandle.allocate(config.getAllocator());
boolean free = true; boolean free = true;
try { 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); InetSocketAddress remoteAddress = (InetSocketAddress) ch.receive(nioData);
if (remoteAddress == null) { if (remoteAddress == null) {
return 0; return 0;
} }
int readBytes = nioData.position(); int readBytes = nioData.position() - pos;
data.writerIndex(data.writerIndex() + readBytes); data.writerIndex(data.writerIndex() + readBytes);
allocHandle.record(readBytes); allocHandle.record(readBytes);