From 8f4da556c5b01bfc0f75051153566791b0d101c3 Mon Sep 17 00:00:00 2001 From: Fanda Vacek Date: Fri, 2 Feb 2024 19:32:38 +0100 Subject: [PATCH] Fixed bug when StreamFrameReader::addData() was running forever. --- libshvchainpack/include/shv/chainpack/utils.h | 2 +- libshvchainpack/src/chainpack/rpcdriver.cpp | 2 +- libshvchainpack/src/chainpack/utils.cpp | 10 +++++----- libshviotqt/src/rpc/socket.cpp | 4 ++++ 4 files changed, 11 insertions(+), 7 deletions(-) diff --git a/libshvchainpack/include/shv/chainpack/utils.h b/libshvchainpack/include/shv/chainpack/utils.h index 08b13ce4b..7f55f8346 100644 --- a/libshvchainpack/include/shv/chainpack/utils.h +++ b/libshvchainpack/include/shv/chainpack/utils.h @@ -18,6 +18,7 @@ namespace utils { SHVCHAINPACK_DECL_EXPORT std::string hexArray(const char *bytes, size_t n); SHVCHAINPACK_DECL_EXPORT std::string hexDump(const char *bytes, size_t n); +SHVCHAINPACK_DECL_EXPORT std::string hexDump(const std::string_view &bytes); SHVCHAINPACK_DECL_EXPORT std::string byteToHex( uint8_t i ); SHVCHAINPACK_DECL_EXPORT void byteToHex( std::array &arr, uint8_t i ); @@ -51,7 +52,6 @@ class SHVCHAINPACK_DECL_EXPORT Utils static std::string toHex(const std::basic_string &bytes); static char fromHex(char c); static std::string fromHex(const std::string &bytes); - static std::string hexDump(const std::string_view &bytes); template static std::string toString(I n) diff --git a/libshvchainpack/src/chainpack/rpcdriver.cpp b/libshvchainpack/src/chainpack/rpcdriver.cpp index ebbe6cd3e..dba2f0a27 100644 --- a/libshvchainpack/src/chainpack/rpcdriver.cpp +++ b/libshvchainpack/src/chainpack/rpcdriver.cpp @@ -48,7 +48,7 @@ void RpcDriver::sendRpcFrame(RpcFrame &&frame) void RpcDriver::onFrameDataRead(std::string &&frame_data) { logRpcData() << __PRETTY_FUNCTION__ << "+++++++++++++++++++++++++++++++++"; - logRpcData().nospace() << "FRAME DATA " << frame_data.size() << " bytes of data read:\n" << shv::chainpack::Utils::hexDump(frame_data); + logRpcData().nospace() << "FRAME DATA " << frame_data.size() << " bytes of data read:\n" << shv::chainpack::utils::hexDump(frame_data); try { auto frame = RpcFrame::fromChainPack(std::move(frame_data)); onRpcFrameReceived(std::move(frame)); diff --git a/libshvchainpack/src/chainpack/utils.cpp b/libshvchainpack/src/chainpack/utils.cpp index 8d5545cf4..39bc564e1 100644 --- a/libshvchainpack/src/chainpack/utils.cpp +++ b/libshvchainpack/src/chainpack/utils.cpp @@ -72,6 +72,11 @@ string hexArray(const char *bytes, size_t n) return ret + ']'; } +string hexDump(const std::string_view &bytes) +{ + return utils::hexDump(bytes.data(), bytes.size()); +} + } std::string Utils::removeJsonComments(const std::string &json_str) { @@ -152,11 +157,6 @@ std::string Utils::fromHex(const std::string &bytes) return ret; } -std::string Utils::hexDump(const std::string_view &bytes) -{ - return utils::hexDump(bytes.data(), bytes.size()); -} - RpcValue Utils::mergeMaps(const RpcValue &value_base, const RpcValue &value_over) { if(value_over.isMap() && value_base.isMap()) { diff --git a/libshviotqt/src/rpc/socket.cpp b/libshviotqt/src/rpc/socket.cpp index 734d1c058..6d8538452 100644 --- a/libshviotqt/src/rpc/socket.cpp +++ b/libshviotqt/src/rpc/socket.cpp @@ -61,6 +61,7 @@ void FrameWriter::flushToWebSocket(QWebSocket *socket) void StreamFrameReader::addData(std::string_view data) { m_readBuffer += data; + shvDebug() << "received:\n" << chainpack::utils::hexDump(data); while (true) { std::istringstream in(m_readBuffer); int err_code; @@ -82,6 +83,9 @@ void StreamFrameReader::addData(std::string_view data) m_readBuffer = std::string(m_readBuffer, consumed_len + frame_size); m_frames.push_back(std::move(frame)); } + else { + break; + } } }