Removed the unused variable warning in the new WEB API endpoint, changed the way sent files are handled regarding the sent bytes count both for the FTPServer and WEBServer

This commit is contained in:
Anatole SCHRAMM 2022-04-29 09:58:15 +02:00
parent 9247d261cf
commit 720f2e9579
3 changed files with 14 additions and 15 deletions

View File

@ -19,9 +19,6 @@ class FTPServer : public TCPServer<T>
enum FTPMsgCode {_150, _200, _215, _220, _221, _230, _226, _227, _250, _257, _331, _350, _451, _5_502, _504, _530, _550 };
FTPServer(uint16_t port = 21, SDClass *sdClass = NULL, const char *login = NULL, const char *password = NULL, uint8_t maxClient = MAX_CLIENT, uint16_t clientCommandDataBufferSize = 255) : TCPServer<T>(port, maxClient, clientCommandDataBufferSize),
_login(NULL),
_password(NULL),
_dataPort(1024),
_dataServer(_dataPort),
_sdClass(sdClass)
{
@ -918,7 +915,7 @@ class FTPServer : public TCPServer<T>
if (fileToSend)
{
*fts = OK;
size_t readBytes(0);
size_t readBytes(0), sentBytes(0);
fileToSend.seek(client->_fileSentBytes);
if(fileToSend.available())
@ -934,14 +931,14 @@ class FTPServer : public TCPServer<T>
}
readBytes = fileToSend.read(sendBuffer, mallocAcceptedSize);
client->_dataClient.write(sendBuffer, readBytes);
sentBytes = client->_dataClient.write(sendBuffer, readBytes);
free(sendBuffer);
client->_fileSentBytes += readBytes;
client->_fileSentBytes += sentBytes;
#ifdef DEBUG_FTPS
Serial.printf("File : bytes sent : %u - free stack : %u\n", readBytes, ESP.getFreeContStack());
Serial.printf("File : bytes read : %u, bytes sent : %u - free stack : %u\n", readBytes, sentBytes, ESP.getFreeContStack());
#endif
}
else //The whole file has been sent
@ -1031,10 +1028,10 @@ class FTPServer : public TCPServer<T>
}
}
char *_login;
char *_password;
char *_login = nullptr;
char *_password = nullptr;
char *_FTPDir = nullptr;
uint16_t _dataPort;
uint16_t _dataPort = 1024;
WiFiServer _dataServer; //In passive mode, the FTP server opens two different ports (one for the commands and the other for the data stream)
SDClass *_sdClass;

View File

@ -575,7 +575,7 @@ class WEBServer : public TCPServer<T>, public HttpConstants
{
File pageToSend;
char *filePath(NULL), *header(NULL);
size_t readBytes(0);
size_t readBytesFromFS(0), sentBytesFromSocket(0);
//We check what kind of http verb it is
switch(client->_httpRequestData.HRM)
{
@ -715,16 +715,16 @@ class WEBServer : public TCPServer<T>, public HttpConstants
return false; //Not clean but what else can I do. Should never happen anyway.
}
readBytes = pageToSend.read(sendBuffer,mallocAcceptedSize);
client->_client.write(sendBuffer, readBytes);
readBytesFromFS = pageToSend.read(sendBuffer,mallocAcceptedSize);
sentBytesFromSocket = client->_client.write(sendBuffer, readBytesFromFS);
free(sendBuffer);
#ifdef DEBUG_WEBS
Serial.printf("Bytes sent : %u, got allocated buffer size : %u - free stack : %u\n", readBytes, mallocAcceptedSize, ESP.getFreeContStack());
Serial.printf("Bytes read from FS : %u, Bytes sent : %u, got allocated buffer size : %u - free stack : %u\n", readBytesFromFS, sentBytesFromSocket, mallocAcceptedSize, ESP.getFreeContStack());
#endif
client->_fileSentBytes += readBytes; //We save the number of bytes sent so that we can reopen the file to this position later on.
client->_fileSentBytes += sentBytesFromSocket; //We save the number of bytes sent so that we can reopen the file to this position later on.
}
else
{

View File

@ -560,6 +560,8 @@ boolean ioSetModeApi(WEBServer<WEBClient>::HttpRequestData &HRD, WiFiClient *wc,
boolean otaUpdateApi(WEBServer<WEBClient>::HttpRequestData &HRD, WiFiClient *wc, void *pData)
{
(void)HRD;
(void)pData;
Serial.printf("OTA Update resquest\n");
char buffer[500];