summaryrefslogtreecommitdiff
path: root/src/buffer.cc
diff options
context:
space:
mode:
authorJoel Klinghed <the_jk@yahoo.com>2017-03-16 23:28:09 +0100
committerJoel Klinghed <the_jk@yahoo.com>2017-03-16 23:38:19 +0100
commit87774d8981ae7a079492d8949e205065ba72a8e4 (patch)
treef056ffbdfb436143db1d968ffc7c82b1cb3d79a3 /src/buffer.cc
parent719d90a40e83e870be19f8d46cc55caed618aa35 (diff)
Add basic console monitor and implement monitor support
Diffstat (limited to 'src/buffer.cc')
-rw-r--r--src/buffer.cc11
1 files changed, 10 insertions, 1 deletions
diff --git a/src/buffer.cc b/src/buffer.cc
index d0c5fbb..4bde195 100644
--- a/src/buffer.cc
+++ b/src/buffer.cc
@@ -12,7 +12,8 @@ namespace {
class BufferImpl : public Buffer {
public:
BufferImpl(size_t capacity, size_t min_avail)
- : capacity_(capacity), min_avail_(min_avail) {
+ : capacity_(capacity), min_avail_(
+ std::max(min_avail, static_cast<size_t>(1))) {
data_ = capacity_ > 0 ?
reinterpret_cast<char*>(malloc(capacity_)) : nullptr;
end_ = data_;
@@ -117,3 +118,11 @@ void Buffer::write(void const* data, size_t size) {
}
}
+void Buffer::clear() {
+ while (true) {
+ size_t avail;
+ read_ptr(&avail);
+ if (avail == 0) return;
+ consume(avail);
+ }
+}