[dev_sweeper_3.1.0] WebSocket空指针修复

This commit is contained in:
xinfengkun
2023-05-09 14:59:00 +08:00
parent d02a70e478
commit 3d23a1fd59

View File

@@ -188,6 +188,7 @@ public class FpgaSocket implements IWebSocket {
void onWebSocketConnectFailed(String t);
void onMessage(String message);
//TODO 计算耗时 临时测试
void onMessage(long receiveTime, ByteString bytes) throws InvalidProtocolBufferException;
}
@@ -366,14 +367,16 @@ public class FpgaSocket implements IWebSocket {
*/
private void close(boolean isInitiative, int code) {
isConnected.set(false);
String closeReason = null;
if (isInitiative) {
closeReason = "用户主动关闭";
}
boolean isClose = mWebSocket.close(code, closeReason);
CupidLogUtils.i(TAG, "WebSocket " + (isInitiative ? "主动" : "被动") + "断开连接是否成功= " + isClose);
if (!isInitiative) {
mWebSocket.cancel();
if (mWebSocket != null) {
String closeReason = null;
if (isInitiative) {
closeReason = "用户主动关闭";
}
boolean isClose = mWebSocket.close(code, closeReason);
CupidLogUtils.i(TAG, "WebSocket " + (isInitiative ? "主动" : "被动") + "断开连接是否成功= " + isClose);
if (!isInitiative) {
mWebSocket.cancel();
}
}
mWebSocket = null;
}