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 netty#3884
  • Loading branch information
Scottmitch committed Aug 27, 2015
1 parent 74a1ddc commit 67eabac
Showing 1 changed file with 23 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -184,39 +184,32 @@ protected int doReadMessages(List<Object> msgs) throws Exception {
return readMessages;
}

Set<SelectionKey> reableKeys = readSelector.selectedKeys();
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;
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;
}
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();
}
}
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;
}
Expand Down

0 comments on commit 67eabac

Please sign in to comment.