diff --git a/native/serverconnection/src/connection/ft/FileTransferManager.cpp b/native/serverconnection/src/connection/ft/FileTransferManager.cpp index ac98b36..58b5adf 100644 --- a/native/serverconnection/src/connection/ft/FileTransferManager.cpp +++ b/native/serverconnection/src/connection/ft/FileTransferManager.cpp @@ -376,7 +376,6 @@ void Transfer::callback_write(short flags) { uint64_t buffer_size = 1400; /* best TCP packet size (equal to the MTU) */ pipes::buffer buffer{buffer_size}; auto read_status = source->read_bytes(error, buffer.data_ptr(), buffer_size); - this->last_source_read = system_clock::now(); if(read_status != error::success) { if(read_status == error::would_block) { readd_write_for_read = true; @@ -398,6 +397,7 @@ void Transfer::callback_write(short flags) { break; } + this->last_source_read = system_clock::now(); { lock_guard lock(this->queue_lock); this->write_queue.push_back(buffer.range(0, buffer_size)); diff --git a/native/serverconnection/src/connection/ft/FileTransferObject.cpp b/native/serverconnection/src/connection/ft/FileTransferObject.cpp index c4be3f3..3aea0e1 100644 --- a/native/serverconnection/src/connection/ft/FileTransferObject.cpp +++ b/native/serverconnection/src/connection/ft/FileTransferObject.cpp @@ -207,6 +207,7 @@ uint64_t TransferFileSource::byte_length() const { bool TransferFileSource::initialize(std::string &error) { auto file = fs::u8path(this->_path) / fs::u8path(this->_name); + log_debug(category::file_transfer, tr("Opening source file for transfer: {} ({})"), file.string(), fs::absolute(file).string()); error_code errc; if(!fs::exists(file)) { @@ -252,22 +253,36 @@ void TransferFileSource::finalize() { } error::value TransferFileSource::read_bytes(std::string &error, uint8_t *buffer, uint64_t &length) { - auto result = this->file_stream.readsome((char*) buffer, length); + error.clear(); +#ifdef WIN32 + auto blength = this->byte_length(); + if(this->position >= blength) { + error = "eof reached"; + return error::custom; + } + if(this->position + length > this->byte_length()) + length = this->byte_length() - this->position; + this->file_stream.read((char*) buffer, length); + this->position += length; +#else + auto result = this->file_stream.readsome((char*) buffer, length); if(result > 0) { length = result; this->position += result; return error::success; - } + } else if(result == 0) { + return error::would_block; + } else + error = "read returned " + to_string(result) + "/" + to_string(length); +#endif if(!this->file_stream) { if(this->file_stream.eof()) error = "eof reached"; else error = "io error. failed to read"; - } else { - error = "read returned " + to_string(result) + "/" + to_string(length); } - return error::custom; + return error.empty() ? error::success : error::custom; } uint64_t TransferFileSource::stream_index() const {