I'm implementing a file transfer facility for my ESP32 app. I'm using a TCP socket for this. Small files work OK, but bigger ones eventually fail. Initially I was getting about 70KB into a file transfer before the ESP broke[*]. I inserted a small delay into my Windoze program, and that got me about 10X deeper.
[*] by "broke" I mean that the recv call returns 0 bytes, and then I start getting the error " No more processes" on subsequent read attempts. It doesn't recover until the sender gives up and sends a RST.
Here's the source code; can anyone suggest what I might be doing wrong?
Code: Select all
int Ota::receiveBinary(int size)
{
char buff[512];
int bytesRead;
int rc = 0;
ESP_LOGI(TAG, "receiveBinary(): file size is %d", size);
while (size > 0)
{
// read from the socket.
bytesRead = recv(m_sockRead, buff, (size_t) sizeof(buff), 0);//MSG_DONTWAIT);
if (bytesRead > 0)
{
ESP_LOGI(TAG, "receiveBinary(): %d bytes read.", bytesRead);
}
else if (bytesRead == 0)
{
ESP_LOGW(TAG, "receiveBinary(): recv() returned 0 bytes.");
continue;
}
else if (errno == EAGAIN || errno == EWOULDBLOCK)
{
ESP_LOGW(TAG, "receiveBinary(): recv() returned error %s", strerror(errno));
continue;
}
else
{
ESP_LOGE(TAG, "receiveBinary(): recv() returned error %s.", strerror(errno));
rc = -1;
break;
}
size -= bytesRead;
ESP_LOGI(TAG, "receiveBinary(): %d bytes remaining.", size);
}
ESP_ERROR_CHECK(close(m_sockRead));
ESP_LOGI(TAG, "receiveBinary(): closed socket sockRead.");
return rc;
}