Commit 55f8bee0 authored by Matthias Vallentin's avatar Matthias Vallentin

Make pubsync() reset the get area

parent 8933b78f
......@@ -268,7 +268,8 @@ public:
// We use a const_cast because C++11 doesn't provide a non-const data()
// overload. Using std::data(c) would be the right way to write this.
auto data = const_cast<char_type*>(c.data());
setbuf(data, static_cast<std::streamsize>(c.size()));
auto size = static_cast<std::streamsize>(c.size());
setbuf(data, size);
}
// See note in arraybuf(arraybuf&&).
......@@ -331,6 +332,15 @@ protected:
return this->default_seekoff(off, dir, which);
}
// Synchronizes the get area with the underlying buffer.
int sync() override {
// See note in ctor for const_cast
auto data = const_cast<char_type*>(container_.data());
auto size = static_cast<std::streamsize>(container_.size());
setbuf(data, size);
return 0;
}
// -- get area -------------------------------------------------------------
// We can't get obtain more characters on underflow, so we only optimize
......
......@@ -141,4 +141,9 @@ CAF_TEST(containerbuf_reset_get_area) {
n = vb.sgetn(bar, 3);
CAF_CHECK_EQUAL(n, 3);
CAF_CHECK_EQUAL(std::string(bar, 3), "bar");
// Synchronize the get area after having messed with the underlying buffer.
buf.resize(1);
CAF_CHECK_EQUAL(vb.pubsync(), 0);
CAF_CHECK_EQUAL(vb.sbumpc(), 'f');
CAF_CHECK_EQUAL(vb.in_avail(), 0);
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment