Skip to content
Snippets Groups Projects
Commit 1a8b52c3 authored by Guillaume Roguez's avatar Guillaume Roguez Committed by Olivier SOLDANO
Browse files

ftp: fix write when out file is closed and emit condition.


* protect against write() call on a closed incoming stream.
* Use DataTransferEventCode::closed_by_peer when
data are not completly received, else ataTransferEventCode::finished
is emitted.

Change-Id: I15f2518f70afbe1bfe8aa8813cbca676dec4360a
Reviewed-by: default avatarOlivier Soldano <olivier.soldano@savoirfairelinux.com>
parent 56276217
No related branches found
No related tags found
No related merge requests found
......@@ -287,9 +287,13 @@ IncomingFileTransfer::close() noexcept
} catch (...) {}
fout_.close();
RING_DBG() << "[FTP] file closed with size " << info_.bytesProgress;
emit(DRing::DataTransferEventCode::finished);
RING_DBG() << "[FTP] file closed, rx " << info_.bytesProgress
<< " on " << info_.totalSize;
if (std::size_t(info_.bytesProgress) == info_.totalSize)
emit(DRing::DataTransferEventCode::finished);
else
emit(DRing::DataTransferEventCode::closed_by_host);
}
void
......
......@@ -93,7 +93,8 @@ FtpServer::write(const std::vector<uint8_t>& buffer)
auto count = headerStream_.gcount();
if (!count)
continue;
out_->write(reinterpret_cast<const uint8_t*>(&line_[0]), count);
if (out_)
out_->write(reinterpret_cast<const uint8_t*>(&line_[0]), count);
rx_ += count;
if (rx_ >= fileSize_) {
closeCurrentFile();
......@@ -107,7 +108,8 @@ FtpServer::write(const std::vector<uint8_t>& buffer)
break;
case FtpState::READ_DATA:
out_->write(&buffer[0], buffer.size());
if (out_)
out_->write(&buffer[0], buffer.size());
rx_ += buffer.size();
if (rx_ >= fileSize_) {
closeCurrentFile();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment