工具与软件:
社区、您好!
我在自定义应用程序中有 OTA 更新。 更新文件(.tar)位于服务器上。
更新过程中的某个时间、我会收到 SLNETERR_BSD_EAGAIN 错误。 当服务器在套接字超时之前没有响应时会发生这种情况。
我已将套接字超时设置为5秒、我认为服务器有足够的时间进行响应。
SLNETERR_BSD_EAGAIN 错误意味着重试,但在 ProcessOta()中,当该错误出现时,将停止 OTA 更新,显示错误消息"OTA_NOTIF_DOWNLOAD_ERROR" 。
为了避免这种情况、我将通过再次调用 GetChunk 回调尝试获取丢失的数据包、您也可以在下面的代码片段中看到。
对于测试、我将重试尝试次数保持为10。
问题是、如果我不在两次尝试之间保持睡眠时间、则会连续出现相同的套接字超时错误、并且所有重试尝试都将消失。
保留此睡眠时间后、我仍然会收到此错误、但不会超过重试尝试次数。
我的问题是、为什么需要这个睡眠时间?
可能是 NWP 处理器繁忙而没有及时响应请求?
我无法理解这种行为。
以下代码片段来自函数 ProcessOta()的 ota_if.c 文件
do
{
/* Now, fill the rest of the buffer (using GetChunk Callback) */
rc = m_sessionCBs[m_ota.type].fGetChunk(m_ota.hSession, &m_ota.buff[nUnprocessed], OTA_BUFF_SIZE-nUnprocessed);
if(rc > 0)
{
/* Update counters with the actual number of bytes read */
m_ota.nTotalRead += rc;
nUnprocessed += rc;
ui8RetryCnt = 0;
LOG_DEBUG("ProcessOta:: read=%d (%d)", rc, m_ota.nTotalRead);
}
else if(rc == 0)
{
/* mark end of input */
bEndOfInput = true;
LOG_DEBUG("ProcessOta:: read=0 (%d)", m_ota.nTotalRead);
}
else if((rc == SLNETERR_BSD_EAGAIN) && (ui8RetryCnt < OTA_PACKET_RETRY_COUNT))
{
LOG_WARNING("ProcessOta:: Socket did not respond and trying again!");
sleep(1);
}
else
{
LOG_ERROR("ProcessOta: ---- Can't get next chunk (%d)", rc);
return rc;
}
ui8RetryCnt++;
if(ui8RetryCnt > OTA_PACKET_RETRY_COUNT)
{
break;
}
}
while(rc == SLNETERR_BSD_EAGAIN);