summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Paiva <david@nailbuster.com>2018-10-05 04:22:49 +0200
committerGitHub <noreply@github.com>2018-10-05 04:22:49 +0200
commit298ccd2a10dfe8ca5033ffae7175ae5e38191fb7 (patch)
treec71aa9fe06bb47e7bd8c7f07ef28add1e1340030
parentUpdate README.md (diff)
parentPrevent disconnect before file is fully received (diff)
downloadFTPCLientServer-298ccd2a10dfe8ca5033ffae7175ae5e38191fb7.tar
FTPCLientServer-298ccd2a10dfe8ca5033ffae7175ae5e38191fb7.tar.gz
FTPCLientServer-298ccd2a10dfe8ca5033ffae7175ae5e38191fb7.tar.bz2
FTPCLientServer-298ccd2a10dfe8ca5033ffae7175ae5e38191fb7.tar.lz
FTPCLientServer-298ccd2a10dfe8ca5033ffae7175ae5e38191fb7.tar.xz
FTPCLientServer-298ccd2a10dfe8ca5033ffae7175ae5e38191fb7.tar.zst
FTPCLientServer-298ccd2a10dfe8ca5033ffae7175ae5e38191fb7.zip
-rw-r--r--ESP8266FtpServer.cpp18
1 files changed, 12 insertions, 6 deletions
diff --git a/ESP8266FtpServer.cpp b/ESP8266FtpServer.cpp
index 7d25e9a..98401c6 100644
--- a/ESP8266FtpServer.cpp
+++ b/ESP8266FtpServer.cpp
@@ -782,11 +782,11 @@ return false;
boolean FtpServer::doStore()
{
- if( data.connected() )
+ // Avoid blocking by never reading more bytes than are available
+ int navail = data.available();
+
+ if (navail > 0)
{
- // Avoid blocking by never reading more bytes than are available
- int navail = data.available();
- if (navail <= 0) return true;
// And be sure not to overflow buf.
if (navail > FTP_BUF_SIZE) navail = FTP_BUF_SIZE;
int16_t nb = data.read((uint8_t*) buf, navail );
@@ -797,10 +797,16 @@ boolean FtpServer::doStore()
file.write((uint8_t*) buf, nb );
bytesTransfered += nb;
}
+ }
+ if( !data.connected() && (navail <= 0) )
+ {
+ closeTransfer();
+ return false;
+ }
+ else
+ {
return true;
}
- closeTransfer();
- return false;
}
void FtpServer::closeTransfer()