Skip to content
Permalink
Browse files

Fix usage of the NIO selected keys set

"[...] Keys are never removed from the selected-key set in any
other way; they are not, in particular, removed as a side effect
of selection operations. [...]"
  • Loading branch information
ibauersachs committed Jan 12, 2020
1 parent ecff2a7 commit 6fc49f31fb32ad5329dad733dc1333074c71cbb0
Showing with 6 additions and 3 deletions.
  1. +5 −1 src/main/java/org/xbill/DNS/Client.java
  2. +1 −2 src/test/java/org/xbill/DNS/NioTcpClientTest.java
@@ -6,6 +6,7 @@
import java.net.SocketAddress;
import java.nio.channels.SelectionKey;
import java.nio.channels.Selector;
import java.util.Iterator;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
import lombok.extern.slf4j.Slf4j;
@@ -70,7 +71,10 @@ static void addSelectorTimeoutTask(Runnable r) {
}

private static void processReadyKeys() {
for (SelectionKey key : selector.selectedKeys()) {
Iterator<SelectionKey> it = selector.selectedKeys().iterator();
while (it.hasNext()) {
SelectionKey key = it.next();
it.remove();
KeyProcessor t = (KeyProcessor) key.attachment();
t.processReadyKey(key);
}
@@ -13,14 +13,13 @@
import java.nio.ByteBuffer;
import java.time.Duration;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
import org.junit.jupiter.api.Test;

public class NioTcpClientTest {
@Test
void testResponseStream() throws InterruptedException, IOException, ExecutionException {
void testResponseStream() throws InterruptedException, IOException {
Record qr = Record.newRecord(Name.fromConstantString("example.com."), Type.A, DClass.IN);
Message[] q = new Message[] {Message.newQuery(qr), Message.newQuery(qr)};
CountDownLatch cdl1 = new CountDownLatch(q.length);

0 comments on commit 6fc49f3

Please sign in to comment.
You can’t perform that action at this time.