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
This commit is contained in:
Scott Mitchell 2015-08-21 09:28:18 -07:00
parent 5498fd12dc
commit 56cc0bbd4c

View File

@ -183,36 +183,29 @@ public class OioSctpChannel extends AbstractOioMessageChannel
return readMessages; return readMessages;
} }
Set<SelectionKey> reableKeys = readSelector.selectedKeys(); final RecvByteBufAllocator.Handle allocHandle = unsafe().recvBufAllocHandle();
ByteBuf buffer = allocHandle.allocate(config().getAllocator());
boolean free = true;
try { try {
for (@SuppressWarnings("unused") SelectionKey ignored : reableKeys) { ByteBuffer data = buffer.nioBuffer(buffer.writerIndex(), buffer.writableBytes());
final RecvByteBufAllocator.Handle allocHandle = unsafe().recvBufAllocHandle(); MessageInfo messageInfo = ch.receive(data, null, notificationHandler);
ByteBuf buffer = allocHandle.allocate(config().getAllocator()); if (messageInfo == null) {
boolean free = true; return readMessages;
}
try {
ByteBuffer data = buffer.nioBuffer(buffer.writerIndex(), buffer.writableBytes()); data.flip();
MessageInfo messageInfo = ch.receive(data, null, notificationHandler); allocHandle.lastBytesRead(data.remaining());
if (messageInfo == null) { msgs.add(new SctpMessage(messageInfo,
return readMessages; buffer.writerIndex(buffer.writerIndex() + allocHandle.lastBytesRead())));
} free = false;
++readMessages;
data.flip(); } catch (Throwable cause) {
allocHandle.lastBytesRead(data.remaining()); PlatformDependent.throwException(cause);
msgs.add(new SctpMessage(messageInfo, } finally {
buffer.writerIndex(buffer.writerIndex() + allocHandle.lastBytesRead()))); if (free) {
free = false; buffer.release();
++readMessages;
} catch (Throwable cause) {
PlatformDependent.throwException(cause);
} finally {
if (free) {
buffer.release();
}
}
} }
} finally {
reableKeys.clear();
} }
return readMessages; return readMessages;
} }