--- a/jdk/src/share/classes/sun/nio/ch/SocketAdaptor.java Thu Oct 04 10:04:56 2012 -0700
+++ b/jdk/src/share/classes/sun/nio/ch/SocketAdaptor.java Thu Oct 04 19:53:08 2012 +0100
@@ -97,25 +97,19 @@
return;
}
- // Implement timeout with a selector
- SelectionKey sk = null;
- Selector sel = null;
sc.configureBlocking(false);
try {
if (sc.connect(remote))
return;
- sel = Util.getTemporarySelector(sc);
- sk = sc.register(sel, SelectionKey.OP_CONNECT);
long to = timeout;
for (;;) {
if (!sc.isOpen())
throw new ClosedChannelException();
long st = System.currentTimeMillis();
- int ns = sel.select(to);
- if (ns > 0 &&
- sk.isConnectable() && sc.finishConnect())
+
+ int result = sc.poll(PollArrayWrapper.POLLCONN, to);
+ if (result > 0 && sc.finishConnect())
break;
- sel.selectedKeys().remove(sk);
to -= System.currentTimeMillis() - st;
if (to <= 0) {
try {
@@ -125,12 +119,8 @@
}
}
} finally {
- if (sk != null)
- sk.cancel();
if (sc.isOpen())
sc.configureBlocking(true);
- if (sel != null)
- Util.releaseTemporarySelector(sel);
}
} catch (Exception x) {
@@ -199,39 +189,29 @@
throw new IllegalBlockingModeException();
if (timeout == 0)
return sc.read(bb);
+ sc.configureBlocking(false);
- // Implement timeout with a selector
- SelectionKey sk = null;
- Selector sel = null;
- sc.configureBlocking(false);
try {
int n;
if ((n = sc.read(bb)) != 0)
return n;
- sel = Util.getTemporarySelector(sc);
- sk = sc.register(sel, SelectionKey.OP_READ);
long to = timeout;
for (;;) {
if (!sc.isOpen())
throw new ClosedChannelException();
long st = System.currentTimeMillis();
- int ns = sel.select(to);
- if (ns > 0 && sk.isReadable()) {
+ int result = sc.poll(PollArrayWrapper.POLLIN, to);
+ if (result > 0) {
if ((n = sc.read(bb)) != 0)
return n;
}
- sel.selectedKeys().remove(sk);
to -= System.currentTimeMillis() - st;
if (to <= 0)
throw new SocketTimeoutException();
}
} finally {
- if (sk != null)
- sk.cancel();
if (sc.isOpen())
sc.configureBlocking(true);
- if (sel != null)
- Util.releaseTemporarySelector(sel);
}
}