in nlsCppSdk/transport/nlsEventNetWork.cpp [539:618]
int NlsEventNetWork::stop(INlsRequest *request) {
MUTEX_LOCK(_mtxThread);
if (_eventClient == NULL) {
LOG_ERROR(
"NlsEventNetWork has destroyed, please invoke startWorkThread() "
"first.");
MUTEX_UNLOCK(_mtxThread);
return -(EventClientEmpty);
}
ConnectNode *node = request->getConnectNode();
if (node == NULL) {
LOG_ERROR("The node of request(%p) is nullptr, you have destroyed request!",
request);
MUTEX_UNLOCK(_mtxThread);
return -(NodeEmpty);
}
/* FlowingSynthesizer Node也许处于发送单轮文本状态, 可等待一会. */
int try_count = 500;
while (request->getRequestParam()->_requestType == FlowingSynthesizer &&
node->_isSendSingleRoundText && try_count-- > 0) {
LOG_WARN(
"Request(%p) Node(%p) is sending a single round of synthetic text.",
request, node);
#ifdef _MSC_VER
Sleep(1);
#else
usleep(1000);
#endif
}
/* invoke stop
* Node未处于运行状态, 或正处于退出状态, 则当前不可调用stop.
*/
if (node->getExitStatus() == ExitStopping) {
LOG_WARN(
"Request(%p) node(%p) has invoked stop, node status:%s, exit "
"status:%s. skip ...",
request, node, node->getConnectNodeStatusString().c_str(),
node->getExitStatusString().c_str());
MUTEX_UNLOCK(_mtxThread);
return Success;
} else if (node->getExitStatus() == ExitCancel) {
LOG_WARN(
"Request(%p) node(%p) has invoked cancel, node status:%s, exit "
"status:%s. skip ...",
request, node, node->getConnectNodeStatusString().c_str(),
node->getExitStatusString().c_str());
MUTEX_UNLOCK(_mtxThread);
return Success;
}
if (node->getConnectNodeStatus() < NodeInvoking ||
node->getConnectNodeStatus() >= NodeFailed ||
node->getExitStatus() != ExitInvalid) {
LOG_ERROR(
"Request(%p) node(%p) invoke stop command failed, current status is "
"invalid. node status:%s, exit status:%s.",
request, node, node->getConnectNodeStatusString().c_str(),
node->getExitStatusString().c_str());
MUTEX_UNLOCK(_mtxThread);
return -(InvokeStopFailed);
}
int ret = node->cmdNotify(CmdStop, NULL);
if (ret == Success && node->getSyncCallTimeout() > 0) {
node->waitInvokeFinish();
int error_code = node->getErrorCode();
if (error_code != Success) {
MUTEX_UNLOCK(_mtxThread);
return -(error_code);
}
}
MUTEX_UNLOCK(_mtxThread);
return ret;
}