Clear selectedKeys in OioSctpChannel.doReadMessages

Motivation:
The fix for https://github.com/netty/netty/issues/3884 breaks SctpEchoTest because Selector.select will always return 0 if you do not clear last selectedKeys.

Modifications:
Clear readSelector.selectedKeys() if it is not empty.

Result:
SctpEchoTest is green again.
This commit is contained in:
zhangduo 2015-12-21 16:33:42 +08:00 committed by Norman Maurer
parent 7c1602125a
commit c22f1aa4ac

View File

@ -183,7 +183,12 @@ public class OioSctpChannel extends AbstractOioMessageChannel
if (!keysSelected) { if (!keysSelected) {
return readMessages; return readMessages;
} }
// We must clear the selectedKeys because the Selector will never do it. If we do not clear it, the selectionKey
// will always be returned even if there is no data can be read which causes performance issue. And in some
// implementation of Selector, the select method may return 0 if the selectionKey which is ready for process has
// already been in the selectedKeys and cause the keysSelected above to be false even if we actually have
// something to read.
readSelector.selectedKeys().clear();
final RecvByteBufAllocator.Handle allocHandle = unsafe().recvBufAllocHandle(); final RecvByteBufAllocator.Handle allocHandle = unsafe().recvBufAllocHandle();
ByteBuf buffer = allocHandle.allocate(config().getAllocator()); ByteBuf buffer = allocHandle.allocate(config().getAllocator());
boolean free = true; boolean free = true;