From f1bbb8ac1e75baaf050d063b032fe5aa6275d478 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=80=E7=9B=B4=E5=90=91=E5=89=8D=E7=9A=84=E5=B0=8F?= =?UTF-8?q?=E7=99=BD=E7=BE=8A?= Date: Mon, 24 Jul 2023 02:44:06 +0000 Subject: [PATCH] update pwrapic/src/sockclient.c. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 一直向前的小白羊 --- pwrapic/src/sockclient.c | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/pwrapic/src/sockclient.c b/pwrapic/src/sockclient.c index eaa08f2..e56741c 100644 --- a/pwrapic/src/sockclient.c +++ b/pwrapic/src/sockclient.c @@ -398,24 +398,30 @@ int InitSockClient(void) InitMsgFactory(); InitThreadInfo(&g_sockThread); int ret = SUCCESS; - do { - if (CreateConnection() != SUCCESS) { - ret = ERR_COMMON; - break; - } - int r = CreateThread(&g_sockThread, RunSocketProcess, NULL); - if (r != SUCCESS) { - PwrLog(ERROR, "Create recv thread failed. ret[%d]", r); - ret = ERR_COMMON; - break; + int r; + // Initialize g_sockThread and check if it's successful + r = CreateThread(&g_sockThread, RunSocketProcess, NULL); + if (r != SUCCESS) { + PwrLog(ERROR, "Create recv thread failed. ret[%d]", r); + ret = ERR_COMMON; + } + // If g_sockThread initialization is successful, continue with connection creation + if (ret == SUCCESS) { + // CreateConnection returns SUCCESS or ERR_COMMON + ret = CreateConnection(); + if (ret != SUCCESS) { + PwrLog(ERROR, "Create connection failed. ret[%d]", ret); + FiniThreadInfo(&g_sockThread); // Cleanup the g_sockThread if the connection creation fails } - } while (0); + } + // If any of the initialization steps fail, clean up and return the error if (ret != SUCCESS) { FiniSockClient(); } return ret; } + int FiniSockClient(void) { FiniThreadInfo(&g_sockThread); -- Gitee