// Copyright (c) 2005 Brian Wellington (bwelling@xbill.org)

package org.xbill.DNS;

import java.io.*;
import java.net.*;
import java.nio.*;
import java.nio.channels.*;
import org.xbill.DNS.utils.hexdump;

class Client {

protected long endTime;
protected SelectionKey key;

protected
Client(SelectableChannel channel, long endTime) throws IOException {
	boolean done = false;
	Selector selector = null;
	try {
		selector = Selector.open();
		channel.configureBlocking(false);
		key = channel.register(selector, 0);
		done = true;
	}
	finally {
		if (!done && selector != null)
			selector.close();
		if (!done)
			channel.close();
	}
}

static protected void
blockUntil(SelectionKey key, long endTime) throws IOException {
	long timeout = endTime - System.currentTimeMillis();
	if (timeout < 0 || key.selector().select(timeout) == 0)
		throw new SocketTimeoutException();
}

static protected void
verboseLog(String prefix, byte [] data) {
	if (Options.check("verbosemsg"))
		System.err.println(hexdump.dump(prefix, data));
}

void
cleanup() throws IOException {
	key.selector().close();
	key.channel().close();
}

}

@@ -771,16 +771,32 @@
 llis();%0A
+%09int nkeys = 0;%0A
 %09if (tim
@@ -804,14 +804,22 @@
 out 
-%3C 0 %7C%7C
+%3E 0)%0A%09%09nkeys =
  key
@@ -845,16 +845,90 @@
 timeout)
+;%0A%09else if (timeout == 0)%0A%09%09nkeys = key.selector().selectNow();%0A%09if (nkeys
  == 0)%0A%09

Fix select usage.