From 1043fd1d7d1f4f732d4c4bac5be1924692bf6f31 Mon Sep 17 00:00:00 2001 From: Michel De Vittori Date: Fri, 19 Jul 2019 11:10:40 +0200 Subject: Update File.cpp (cherry picked from commit e1cc67c13c63b7ad894687f8f23863a737fef30f) --- src/input/File.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 3b9939c2528502e78b8433a80e0fa0736e278569 Mon Sep 17 00:00:00 2001 From: Michel De Vittori Date: Mon, 22 Jul 2019 17:26:23 +0200 Subject: Update File.cpp (cherry picked from commit 0993a6f886115d194466d1787b253e35921fd988) --- src/input/File.cpp | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) 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 From 2441cc2dfff9aa0fe995ada8be0222ca37c7882c Mon Sep 17 00:00:00 2001 From: "Matthias P. Braendli" Date: Wed, 21 Aug 2019 15:34:35 +0200 Subject: Simplify nonblocking File input (cherry picked from commit 1ce18aa61b14ae5201d70cdf07be62183e18de67) --- src/input/File.cpp | 37 ++++++++++++++++++++----------------- 1 file changed, 20 insertions(+), 17 deletions(-) diff --git a/src/input/File.cpp b/src/input/File.cpp index 5d25f49..20036ae 100644 --- a/src/input/File.cpp +++ b/src/input/File.cpp @@ -2,7 +2,7 @@ Copyright (C) 2009 Her Majesty the Queen in Right of Canada (Communications Research Center Canada) - Copyright (C) 2018 Matthias P. Braendli + Copyright (C) 2019 Matthias P. Braendli http://www.opendigitalradio.org */ @@ -105,12 +105,13 @@ int FileBase::rewind() ssize_t FileBase::readFromFile(uint8_t* buffer, size_t size) { + using namespace std; + ssize_t ret = 0; if (m_nonblock) { if (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); + const size_t required_len = size - m_nonblock_buffer.size(); + vector buf(required_len); ret = read(m_fd, buf.data(), required_len); /* If no process has the pipe open for writing, read() shall return 0 @@ -128,23 +129,25 @@ ssize_t FileBase::readFromFile(uint8_t* buffer, size_t size) etiLog.level(alert) << "ERROR: Can't read file " << strerror(errno); return -1; } - - 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; + + // read() might read less data than requested + buf.resize(ret); + + copy(buf.begin(), buf.end(), back_inserter(m_nonblock_buffer)); } - else { - 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)); - m_nonblock_buffer = std::move(remaining_buf); + if (m_nonblock_buffer.size() >= size) { + copy(m_nonblock_buffer.begin(), m_nonblock_buffer.begin() + size, buffer); + + vector remaining_buf; + copy(m_nonblock_buffer.begin() + size, m_nonblock_buffer.end(), back_inserter(remaining_buf)); + m_nonblock_buffer = move(remaining_buf); + return size; } - return 0; + else { + return 0; + } } else { ret = read(m_fd, buffer, size); -- cgit v1.2.3 From fae852391354752e1fe73a7ee14503b77a53943a Mon Sep 17 00:00:00 2001 From: "Matthias P. Braendli" Date: Fri, 20 Dec 2019 11:21:44 +0100 Subject: Prepare v2.4.2 This is a special release that backports a fix that went into v3 back onto v2.4.1. --- ChangeLog | 4 ++++ configure.ac | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 307023f..b71d0af 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,6 +1,10 @@ This file contains information about the changes done to ODR-DabMux in this repository +2019-12-20: Matthias P. Braendli + (v2.4.2): + Backport the file input nonblock fix to v2.4.1. + 2019-06-25: Matthias P. Braendli (v2.4.1): Fix bug when odr-zmq2edi is used with more than one destination. diff --git a/configure.ac b/configure.ac index 50623a2..9974f1f 100644 --- a/configure.ac +++ b/configure.ac @@ -19,7 +19,7 @@ # along with ODR-DabMux. If not, see . AC_PREREQ(2.69) -AC_INIT([ODR-DabMux], [2.4.1], [matthias.braendli@mpb.li]) +AC_INIT([ODR-DabMux], [2.4.2], [matthias.braendli@mpb.li]) AC_CONFIG_AUX_DIR([build-aux]) AC_CONFIG_MACRO_DIR([m4]) AC_CANONICAL_SYSTEM -- cgit v1.2.3