Skip to content

Commit

Permalink
OioSctpChannel iterating over selected keys
Browse files Browse the repository at this point in the history
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 #3884
  • Loading branch information
Scottmitch committed Aug 27, 2015
1 parent 52b77a7 commit fae5d88
Showing 1 changed file with 20 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -183,36 +183,29 @@ protected int doReadMessages(List<Object> msgs) throws Exception {
return readMessages;
}

Set<SelectionKey> reableKeys = readSelector.selectedKeys();
try {
for (@SuppressWarnings("unused") SelectionKey ignored : reableKeys) {
final RecvByteBufAllocator.Handle allocHandle = unsafe().recvBufAllocHandle();
ByteBuf buffer = allocHandle.allocate(config().getAllocator());
boolean free = true;
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;
}
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();
}
}
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;
}
Expand Down

0 comments on commit fae5d88

Please sign in to comment.