From 2962dc83060d948656d0b1e52d1e67ad07afb4f5 Mon Sep 17 00:00:00 2001
From: zhaomingwork <61895407+zhaomingwork@users.noreply.github.com>
Date: 星期四, 15 六月 2023 11:34:35 +0800
Subject: [PATCH] For cpp ws client long file not exited bug (#631)
---
funasr/runtime/websocket/funasr-ws-client.cpp | 20 ++++++++++++++------
1 files changed, 14 insertions(+), 6 deletions(-)
diff --git a/funasr/runtime/websocket/funasr-ws-client.cpp b/funasr/runtime/websocket/funasr-ws-client.cpp
index 3c20fd8..4a3c751 100644
--- a/funasr/runtime/websocket/funasr-ws-client.cpp
+++ b/funasr/runtime/websocket/funasr-ws-client.cpp
@@ -106,7 +106,16 @@
const std::string& payload = msg->get_payload();
switch (msg->get_opcode()) {
case websocketpp::frame::opcode::text:
- LOG(INFO)<<"on_message = " << payload;
+ total_num=total_num+1;
+ LOG(INFO)<<total_num<<",on_message = " << payload;
+ if((total_num+1)==wav_index)
+ {
+ websocketpp::lib::error_code ec;
+ m_client.close(m_hdl, websocketpp::close::status::going_away, "", ec);
+ if (ec){
+ LOG(ERROR)<< "Error closing connection " << ec.message();
+ }
+ }
}
}
@@ -139,12 +148,10 @@
}
send_wav_data(wav_list[i], wav_ids[i]);
}
- WaitABit();
- m_client.close(m_hdl, websocketpp::close::status::going_away, "", ec);
- if (ec){
- LOG(ERROR)<< "Error closing connection " << ec.message();
- }
+ WaitABit();
+
asio_thread.join();
+
}
// The open handler will signal that we are ready to start sending data
@@ -267,6 +274,7 @@
websocketpp::lib::mutex m_lock;
bool m_open;
bool m_done;
+ int total_num=0;
};
int main(int argc, char* argv[]) {
--
Gitblit v1.9.1