From 8f2b8a85aa554e2ba601abdadd3ce58ae0d5230b Mon Sep 17 00:00:00 2001 From: dai_chunwei Date: Wed, 29 Sep 2021 15:54:13 -0700 Subject: [PATCH] lib req,need long connect --- src/common/channel.cpp | 19 +++++++++++++++---- src/common/define.h | 1 + 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/src/common/channel.cpp b/src/common/channel.cpp index fa9a801a..08558720 100644 --- a/src/common/channel.cpp +++ b/src/common/channel.cpp @@ -129,9 +129,20 @@ void HdcChannelBase::ReadStream(uv_stream_t *tcp, ssize_t nread, const uv_buf_t if (hChannel->availTailIndex - DWORD_SERIALIZE_SIZE < size) { break; } - if (thisClass->ReadChannel(hChannel, (uint8_t *)hChannel->ioBuf + DWORD_SERIALIZE_SIZE + indexBuf, size) < 0) { - needExit = true; - break; + + if (!strncmp((char *)hChannel->ioBuf + DWORD_SERIALIZE_SIZE, LONG_CONN_MESSAGE.c_str(), LONG_CONN_MESSAGE.size())) { //HLONG is need long connect + if (thisClass->ReadChannel(hChannel, (uint8_t *)hChannel->ioBuf + LONG_CONN_MESSAGE.size() + DWORD_SERIALIZE_SIZE + indexBuf, size) < 0) { + // update io + hChannel->availTailIndex -= (DWORD_SERIALIZE_SIZE + size); + indexBuf += DWORD_SERIALIZE_SIZE + size; + needExit = false; // keep connect + break; + } + } else { + if (thisClass->ReadChannel(hChannel, (uint8_t *)hChannel->ioBuf + DWORD_SERIALIZE_SIZE + indexBuf, size) < 0) { + needExit = true; + break; + } } // update io hChannel->availTailIndex -= (DWORD_SERIALIZE_SIZE + size); @@ -427,4 +438,4 @@ HChannel HdcChannelBase::AdminChannel(const uint8_t op, const uint32_t channelId } return hRet; } -} \ No newline at end of file +} diff --git a/src/common/define.h b/src/common/define.h index 7b1f6396..495660d6 100644 --- a/src/common/define.h +++ b/src/common/define.h @@ -54,6 +54,7 @@ const string UT_TMP_PATH = "/tmp/hdc-ut"; const string SERVER_NAME = "HDCServer"; const string STRING_EMPTY = ""; const string HANDSHAKE_MESSAGE = "OHOS HDC"; // sep not char '-', not more than 11 bytes +const string LONG_CONN_MESSAGE = "HLONG"; // long socket connect flag const string PACKET_FLAG = "HW"; // must 2bytes const string EMPTY_ECHO = "[Empty]"; const string MESSAGE_INFO = "[Info]"; -- Gitee