From fb9a16dd40a28bd923f295361a4ce3712138dc22 Mon Sep 17 00:00:00 2001 From: Yufeng Wang Date: Tue, 17 Aug 2021 15:46:36 -0700 Subject: [PATCH] Set response timeout value during echo SendMessage --- src/protocols/echo/EchoClient.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/protocols/echo/EchoClient.cpp b/src/protocols/echo/EchoClient.cpp index 829b867794291c..5311e07a22e4cb 100644 --- a/src/protocols/echo/EchoClient.cpp +++ b/src/protocols/echo/EchoClient.cpp @@ -29,6 +29,9 @@ namespace chip { namespace Protocols { namespace Echo { +// The Echo message timeout value in milliseconds. +constexpr uint32_t kEchoMessageTimeoutMsec = 800; + CHIP_ERROR EchoClient::Init(Messaging::ExchangeManager * exchangeMgr, SecureSessionHandle session) { // Error if already initialized. @@ -74,6 +77,8 @@ CHIP_ERROR EchoClient::SendEchoRequest(System::PacketBufferHandle && payload, Me return CHIP_ERROR_NO_MEMORY; } + mExchangeCtx->SetResponseTimeout(kEchoMessageTimeoutMsec); + // Send an Echo Request message. Discard the exchange context if the send fails. err = mExchangeCtx->SendMessage(MsgType::EchoRequest, std::move(payload), sendFlags.Set(Messaging::SendMessageFlags::kExpectResponse)); @@ -114,6 +119,7 @@ CHIP_ERROR EchoClient::OnMessageReceived(Messaging::ExchangeContext * ec, const void EchoClient::OnResponseTimeout(Messaging::ExchangeContext * ec) { + mExchangeCtx = nullptr; ChipLogProgress(Echo, "Time out! failed to receive echo response from Exchange: %p", ec); }