mirror of
https://gitee.com/openharmony/developtools_hdc
synced 2024-11-23 15:12:24 +00:00
some socket mntn
Signed-off-by: 李帅 <leo.lishuai@huawei.com>
This commit is contained in:
parent
30bc9658fb
commit
a04a22f9c7
@ -833,6 +833,7 @@ void PrintLogEx(const char *functionName, int line, uint8_t logLevel, const char
|
||||
{
|
||||
bool hasCallClose = false;
|
||||
if (handle->loop && !uv_is_closing(handle)) {
|
||||
DispUvStreamInfo((const uv_stream_t *)handle, "before uv handle close");
|
||||
uv_close((uv_handle_t *)handle, closeCallBack);
|
||||
hasCallClose = true;
|
||||
}
|
||||
@ -841,6 +842,24 @@ void PrintLogEx(const char *functionName, int line, uint8_t logLevel, const char
|
||||
}
|
||||
}
|
||||
|
||||
void DispUvStreamInfo(const uv_stream_t *handle, const char *prefix)
|
||||
{
|
||||
uv_handle_type type = handle->type;
|
||||
string name = "unknown";
|
||||
if (type == UV_TCP) {
|
||||
name = "tcp";
|
||||
} else if (type == UV_NAMED_PIPE) {
|
||||
name = "named_pipe";
|
||||
} else {
|
||||
WRITE_LOG(LOG_DEBUG, "%s, the uv handle type is %d", prefix, type);
|
||||
return;
|
||||
}
|
||||
|
||||
size_t bufNotSended = uv_stream_get_write_queue_size(handle);
|
||||
if (bufNotSended != 0) {
|
||||
WRITE_LOG(LOG_DEBUG, "%s, the uv handle type is %s, has %u bytes data", prefix, name.c_str(), bufNotSended);
|
||||
}
|
||||
}
|
||||
int SendToStream(uv_stream_t *handleStream, const uint8_t *buf, const int bufLen)
|
||||
{
|
||||
StartTraceScope("Base::SendToStream");
|
||||
@ -1860,6 +1879,9 @@ void PrintLogEx(const char *functionName, int line, uint8_t logLevel, const char
|
||||
uint8_t version = (HDC_VERSION_NUMBER << 12 >> 24) & 0xff;
|
||||
uint8_t fix = (HDC_VERSION_NUMBER << 20 >> 28) & 0xff; // max 16, tail is p
|
||||
string ver = StringFormat("%x.%x.%x%c", major, minor, version, a + fix);
|
||||
#ifndef IS_RELEASE_VERSION
|
||||
ver += " for ide mac test only";
|
||||
#endif
|
||||
return "Ver: " + ver;
|
||||
}
|
||||
|
||||
|
@ -78,6 +78,7 @@ namespace Base {
|
||||
void TryCloseHandle(const uv_handle_t *handle);
|
||||
void TryCloseHandle(const uv_handle_t *handle, uv_close_cb closeCallBack);
|
||||
void TryCloseHandle(const uv_handle_t *handle, bool alwaysCallback, uv_close_cb closeCallBack);
|
||||
void DispUvStreamInfo(const uv_stream_t *handle, const char *prefix);
|
||||
char **SplitCommandToArgs(const char *cmdStringLine, int *slotIndex);
|
||||
bool RunPipeComand(const char *cmdString, char *outBuf, uint16_t sizeOutBuf, bool ignoreTailLf);
|
||||
// results need to save in buf which can't be const
|
||||
|
@ -189,6 +189,11 @@ struct HdcUART {
|
||||
};
|
||||
using HUART = struct HdcUART *;
|
||||
#endif
|
||||
struct HdcSessionStat {
|
||||
// send/recv bytes for dataPipe/dataFd
|
||||
std::atomic<uint64_t> dataSendBytes;
|
||||
std::atomic<uint64_t> dataRecvBytes;
|
||||
};
|
||||
|
||||
struct HdcSession {
|
||||
bool serverOrDaemon; // instance of daemon or server
|
||||
@ -239,6 +244,7 @@ struct HdcSession {
|
||||
std::atomic<bool> isNeedDropData; // host: Whether to discard the USB data after it is read
|
||||
bool isSoftReset; // for daemon, Used to record whether a reset command has been received
|
||||
|
||||
HdcSessionStat stat;
|
||||
std::string ToDebugString()
|
||||
{
|
||||
std::ostringstream oss;
|
||||
@ -278,6 +284,7 @@ struct HdcSession {
|
||||
(void)memset_s(dataPipe, sizeof(dataPipe), 0, sizeof(dataPipe));
|
||||
(void)memset_s(&hChildWorkTCP, sizeof(hChildWorkTCP), 0, sizeof(hChildWorkTCP));
|
||||
(void)memset_s(&fdChildWorkTCP, sizeof(fdChildWorkTCP), 0, sizeof(fdChildWorkTCP));
|
||||
(void)memset_s(&stat, sizeof(stat), 0, sizeof(stat));
|
||||
#ifdef HDC_SUPPORT_UART
|
||||
hUART = nullptr;
|
||||
#endif
|
||||
|
@ -644,6 +644,7 @@ void HdcSessionBase::FreeSession(const uint32_t sessionId)
|
||||
WRITE_LOG(LOG_WARN, "FreeSession hSession nullptr or isDead sessionId:%u", sessionId);
|
||||
break;
|
||||
}
|
||||
WRITE_LOG(LOG_INFO, "dataFdSend:%llu, dataFdRecv:%llu", uint64_t(hSession->stat.dataSendBytes), uint64_t(hSession->stat.dataRecvBytes));
|
||||
hSession->isDead = true;
|
||||
Base::TimerUvTask(&loopMain, hSession, FreeSessionOpeate);
|
||||
NotifyInstanceSessionFree(hSession, false);
|
||||
@ -972,6 +973,7 @@ int HdcSessionBase::FetchIOBuf(HSession hSession, uint8_t *ioBuf, int read)
|
||||
WRITE_LOG(LOG_FATAL, "FetchIOBuf read io failed,%s", buf);
|
||||
return ERR_IO_FAIL;
|
||||
}
|
||||
hSession->stat.dataRecvBytes += read;
|
||||
hSession->availTailIndex += read;
|
||||
while (!hSession->isDead && hSession->availTailIndex > static_cast<int>(sizeof(PayloadHead))) {
|
||||
childRet = ptrConnect->OnRead(hSession, ioBuf + indexBuf, hSession->availTailIndex);
|
||||
|
@ -482,6 +482,7 @@ int HdcHostUSB::UsbToHdcProtocol(uv_stream_t *stream, uint8_t *appendData, int d
|
||||
strerror_r(errno, buf, bufSize);
|
||||
#endif
|
||||
WRITE_LOG(LOG_FATAL, "select error:%d [%s][%d]", errno, buf, childRet);
|
||||
Base::DispUvStreamInfo(stream, "hostusb select failed");
|
||||
break;
|
||||
}
|
||||
childRet = send(fd, reinterpret_cast<const char *>(appendData) + index, dataSize - index, 0);
|
||||
@ -494,10 +495,12 @@ int HdcHostUSB::UsbToHdcProtocol(uv_stream_t *stream, uint8_t *appendData, int d
|
||||
strerror_r(errno, buf, bufSize);
|
||||
#endif
|
||||
WRITE_LOG(LOG_FATAL, "UsbToHdcProtocol senddata err:%d [%s]", errno, buf);
|
||||
Base::DispUvStreamInfo(stream, "hostusb send failed");
|
||||
break;
|
||||
}
|
||||
index += childRet;
|
||||
}
|
||||
hSession->stat.dataSendBytes += index;
|
||||
if (index != dataSize) {
|
||||
WRITE_LOG(LOG_FATAL, "UsbToHdcProtocol partialsenddata err:%d [%d]", index, dataSize);
|
||||
return ERR_IO_FAIL;
|
||||
|
Loading…
Reference in New Issue
Block a user