summaryrefslogtreecommitdiffstats
path: root/ESP8266FtpServer.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'ESP8266FtpServer.cpp')
-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()