From 1525edfde73c94f2c5065f701fec09283e5684d8 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 | 55 ++++++++----------- 1 file changed, 24 insertions(+), 31 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 6416ea4e60..01a79d65ad 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 @@ -184,39 +184,32 @@ public class OioSctpChannel extends AbstractOioMessageChannel return readMessages; } - Set reableKeys = readSelector.selectedKeys(); + RecvByteBufAllocator.Handle allocHandle = this.allocHandle; + if (allocHandle == null) { + this.allocHandle = allocHandle = config().getRecvByteBufAllocator().newHandle(); + } + ByteBuf buffer = allocHandle.allocate(config().getAllocator()); + boolean free = true; + try { - for (SelectionKey ignored : reableKeys) { - RecvByteBufAllocator.Handle allocHandle = this.allocHandle; - if (allocHandle == null) { - this.allocHandle = allocHandle = config().getRecvByteBufAllocator().newHandle(); - } - 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(); - msgs.add(new SctpMessage(messageInfo, buffer.writerIndex(buffer.writerIndex() + data.remaining()))); - free = false; - readMessages ++; - } catch (Throwable cause) { - PlatformDependent.throwException(cause); - } finally { - int bytesRead = buffer.readableBytes(); - allocHandle.record(bytesRead); - 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(); + msgs.add(new SctpMessage(messageInfo, buffer.writerIndex(buffer.writerIndex() + data.remaining()))); + free = false; + readMessages ++; + } catch (Throwable cause) { + PlatformDependent.throwException(cause); + } finally { + int bytesRead = buffer.readableBytes(); + allocHandle.record(bytesRead); + if (free) { + buffer.release(); } - } finally { - reableKeys.clear(); } return readMessages; }