8201474: (so) Socket adaptor connect(InetAddress, timeout) succeeds when connection fails
Reviewed-by: bpb
This commit is contained in:
parent
85fbf32898
commit
45fb75c85a
@ -1280,8 +1280,8 @@ class DatagramChannelImpl
|
|||||||
boolean polled = false;
|
boolean polled = false;
|
||||||
try {
|
try {
|
||||||
beginRead(blocking, false);
|
beginRead(blocking, false);
|
||||||
int n = Net.poll(fd, Net.POLLIN, timeout);
|
int events = Net.poll(fd, Net.POLLIN, timeout);
|
||||||
polled = (n > 0);
|
polled = (events != 0);
|
||||||
} finally {
|
} finally {
|
||||||
endRead(blocking, polled);
|
endRead(blocking, polled);
|
||||||
}
|
}
|
||||||
|
@ -431,8 +431,8 @@ class ServerSocketChannelImpl
|
|||||||
boolean polled = false;
|
boolean polled = false;
|
||||||
try {
|
try {
|
||||||
begin(true);
|
begin(true);
|
||||||
int n = Net.poll(fd, Net.POLLIN, timeout);
|
int events = Net.poll(fd, Net.POLLIN, timeout);
|
||||||
polled = (n > 0);
|
polled = (events != 0);
|
||||||
} finally {
|
} finally {
|
||||||
end(true, polled);
|
end(true, polled);
|
||||||
}
|
}
|
||||||
|
@ -951,8 +951,8 @@ class SocketChannelImpl
|
|||||||
boolean polled = false;
|
boolean polled = false;
|
||||||
try {
|
try {
|
||||||
beginRead(blocking);
|
beginRead(blocking);
|
||||||
int n = Net.poll(fd, Net.POLLIN, timeout);
|
int events = Net.poll(fd, Net.POLLIN, timeout);
|
||||||
polled = (n > 0);
|
polled = (events != 0);
|
||||||
} finally {
|
} finally {
|
||||||
endRead(blocking, polled);
|
endRead(blocking, polled);
|
||||||
}
|
}
|
||||||
@ -977,10 +977,13 @@ class SocketChannelImpl
|
|||||||
boolean polled = false;
|
boolean polled = false;
|
||||||
try {
|
try {
|
||||||
beginFinishConnect(blocking);
|
beginFinishConnect(blocking);
|
||||||
int n = Net.poll(fd, Net.POLLCONN, timeout);
|
int events = Net.poll(fd, Net.POLLCONN, timeout);
|
||||||
polled = (n > 0);
|
polled = (events != 0);
|
||||||
} finally {
|
} finally {
|
||||||
endFinishConnect(blocking, polled);
|
// invoke endFinishConnect with completed = false so that
|
||||||
|
// the state is not changed to ST_CONNECTED. The socket
|
||||||
|
// adaptor will use finishConnect to finish.
|
||||||
|
endFinishConnect(blocking, /*completed*/false);
|
||||||
}
|
}
|
||||||
return polled;
|
return polled;
|
||||||
} finally {
|
} finally {
|
||||||
|
@ -700,7 +700,8 @@ Java_sun_nio_ch_Net_poll(JNIEnv* env, jclass this, jobject fdo, jint events, jlo
|
|||||||
if (rv >= 0) {
|
if (rv >= 0) {
|
||||||
return pfd.revents;
|
return pfd.revents;
|
||||||
} else if (errno == EINTR) {
|
} else if (errno == EINTR) {
|
||||||
return IOS_INTERRUPTED;
|
// interrupted, no events to return
|
||||||
|
return 0;
|
||||||
} else {
|
} else {
|
||||||
handleSocketError(env, errno);
|
handleSocketError(env, errno);
|
||||||
return IOS_THROWN;
|
return IOS_THROWN;
|
||||||
|
@ -22,7 +22,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
/* @test
|
/* @test
|
||||||
* @bug 8156002
|
* @bug 8156002 8201474
|
||||||
* @summary Unit test for socket-channel adaptors
|
* @summary Unit test for socket-channel adaptors
|
||||||
* @library .. /test/lib
|
* @library .. /test/lib
|
||||||
* @build jdk.test.lib.Utils TestServers
|
* @build jdk.test.lib.Utils TestServers
|
||||||
@ -37,18 +37,16 @@ import java.util.Arrays;
|
|||||||
|
|
||||||
public class AdaptSocket {
|
public class AdaptSocket {
|
||||||
|
|
||||||
static java.io.PrintStream out = System.out;
|
static final java.io.PrintStream out = System.out;
|
||||||
|
|
||||||
static void test(TestServers.DayTimeServer dayTimeServer,
|
static void test(TestServers.AbstractServer server,
|
||||||
int timeout,
|
int timeout,
|
||||||
boolean shouldTimeout)
|
boolean shouldTimeout)
|
||||||
throws Exception
|
throws Exception
|
||||||
{
|
{
|
||||||
out.println();
|
out.println();
|
||||||
|
|
||||||
InetSocketAddress isa
|
InetSocketAddress isa = new InetSocketAddress(server.getAddress(), server.getPort());
|
||||||
= new InetSocketAddress(dayTimeServer.getAddress(),
|
|
||||||
dayTimeServer.getPort());
|
|
||||||
SocketChannel sc = SocketChannel.open();
|
SocketChannel sc = SocketChannel.open();
|
||||||
Socket so = sc.socket();
|
Socket so = sc.socket();
|
||||||
out.println("opened: " + so);
|
out.println("opened: " + so);
|
||||||
@ -151,6 +149,30 @@ public class AdaptSocket {
|
|||||||
sc.close();
|
sc.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void testConnect(TestServers.AbstractServer server,
|
||||||
|
int timeout,
|
||||||
|
boolean shouldFail)
|
||||||
|
throws Exception
|
||||||
|
{
|
||||||
|
SocketAddress sa = new InetSocketAddress(server.getAddress(), server.getPort());
|
||||||
|
try (SocketChannel sc = SocketChannel.open()) {
|
||||||
|
Socket s = sc.socket();
|
||||||
|
try {
|
||||||
|
if (timeout > 0) {
|
||||||
|
s.connect(sa, timeout);
|
||||||
|
} else {
|
||||||
|
s.connect(sa);
|
||||||
|
}
|
||||||
|
if (shouldFail)
|
||||||
|
throw new Exception("Connection should not be established");
|
||||||
|
} catch (SocketException se) {
|
||||||
|
if (!shouldFail)
|
||||||
|
throw se;
|
||||||
|
out.println("connect failed as expected: " + se);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static void main(String[] args) throws Exception {
|
public static void main(String[] args) throws Exception {
|
||||||
|
|
||||||
try (TestServers.DayTimeServer dayTimeServer
|
try (TestServers.DayTimeServer dayTimeServer
|
||||||
@ -177,5 +199,9 @@ public class AdaptSocket {
|
|||||||
= TestServers.NoResponseServer.startNewServer()) {
|
= TestServers.NoResponseServer.startNewServer()) {
|
||||||
testRead(noResponseServer, 10, true);
|
testRead(noResponseServer, 10, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TestServers.RefusingServer refuser = TestServers.RefusingServer.newRefusingServer();
|
||||||
|
testConnect(refuser, 0, true);
|
||||||
|
testConnect(refuser, 2000, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user