Skip to content

Commit c720c95

Browse files
committed
[Wisp] Keep aligning Socket.isConnected() with the normal OpenJDK returning result for ServerSocket.accept()
Summary: Same as #438: we have another path ServerSocket.accept() to cover. Test Plan: ServerSocketConnectionTest.java Reviewed-by: D-D-H, yuleil Issue: #437
1 parent b4f6c89 commit c720c95

File tree

3 files changed

+24
-3
lines changed

3 files changed

+24
-3
lines changed

jdk/src/share/classes/java/net/ServerSocket.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -568,7 +568,9 @@ public Socket accept() throws IOException {
568568
if (!isBound())
569569
throw new SocketException("Socket is not bound yet");
570570
if (WispEngine.transparentWispSwitch()) {
571-
return asyncImpl.accept();
571+
Socket s = asyncImpl.accept();
572+
s.setConnected();
573+
return s;
572574
}
573575
Socket s = new Socket((SocketImpl) null);
574576
implAccept(s);

jdk/src/share/classes/java/net/Socket.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -760,8 +760,6 @@ void setBound() {
760760
}
761761

762762
void setConnected() {
763-
if (WispEngine.transparentWispSwitch())
764-
throw new UnsupportedOperationException();
765763
connected = true;
766764
}
767765

jdk/test/com/alibaba/wisp/io/ServerSocketConnectionTest.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,29 @@ private static void testIsConnectedAfterConnectionFailure() throws Exception {
8484
}
8585
}
8686

87+
private static void testIsConnectedAfterAcception() throws Exception {
88+
Socket s1 = null;
89+
try (ServerSocket ss = new ServerSocket(0)) {
90+
InetAddress ia = InetAddress.getLocalHost();
91+
InetSocketAddress isa = new InetSocketAddress(ia, ss.getLocalPort());
92+
new Socket().connect(isa);
93+
s1 = ss.accept();
94+
} catch (Exception e) {
95+
e.printStackTrace();
96+
throw new RuntimeException("Test Failed!");
97+
} finally {
98+
if (s1 != null) {
99+
assertTrue(s1.isConnected());
100+
s1.close();
101+
// We should return true even after the socket is closed, to keep align with OpenJDK.
102+
assertTrue(s1.isConnected());
103+
}
104+
}
105+
}
106+
87107
public static void main(String args[]) throws Exception {
88108
testIsConnectedAfterClosing();
89109
testIsConnectedAfterConnectionFailure();
110+
testIsConnectedAfterAcception();
90111
}
91112
}

0 commit comments

Comments
 (0)