From e1cc67c13c63b7ad894687f8f23863a737fef30f Mon Sep 17 00:00:00 2001 From: Michel De Vittori Date: Fri, 19 Jul 2019 11:10:40 +0200 Subject: Update File.cpp --- src/input/File.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/input/File.cpp') diff --git a/src/input/File.cpp b/src/input/File.cpp index 54dac1e..2528997 100644 --- a/src/input/File.cpp +++ b/src/input/File.cpp @@ -128,7 +128,7 @@ ssize_t FileBase::readFromFile(uint8_t* buffer, size_t size) return -1; } - if (buf.size() + ret == size) { + if (ret == size) { std::copy(m_nonblock_buffer.begin(), m_nonblock_buffer.end(), buffer); buffer += m_nonblock_buffer.size(); -- cgit v1.2.3 From 0993a6f886115d194466d1787b253e35921fd988 Mon Sep 17 00:00:00 2001 From: Michel De Vittori Date: Mon, 22 Jul 2019 17:26:23 +0200 Subject: Update File.cpp --- src/input/File.cpp | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) (limited to 'src/input/File.cpp') diff --git a/src/input/File.cpp b/src/input/File.cpp index 2528997..5d25f49 100644 --- a/src/input/File.cpp +++ b/src/input/File.cpp @@ -108,7 +108,8 @@ ssize_t FileBase::readFromFile(uint8_t* buffer, size_t size) ssize_t ret = 0; if (m_nonblock) { if (size > m_nonblock_buffer.size()) { - size_t required_len = size - m_nonblock_buffer.size(); + size_t m_nonblock_buffer_len = m_nonblock_buffer.size(); + size_t required_len = size - m_nonblock_buffer_len; std::vector buf(required_len); ret = read(m_fd, buf.data(), required_len); @@ -127,20 +128,15 @@ ssize_t FileBase::readFromFile(uint8_t* buffer, size_t size) etiLog.level(alert) << "ERROR: Can't read file " << strerror(errno); return -1; } - - if (ret == size) { - std::copy(m_nonblock_buffer.begin(), m_nonblock_buffer.end(), - buffer); - buffer += m_nonblock_buffer.size(); - m_nonblock_buffer.clear(); - std::copy(buf.begin(), buf.end(), buffer); - return size; - } + + std::copy(m_nonblock_buffer.begin(), m_nonblock_buffer.end(), buffer); + buffer += m_nonblock_buffer_len; + m_nonblock_buffer.clear(); + std::copy(buf.begin(), buf.end(), buffer); + return ret+m_nonblock_buffer_len; } else { - std::copy(m_nonblock_buffer.begin(), m_nonblock_buffer.begin() + size, - buffer); - + std::copy(m_nonblock_buffer.begin(), m_nonblock_buffer.begin() + size, buffer); std::vector remaining_buf; std::copy(m_nonblock_buffer.begin() + size, m_nonblock_buffer.end(), std::back_inserter(remaining_buf)); -- cgit v1.2.3