diff --git a/transport-sctp/src/main/java/io/netty/channel/sctp/nio/NioSctpChannel.java b/transport-sctp/src/main/java/io/netty/channel/sctp/nio/NioSctpChannel.java index 5dd52731e8..b0ef61007f 100644 --- a/transport-sctp/src/main/java/io/netty/channel/sctp/nio/NioSctpChannel.java +++ b/transport-sctp/src/main/java/io/netty/channel/sctp/nio/NioSctpChannel.java @@ -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) { diff --git a/transport/src/main/java/io/netty/channel/socket/nio/NioDatagramChannel.java b/transport/src/main/java/io/netty/channel/socket/nio/NioDatagramChannel.java index c95801c2ec..8fbc9a6e82 100644 --- a/transport/src/main/java/io/netty/channel/socket/nio/NioDatagramChannel.java +++ b/transport/src/main/java/io/netty/channel/socket/nio/NioDatagramChannel.java @@ -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);