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:
parent
93d2e86ed0
commit
1525edfde7
@ -184,39 +184,32 @@ public class OioSctpChannel extends AbstractOioMessageChannel
|
|||||||
return readMessages;
|
return readMessages;
|
||||||
}
|
}
|
||||||
|
|
||||||
Set<SelectionKey> 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 {
|
try {
|
||||||
for (SelectionKey ignored : reableKeys) {
|
ByteBuffer data = buffer.nioBuffer(buffer.writerIndex(), buffer.writableBytes());
|
||||||
RecvByteBufAllocator.Handle allocHandle = this.allocHandle;
|
MessageInfo messageInfo = ch.receive(data, null, notificationHandler);
|
||||||
if (allocHandle == null) {
|
if (messageInfo == null) {
|
||||||
this.allocHandle = allocHandle = config().getRecvByteBufAllocator().newHandle();
|
return readMessages;
|
||||||
}
|
}
|
||||||
ByteBuf buffer = allocHandle.allocate(config().getAllocator());
|
|
||||||
boolean free = true;
|
data.flip();
|
||||||
|
msgs.add(new SctpMessage(messageInfo, buffer.writerIndex(buffer.writerIndex() + data.remaining())));
|
||||||
try {
|
free = false;
|
||||||
ByteBuffer data = buffer.nioBuffer(buffer.writerIndex(), buffer.writableBytes());
|
readMessages ++;
|
||||||
MessageInfo messageInfo = ch.receive(data, null, notificationHandler);
|
} catch (Throwable cause) {
|
||||||
if (messageInfo == null) {
|
PlatformDependent.throwException(cause);
|
||||||
return readMessages;
|
} finally {
|
||||||
}
|
int bytesRead = buffer.readableBytes();
|
||||||
|
allocHandle.record(bytesRead);
|
||||||
data.flip();
|
if (free) {
|
||||||
msgs.add(new SctpMessage(messageInfo, buffer.writerIndex(buffer.writerIndex() + data.remaining())));
|
buffer.release();
|
||||||
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;
|
return readMessages;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user