提交 a87095ae 编写于 作者: L lei.yul 提交者: yulei

[Wisp] Fix unexpected socket closed exception

Summary:
Make the behavior of reading a closed socket to be consistent
after switching wisp.

Test Plan: Wisp2SocketCloseExceptionTest

Reviewed-by: joeyleeeeeee97 shiyuexw

Issue: alibaba/dragonwell8#124
上级 e65635d8
......@@ -177,6 +177,7 @@ public class WispSocketImpl
}
protected final SocketChannel ch;
private boolean eof = false;
private ByteBuffer bb = null;
// Invoker's previous array
private byte[] bs = null;
......@@ -226,6 +227,9 @@ public class WispSocketImpl
private int read0(ByteBuffer bb)
throws IOException {
if (eof) {
return -1;
}
int n;
try {
if (readAhead != null && readAhead.hasRemaining()) {
......@@ -242,6 +246,9 @@ public class WispSocketImpl
}
if ((n = ch.read(bb)) != 0) {
if (n == -1) {
eof = true;
}
return n;
}
......@@ -265,6 +272,9 @@ public class WispSocketImpl
WEA.unregisterEvent();
}
if (n == -1) {
eof = true;
}
return n;
}
......
/*
* @test
* @summary Verify that the behavior of read a closed socket is consistent
* @requires os.family == "linux"
* @run main/othervm -XX:+UnlockExperimentalVMOptions -XX:+UseWisp2 Wisp2SocketCloseExceptionTest
*/
import java.io.IOException;
import java.io.InputStream;
import java.net.ServerSocket;
import java.net.Socket;
public class Wisp2SocketCloseExceptionTest {
public static void main(String[] args) throws IOException {
ServerSocket serverSocket = new ServerSocket(0);
Socket fd = new Socket("localhost", serverSocket.getLocalPort());
serverSocket.accept().close();
InputStream is = fd.getInputStream();
is.read();
fd.close();
is.read();
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册