mirror of
https://github.com/modelscope/FunASR
synced 2025-09-15 14:48:36 +08:00
use asio strand to keep the order of data (#838)
Co-authored-by: Yabin Li <wucong.lyb@alibaba-inc.com>
This commit is contained in:
parent
a657f5504e
commit
b2ab45f70b
@ -203,6 +203,12 @@ void WebSocketServer::on_open(websocketpp::connection_hdl hdl) {
|
|||||||
data_msg->msg["is_eof"]=false; // if this connection is closed
|
data_msg->msg["is_eof"]=false; // if this connection is closed
|
||||||
data_msg->punc_cache =
|
data_msg->punc_cache =
|
||||||
std::make_shared<std::vector<std::vector<std::string>>>(2);
|
std::make_shared<std::vector<std::vector<std::string>>>(2);
|
||||||
|
data_msg->strand_ = std::make_shared<asio::io_context::strand>(io_decoder_);
|
||||||
|
// std::vector<int> chunk_size = {5, 10, 5}; //TODO, need get from client
|
||||||
|
// FUNASR_HANDLE tpass_online_handle =
|
||||||
|
// FunTpassOnlineInit(tpass_handle, chunk_size);
|
||||||
|
// data_msg->tpass_online_handle = tpass_online_handle;
|
||||||
|
|
||||||
data_map.emplace(hdl, data_msg);
|
data_map.emplace(hdl, data_msg);
|
||||||
// LOG(INFO) << "on_open, active connections: " << data_map.size();
|
// LOG(INFO) << "on_open, active connections: " << data_map.size();
|
||||||
}catch (std::exception const& e) {
|
}catch (std::exception const& e) {
|
||||||
@ -294,7 +300,8 @@ void WebSocketServer::check_and_clean_connection() {
|
|||||||
}
|
}
|
||||||
for (auto hdl : to_remove) {
|
for (auto hdl : to_remove) {
|
||||||
remove_hdl(hdl, data_map);
|
remove_hdl(hdl, data_map);
|
||||||
// LOG(INFO) << "remove one connection ";
|
//LOG(INFO) << "remove one connection ";
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -360,8 +367,8 @@ void WebSocketServer::on_message(websocketpp::connection_hdl hdl,
|
|||||||
|
|
||||||
// if it is in final message, post the sample_data to decode
|
// if it is in final message, post the sample_data to decode
|
||||||
try{
|
try{
|
||||||
asio::post(
|
|
||||||
io_decoder_,
|
msg_data->strand_->post(
|
||||||
std::bind(&WebSocketServer::do_decoder, this,
|
std::bind(&WebSocketServer::do_decoder, this,
|
||||||
std::move(*(sample_data_p.get())), std::move(hdl),
|
std::move(*(sample_data_p.get())), std::move(hdl),
|
||||||
std::ref(msg_data->msg), std::ref(*(punc_cache_p.get())),
|
std::ref(msg_data->msg), std::ref(*(punc_cache_p.get())),
|
||||||
@ -400,7 +407,7 @@ void WebSocketServer::on_message(websocketpp::connection_hdl hdl,
|
|||||||
|
|
||||||
try{
|
try{
|
||||||
// post to decode
|
// post to decode
|
||||||
asio::post(io_decoder_,
|
msg_data->strand_->post(
|
||||||
std::bind(&WebSocketServer::do_decoder, this,
|
std::bind(&WebSocketServer::do_decoder, this,
|
||||||
std::move(subvector), std::move(hdl),
|
std::move(subvector), std::move(hdl),
|
||||||
std::ref(msg_data->msg),
|
std::ref(msg_data->msg),
|
||||||
|
|||||||
@ -58,7 +58,7 @@ typedef struct {
|
|||||||
FUNASR_HANDLE tpass_online_handle=NULL;
|
FUNASR_HANDLE tpass_online_handle=NULL;
|
||||||
std::string online_res = "";
|
std::string online_res = "";
|
||||||
std::string tpass_res = "";
|
std::string tpass_res = "";
|
||||||
|
std::shared_ptr<asio::io_context::strand> strand_; // for data execute in order
|
||||||
} FUNASR_MESSAGE;
|
} FUNASR_MESSAGE;
|
||||||
|
|
||||||
// See https://wiki.mozilla.org/Security/Server_Side_TLS for more details about
|
// See https://wiki.mozilla.org/Security/Server_Side_TLS for more details about
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user