diff options
author | Matthias P. Braendli <matthias.braendli@mpb.li> | 2019-08-21 15:18:45 +0200 |
---|---|---|
committer | Matthias P. Braendli <matthias.braendli@mpb.li> | 2019-08-21 15:18:45 +0200 |
commit | bfb88439e160ed2e939c64455d430a28e9903d59 (patch) | |
tree | 1cd296c90a07d965e031c355376654cdfd0b94f8 /src/input | |
parent | 86ea8cd8b8b5af7917db28ae30cfb2d2886868fe (diff) | |
parent | 0993a6f886115d194466d1787b253e35921fd988 (diff) | |
download | dabmux-bfb88439e160ed2e939c64455d430a28e9903d59.tar.gz dabmux-bfb88439e160ed2e939c64455d430a28e9903d59.tar.bz2 dabmux-bfb88439e160ed2e939c64455d430a28e9903d59.zip |
Merge 'MichelDeVittori/master' with nonblock file fix into next
Diffstat (limited to 'src/input')
-rw-r--r-- | src/input/File.cpp | 22 |
1 files changed, 9 insertions, 13 deletions
diff --git a/src/input/File.cpp b/src/input/File.cpp index 54dac1e..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<uint8_t> 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 (buf.size() + 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<uint8_t> remaining_buf; std::copy(m_nonblock_buffer.begin() + size, m_nonblock_buffer.end(), std::back_inserter(remaining_buf)); |