diff --git a/src/common/define.h b/src/common/define.h index 128ac64d32dcf16afff81f97786e1a574f6ec827..98ca97f6c5c666441b900536e5c0d0ef49c94f0c 100644 --- a/src/common/define.h +++ b/src/common/define.h @@ -101,8 +101,8 @@ constexpr uint16_t NEW_SESSION_DROP_USB_DATA_TIME_MAX_MS = 1000; // |----------------------------------------------------------------| // | major |reserve| minor |reserve|version| fix | reserve | // |----------------------------------------------------------------| -// 0x30100300 is 3.1.0d -constexpr uint32_t HDC_VERSION_NUMBER = 0x30100300; +// 0x30100300 is 3.1.0c +constexpr uint32_t HDC_VERSION_NUMBER = 0x30100200; constexpr uint32_t HDC_BUF_MAX_BYTES = INT_MAX; #ifdef HDC_HOST constexpr uint32_t HOST_SOCKETPAIR_SIZE = 1024 * 1024; @@ -135,8 +135,6 @@ const char HUGE_BUF_TAG = 'H'; // support huge buffer const size_t BANNER_FEATURE_TAG_OFFSET = 11; const char WAIT_DEVICE_TAG = 'W'; const size_t WAIT_TAG_OFFSET = 11; -const size_t SERVICE_KILL_OFFSET = 10; -const char SERVICE_KILL_TAG = 'K'; // input command const string CMDSTR_SOFTWARE_VERSION = "version"; const string CMDSTR_SOFTWARE_HELP = "help"; diff --git a/src/common/define_enum.h b/src/common/define_enum.h index d5c35374c2b3a4bbbcda9e94de7364de60e7e91e..d502674ed690e3f68e69b05fcb4e49da10f6f55f 100644 --- a/src/common/define_enum.h +++ b/src/common/define_enum.h @@ -155,8 +155,8 @@ enum HdcCommand { CMD_CHECK_SERVER, CMD_CHECK_DEVICE, CMD_WAIT_FOR, - CMD_SERVICE_KILL, - CMD_SERVICE_START, + CMD_SERVER_KILL, // channel kill, not use + CMD_SERVICE_START = 17, // One-pass simple commands CMD_UNITY_COMMAND_HEAD = 1000, // not use CMD_UNITY_EXECUTE, diff --git a/src/common/define_plus.h b/src/common/define_plus.h index 09e12af584d3825d8d5edfee45851c3b55805552..5b7b5fd7788fc53c4063bacec58a84b407594f82 100644 --- a/src/common/define_plus.h +++ b/src/common/define_plus.h @@ -345,7 +345,6 @@ struct HdcChannel { bool fromClient = false; bool connectLocalDevice = false; bool isStableBuf = false; - bool isSupportedKillServerCmd = false; std::atomic writeFailedTimes; }; using HChannel = struct HdcChannel *; diff --git a/src/daemon/etc/hdc.root.para b/src/daemon/etc/hdc.root.para index 1c5e2f6516c28b7a970dab6e5f05e33448eb36e5..5d4de4db148b4313be22517b5c946a18a7819144 100644 --- a/src/daemon/etc/hdc.root.para +++ b/src/daemon/etc/hdc.root.para @@ -11,7 +11,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -const.hdc.version = "Ver: 3.1.0d" +const.hdc.version = "Ver: 3.1.0c" persist.hdc.mode.usb = "enable" persist.hdc.mode.tcp = "disable" persist.hdc.mode.uart = "disable" diff --git a/src/host/client.cpp b/src/host/client.cpp index b356609bcf508b8fe969eaa3444dec19d2bf0e36..f8e91efc148db63db95697c946e820a7093d3b65 100755 --- a/src/host/client.cpp +++ b/src/host/client.cpp @@ -120,54 +120,34 @@ bool HdcClient::ChannelCtrlServer(const string &cmd, string &connectKey) bool isRestart = (cmd.find(" -r") != std::string::npos); bool isKill = !strncmp(cmd.c_str(), CMDSTR_SERVICE_KILL.c_str(), CMDSTR_SERVICE_KILL.size()); bool isStart = !strncmp(cmd.c_str(), CMDSTR_SERVICE_START.c_str(), CMDSTR_SERVICE_START.size()); + if (isKill) { + Base::PrintMessage("Kill server failed unsupport channel kill."); + return false; + } + if (!isStart) { + Base::PrintMessage("Unknown command"); + return false; + } Initial(connectKey); // server is not running, "hdc start [-r]" and "hdc kill -r" will start server directly. if (serverStatus == 0) { - if ((isRestart && isKill) || isStart) { - ChannelCtrlServerStart(channelHostPort.c_str()); - } else if (!isRestart && isKill) { // "hdc kill" will print message and exit directly. - Base::PrintMessage("hdc server process not exists"); - } + ChannelCtrlServerStart(channelHostPort.c_str()); return true; } // server is running - if (isStart) { - if (isRestart) { // "hdc start -r": kill and restart server. - ExecuteCommand(CMDSTR_SERVICE_KILL.c_str()); - MallocChannel(&channel); - ChannelCtrlServerStart(channelHostPort.c_str()); - } else { // "hdc start": ignore and print message. - Base::PrintMessage("hdc server process already exists"); - } - return true; - } else if (isKill) { // "hdc kill": kill server. - ExecuteCommand(CMDSTR_SERVICE_KILL.c_str()); - if (isRestart) { // "-r": restart server. - MallocChannel(&channel); - ChannelCtrlServerStart(channelHostPort.c_str()); + if (isRestart) { // "hdc start -r": kill and restart server. + if (!KillMethodByUv()) { + return false; } - return true; + ChannelCtrlServerStart(channelHostPort.c_str()); + } else { // "hdc start": ignore and print message. + Base::PrintMessage("hdc server process already exists"); } return true; } -bool HdcClient::KillServer(const string &cmd) +bool HdcClient::KillMethodByUv() { - int serverStatus = Base::ProgramMutex(SERVER_NAME.c_str(), true); - if (serverStatus < 0) { - WRITE_LOG(LOG_DEBUG, "get server status failed, serverStatus:%d", serverStatus); - return false; - } - - // server is not running - if (serverStatus == 0) { - if (cmd.find(" -r") != std::string::npos) { - HdcServer::PullupServer(channelHostPort.c_str()); - } - return true; - } - - // server is running uint32_t pid = GetLastPID(); if (pid == 0) { Base::PrintMessage(TERMINAL_HDC_PROCESS_FAILED.c_str()); @@ -181,7 +161,25 @@ bool HdcClient::KillServer(const string &cmd) char buf[size] = { 0 }; uv_strerror_r(rc, buf, size); Base::PrintMessage("Kill server failed %s", buf); + return false; + } + return true; +} + +bool HdcClient::KillServer(const string &cmd) +{ + int serverStatus = Base::ProgramMutex(SERVER_NAME.c_str(), true); + if (serverStatus < 0) { + WRITE_LOG(LOG_DEBUG, "get server status failed, serverStatus:%d", serverStatus); + return false; + } + + // server is running + if (serverStatus != 0 && !KillMethodByUv()) { + return false; } + + // server need to restart if (cmd.find(" -r") != std::string::npos) { string connectKey; Base::PrintMessage("hdc start server, listening: %s", channelHostPort.c_str()); @@ -231,7 +229,6 @@ string HdcClient::AutoConnectKey(string &doCommand, const string &preConnectKey) vecNoConnectKeyCommand.push_back(CMDSTR_SOFTWARE_VERSION); vecNoConnectKeyCommand.push_back(CMDSTR_SOFTWARE_HELP); vecNoConnectKeyCommand.push_back(CMDSTR_TARGET_DISCOVER); - vecNoConnectKeyCommand.push_back(CMDSTR_SERVICE_KILL); vecNoConnectKeyCommand.push_back(CMDSTR_LIST_TARGETS); vecNoConnectKeyCommand.push_back(CMDSTR_CHECK_SERVER); vecNoConnectKeyCommand.push_back(CMDSTR_CONNECT_TARGET); @@ -484,14 +481,6 @@ void HdcClient::CommandWorker(uv_timer_t *handle) return; } uv_timer_stop(handle); - - if (!strncmp(thisClass->command.c_str(), CMDSTR_SERVICE_KILL.c_str(), - CMDSTR_SERVICE_KILL.size()) && !thisClass->channel->isSupportedKillServerCmd) { - WRITE_LOG(LOG_DEBUG, "uv_kill server"); - thisClass->CtrlServiceWork(thisClass->command.c_str()); - return; - } - WRITE_LOG(LOG_DEBUG, "Connect server successful"); bool closeInput = false; if (!HostUpdater::ConfirmCommand(thisClass->command, closeInput)) { @@ -664,10 +653,8 @@ int HdcClient::PreHandshake(HChannel hChannel, const uint8_t *buf) return ERR_BUF_CHECK; } hChannel->isStableBuf = (hShake->banner[BANNER_FEATURE_TAG_OFFSET] != HUGE_BUF_TAG); - hChannel->isSupportedKillServerCmd = - (hShake->banner[SERVICE_KILL_OFFSET] == SERVICE_KILL_TAG); - WRITE_LOG(LOG_DEBUG, "Channel PreHandshake isStableBuf:%d, killflag:%d", - hChannel->isStableBuf, hChannel->isSupportedKillServerCmd); + WRITE_LOG(LOG_DEBUG, "Channel PreHandshake isStableBuf:%d", + hChannel->isStableBuf); if (this->command == CMDSTR_WAIT_FOR && !connectKey.empty()) { hShake->banner[WAIT_TAG_OFFSET] = WAIT_DEVICE_TAG; } diff --git a/src/host/client.h b/src/host/client.h index ce20548f38e0f573cd4f4b4d2fddffc5277f7d1d..9e3ea7a7d3e1a73fa59990886c5cd73ed3574d53 100755 --- a/src/host/client.h +++ b/src/host/client.h @@ -57,6 +57,7 @@ private: bool WaitFor(const string &str); string ListTargetsAll(const string &str); void UpdateList(const string &str); + bool KillMethodByUv(); #ifdef _WIN32 static string GetHilogPath(); diff --git a/src/host/host_usb.h b/src/host/host_usb.h index f01af26899eb54069c4f7dba8e2e71adec611487..252d7f7b363b805e75d0186e7c131da92fa2499d 100644 --- a/src/host/host_usb.h +++ b/src/host/host_usb.h @@ -34,7 +34,6 @@ public: HSession ConnectDetectDaemon(const HSession hSession, const HDaemonInfo pdi); void Stop(); void RemoveIgnoreDevice(string &mountInfo); - void SendSoftResetToDaemon(HSession hSession, uint32_t sessionIdOld); private: enum UsbCheckStatus { @@ -68,6 +67,7 @@ private: void CancelUsbIo(HSession hSession) override; int UsbToHdcProtocol(uv_stream_t *stream, uint8_t *appendData, int dataSize) override; int SubmitUsbBio(HSession hSession, bool sendOrRecv, uint8_t *buf, int bufSize); + void SendSoftResetToDaemon(HSession hSession, uint32_t sessionIdOld); libusb_context *ctxUSB; uv_timer_t devListWatcher; diff --git a/src/host/main.cpp b/src/host/main.cpp index 43bafa0cc146d6f3c9cc02a4eb6b50ecde81a629..46e541099e8bf117dfea4c3f808fcd2e4e908e38 100644 --- a/src/host/main.cpp +++ b/src/host/main.cpp @@ -201,12 +201,12 @@ int RunClientMode(string &commands, string &serverListenString, string &connectK std::cerr << TranslateCommand::Usage(); return 0; } - if (!strncmp(commands.c_str(), CMDSTR_GENERATE_KEY.c_str(), CMDSTR_GENERATE_KEY.size())) { + if (!strncmp(commands.c_str(), CMDSTR_GENERATE_KEY.c_str(), CMDSTR_GENERATE_KEY.size()) || + !strncmp(commands.c_str(), CMDSTR_SERVICE_KILL.c_str(), CMDSTR_SERVICE_KILL.size())) { client.CtrlServiceWork(commands.c_str()); return 0; } - if (!strncmp(commands.c_str(), CMDSTR_SERVICE_KILL.c_str(), CMDSTR_SERVICE_KILL.size()) || - !strncmp(commands.c_str(), CMDSTR_SERVICE_START.c_str(), CMDSTR_SERVICE_START.size())) { + if (!strncmp(commands.c_str(), CMDSTR_SERVICE_START.c_str(), CMDSTR_SERVICE_START.size())) { client.ChannelCtrlServer(commands, connectKey); return 0; } diff --git a/src/host/server.cpp b/src/host/server.cpp index 349467c267b7e83d8a8eac19267473a649b68f63..0948b5df3516ebe15de0b3256b4d751f83f22934 100644 --- a/src/host/server.cpp +++ b/src/host/server.cpp @@ -1058,30 +1058,4 @@ void HdcServer::EchoToClientsForSession(uint32_t targetSessionId, const string & WRITE_LOG(LOG_INFO, "%s:%u %s", __FUNCTION__, targetSessionId, echo.c_str()); hSfc->EchoToAllChannelsViaSessionId(targetSessionId, echo); } - -void HdcServer::SessionSoftReset() -{ - uv_rwlock_rdlock(&daemonAdmin); - map::iterator iter; - for (iter = mapDaemon.begin(); iter != mapDaemon.end(); ++iter) { - HDaemonInfo di = iter->second; - if (!di) { - continue; - } - string devname = di->devName; - if (devname.empty()) { - continue; - } else if ((di->connStatus != STATUS_CONNECTED)) { - continue; - } - if (di->connType == CONN_USB) { - HSession hSession = di->hSession; - if (!hSession) { - continue; - } - clsUSBClt->SendSoftResetToDaemon(hSession, 0); - } - } - uv_rwlock_rdunlock(&daemonAdmin); -} } // namespace Hdc diff --git a/src/host/server.h b/src/host/server.h index dbde82989f76bf8fbd278703199954853ee84cdc..0d1640af4e91002d3711b2119f9f14f89d4e5c75 100755 --- a/src/host/server.h +++ b/src/host/server.h @@ -35,7 +35,6 @@ public: static bool PullupServer(const char *listenString); static void UsbPreConnect(uv_timer_t *handle); void NotifyInstanceSessionFree(HSession hSession, bool freeOrClear) override; - void SessionSoftReset(); HdcHostTCP *clsTCPClt; HdcHostUSB *clsUSBClt; diff --git a/src/host/server_for_client.cpp b/src/host/server_for_client.cpp index 55591defc094c89ce39ad37ad3d1097adbdb1588..809d97b969e51bdb116540568d8002b44b3e01c4 100755 --- a/src/host/server_for_client.cpp +++ b/src/host/server_for_client.cpp @@ -80,7 +80,6 @@ void HdcServerForClient::AcceptClient(uv_stream_t *server, int status) struct ChannelHandShake handShake = {}; if (EOK == strcpy_s(handShake.banner, sizeof(handShake.banner), HANDSHAKE_MESSAGE.c_str())) { handShake.banner[BANNER_FEATURE_TAG_OFFSET] = HUGE_BUF_TAG; // set feature tag for huge buf size - handShake.banner[SERVICE_KILL_OFFSET] = SERVICE_KILL_TAG; handShake.channelId = htonl(hChannel->channelId); string ver = Base::GetVersion() + HDC_MSG_HASH; WRITE_LOG(LOG_DEBUG, "Server ver:%s", ver.c_str()); @@ -492,12 +491,6 @@ bool HdcServerForClient::DoCommandLocal(HChannel hChannel, void *formatCommandIn ret = false; break; } - case CMD_SERVICE_KILL: { - ptrServer->SessionSoftReset(); - WRITE_LOG(LOG_DEBUG, "server kill"); - EchoClient(hChannel, MSG_OK, "Kill server finish"); - _exit(0); - } case CMD_CHECK_SERVER: { WRITE_LOG(LOG_DEBUG, "CMD_CHECK_SERVER command"); ReportServerVersion(hChannel); diff --git a/src/host/translate.cpp b/src/host/translate.cpp index d8bef903bc4e1ea62c30612798e32a3b27bd37b8..5b518637685daa7c63f65e93397a0c4f50e84de5 100755 --- a/src/host/translate.cpp +++ b/src/host/translate.cpp @@ -343,8 +343,6 @@ namespace TranslateCommand { if (strstr(input.c_str(), " -v")) { outCmd->parameters = "v"; } - } else if (!strncmp(input.c_str(), CMDSTR_SERVICE_KILL.c_str(), CMDSTR_SERVICE_KILL.size())) { - outCmd->cmdFlag = CMD_SERVICE_KILL; } else if (!strncmp(input.c_str(), CMDSTR_SERVICE_START.c_str(), CMDSTR_SERVICE_START.size())) { outCmd->cmdFlag = CMD_SERVICE_START; } else if (!strncmp(input.c_str(), CMDSTR_CHECK_SERVER.c_str(), CMDSTR_CHECK_SERVER.size())) {