diff options
author | David Paiva <david@nailbuster.com> | 2018-10-05 04:22:49 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-10-05 04:22:49 +0200 |
commit | 298ccd2a10dfe8ca5033ffae7175ae5e38191fb7 (patch) | |
tree | c71aa9fe06bb47e7bd8c7f07ef28add1e1340030 | |
parent | Update README.md (diff) | |
parent | Prevent disconnect before file is fully received (diff) | |
download | FTPCLientServer-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.cpp | 18 |
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() |