Skip to content

Commit

Permalink
Fixed bug when StreamFrameReader::addData() was running forever.
Browse files Browse the repository at this point in the history
  • Loading branch information
Fanda Vacek committed Feb 2, 2024
1 parent 4b5ac81 commit 8f4da55
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 7 deletions.
2 changes: 1 addition & 1 deletion libshvchainpack/include/shv/chainpack/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<char, 2> &arr, uint8_t i );

Expand Down Expand Up @@ -51,7 +52,6 @@ class SHVCHAINPACK_DECL_EXPORT Utils
static std::string toHex(const std::basic_string<uint8_t> &bytes);
static char fromHex(char c);
static std::string fromHex(const std::string &bytes);
static std::string hexDump(const std::string_view &bytes);

template <typename I>
static std::string toString(I n)
Expand Down
2 changes: 1 addition & 1 deletion libshvchainpack/src/chainpack/rpcdriver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
10 changes: 5 additions & 5 deletions libshvchainpack/src/chainpack/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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()) {
Expand Down
4 changes: 4 additions & 0 deletions libshviotqt/src/rpc/socket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
}
}
}

Expand Down

0 comments on commit 8f4da55

Please sign in to comment.