summaryrefslogtreecommitdiff
path: root/src/buffer_utils.cc
diff options
context:
space:
mode:
authorMaxime Coste <frrrwww@gmail.com>2014-08-26 22:11:23 +0100
committerMaxime Coste <frrrwww@gmail.com>2014-08-26 22:11:23 +0100
commit114d33c7f8e9c3fca62449781233dca580b1bc3d (patch)
tree984b58fbd74708869dd43da884ad30b25832f0f0 /src/buffer_utils.cc
parentf96fa66a41088563e11bbaabcca0c0bd21782ca7 (diff)
Limit the iteration count when reading from a fifo
Diffstat (limited to 'src/buffer_utils.cc')
-rw-r--r--src/buffer_utils.cc7
1 files changed, 6 insertions, 1 deletions
diff --git a/src/buffer_utils.cc b/src/buffer_utils.cc
index 020f7b83..19e35552 100644
--- a/src/buffer_utils.cc
+++ b/src/buffer_utils.cc
@@ -85,6 +85,10 @@ Buffer* create_fifo_buffer(String name, int fd, bool scroll)
auto watcher = new FDWatcher(fd, [buffer, scroll](FDWatcher& watcher) {
constexpr size_t buffer_size = 2048;
+ // if we read data slower than it arrives in the fifo, limiting the
+ // iteration number allows us to go back go back to the event loop and
+ // handle other events sources (such as input)
+ size_t loops = 16;
char data[buffer_size];
const int fifo = watcher.fd();
timeval tv{ 0, 0 };
@@ -113,7 +117,8 @@ Buffer* create_fifo_buffer(String name, int fd, bool scroll)
FD_ZERO(&rfds);
FD_SET(fifo, &rfds);
}
- while (count > 0 and select(fifo+1, &rfds, nullptr, nullptr, &tv) == 1);
+ while (--loops and count > 0 and
+ select(fifo+1, &rfds, nullptr, nullptr, &tv) == 1);
if (count <= 0)
{