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:
parent
9247d261cf
commit
720f2e9579
@ -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 };
|
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),
|
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),
|
_dataServer(_dataPort),
|
||||||
_sdClass(sdClass)
|
_sdClass(sdClass)
|
||||||
{
|
{
|
||||||
@ -918,7 +915,7 @@ class FTPServer : public TCPServer<T>
|
|||||||
if (fileToSend)
|
if (fileToSend)
|
||||||
{
|
{
|
||||||
*fts = OK;
|
*fts = OK;
|
||||||
size_t readBytes(0);
|
size_t readBytes(0), sentBytes(0);
|
||||||
fileToSend.seek(client->_fileSentBytes);
|
fileToSend.seek(client->_fileSentBytes);
|
||||||
|
|
||||||
if(fileToSend.available())
|
if(fileToSend.available())
|
||||||
@ -934,14 +931,14 @@ class FTPServer : public TCPServer<T>
|
|||||||
}
|
}
|
||||||
|
|
||||||
readBytes = fileToSend.read(sendBuffer, mallocAcceptedSize);
|
readBytes = fileToSend.read(sendBuffer, mallocAcceptedSize);
|
||||||
client->_dataClient.write(sendBuffer, readBytes);
|
sentBytes = client->_dataClient.write(sendBuffer, readBytes);
|
||||||
|
|
||||||
free(sendBuffer);
|
free(sendBuffer);
|
||||||
|
|
||||||
client->_fileSentBytes += readBytes;
|
client->_fileSentBytes += sentBytes;
|
||||||
|
|
||||||
#ifdef DEBUG_FTPS
|
#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
|
#endif
|
||||||
}
|
}
|
||||||
else //The whole file has been sent
|
else //The whole file has been sent
|
||||||
@ -1031,10 +1028,10 @@ class FTPServer : public TCPServer<T>
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
char *_login;
|
char *_login = nullptr;
|
||||||
char *_password;
|
char *_password = nullptr;
|
||||||
char *_FTPDir = 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)
|
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;
|
SDClass *_sdClass;
|
||||||
|
@ -575,7 +575,7 @@ class WEBServer : public TCPServer<T>, public HttpConstants
|
|||||||
{
|
{
|
||||||
File pageToSend;
|
File pageToSend;
|
||||||
char *filePath(NULL), *header(NULL);
|
char *filePath(NULL), *header(NULL);
|
||||||
size_t readBytes(0);
|
size_t readBytesFromFS(0), sentBytesFromSocket(0);
|
||||||
//We check what kind of http verb it is
|
//We check what kind of http verb it is
|
||||||
switch(client->_httpRequestData.HRM)
|
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.
|
return false; //Not clean but what else can I do. Should never happen anyway.
|
||||||
}
|
}
|
||||||
|
|
||||||
readBytes = pageToSend.read(sendBuffer,mallocAcceptedSize);
|
readBytesFromFS = pageToSend.read(sendBuffer,mallocAcceptedSize);
|
||||||
client->_client.write(sendBuffer, readBytes);
|
sentBytesFromSocket = client->_client.write(sendBuffer, readBytesFromFS);
|
||||||
|
|
||||||
free(sendBuffer);
|
free(sendBuffer);
|
||||||
|
|
||||||
#ifdef DEBUG_WEBS
|
#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
|
#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
|
else
|
||||||
{
|
{
|
||||||
|
@ -560,6 +560,8 @@ boolean ioSetModeApi(WEBServer<WEBClient>::HttpRequestData &HRD, WiFiClient *wc,
|
|||||||
|
|
||||||
boolean otaUpdateApi(WEBServer<WEBClient>::HttpRequestData &HRD, WiFiClient *wc, void *pData)
|
boolean otaUpdateApi(WEBServer<WEBClient>::HttpRequestData &HRD, WiFiClient *wc, void *pData)
|
||||||
{
|
{
|
||||||
|
(void)HRD;
|
||||||
|
(void)pData;
|
||||||
Serial.printf("OTA Update resquest\n");
|
Serial.printf("OTA Update resquest\n");
|
||||||
|
|
||||||
char buffer[500];
|
char buffer[500];
|
||||||
|
Loading…
Reference in New Issue
Block a user