From 56cc0bbd4c8a55144e2086cc3dd9286f8d0e374d Mon Sep 17 00:00:00 2001 From: Scott Mitchell Date: Fri, 21 Aug 2015 09:28:18 -0700 Subject: [PATCH] OioSctpChannel iterating over selected keys Motivation: OioSctpChannel.doReadMessages is iterating over the selected keys, and ignoring each selected key. It is not known why this is needed and no other channel implementation does this. Modifications: - Stop iterating over selected keys, and just read like other channels Result: No unnecessary iteration in OioSctpChannel.doReadMessages. Fixes https://github.com/netty/netty/issues/3884 --- .../channel/sctp/oio/OioSctpChannel.java | 49 ++++++++----------- 1 file changed, 21 insertions(+), 28 deletions(-) diff --git a/transport-sctp/src/main/java/io/netty/channel/sctp/oio/OioSctpChannel.java b/transport-sctp/src/main/java/io/netty/channel/sctp/oio/OioSctpChannel.java index d0a9c10d2e..56141067c5 100755 --- a/transport-sctp/src/main/java/io/netty/channel/sctp/oio/OioSctpChannel.java +++ b/transport-sctp/src/main/java/io/netty/channel/sctp/oio/OioSctpChannel.java @@ -183,36 +183,29 @@ public class OioSctpChannel extends AbstractOioMessageChannel return readMessages; } - Set reableKeys = readSelector.selectedKeys(); + final RecvByteBufAllocator.Handle allocHandle = unsafe().recvBufAllocHandle(); + ByteBuf buffer = allocHandle.allocate(config().getAllocator()); + boolean free = true; + try { - for (@SuppressWarnings("unused") SelectionKey ignored : reableKeys) { - final RecvByteBufAllocator.Handle allocHandle = unsafe().recvBufAllocHandle(); - ByteBuf buffer = allocHandle.allocate(config().getAllocator()); - boolean free = true; - - try { - ByteBuffer data = buffer.nioBuffer(buffer.writerIndex(), buffer.writableBytes()); - MessageInfo messageInfo = ch.receive(data, null, notificationHandler); - if (messageInfo == null) { - return readMessages; - } - - data.flip(); - allocHandle.lastBytesRead(data.remaining()); - msgs.add(new SctpMessage(messageInfo, - buffer.writerIndex(buffer.writerIndex() + allocHandle.lastBytesRead()))); - free = false; - ++readMessages; - } catch (Throwable cause) { - PlatformDependent.throwException(cause); - } finally { - if (free) { - buffer.release(); - } - } + ByteBuffer data = buffer.nioBuffer(buffer.writerIndex(), buffer.writableBytes()); + MessageInfo messageInfo = ch.receive(data, null, notificationHandler); + if (messageInfo == null) { + return readMessages; + } + + data.flip(); + allocHandle.lastBytesRead(data.remaining()); + msgs.add(new SctpMessage(messageInfo, + buffer.writerIndex(buffer.writerIndex() + allocHandle.lastBytesRead()))); + free = false; + ++readMessages; + } catch (Throwable cause) { + PlatformDependent.throwException(cause); + } finally { + if (free) { + buffer.release(); } - } finally { - reableKeys.clear(); } return readMessages; }