more test utils

This commit is contained in:
Michael Davidsaver
2019-11-26 17:53:41 -08:00
parent 4c60d72f9c
commit dd4da5d6d5
5 changed files with 55 additions and 5 deletions
+10
View File
@@ -337,6 +337,7 @@ bool EvOutBuf::refill(size_t more)
bool EvInBuf::refill(size_t more)
{
if(err) return false;
size_t len = size(); // unconsumed before request
if(base && evbuffer_drain(backing, pos-base))
throw std::bad_alloc();
@@ -344,8 +345,13 @@ bool EvInBuf::refill(size_t more)
limit = base = pos = nullptr;
if(more) {
// ensure new segment contains at least the requested size (one element)
// (we hope this is mostly a no-op)
(void)evbuffer_pullup(backing, len+more);
evbuffer_iovec vec;
// peek at the next segment
auto n = evbuffer_peek(backing, -1, nullptr, &vec, 1);
if(n<=0) { // current (2.1) impl never returns negative
return false;
@@ -353,6 +359,10 @@ bool EvInBuf::refill(size_t more)
base = pos = (uint8_t*)vec.iov_base;
limit = base+vec.iov_len;
if(size() < len+more) {
return false; // pullup didn't work.
}
}
return true;
}