void SenderImpl::waitForCapacity() { //TODO: add option to throw exception rather than blocking? if (capacity <= (flushed ? checkPendingSends(false) : outgoing.size())) { //Initial implementation is very basic. As outgoing is //currently only reduced on receiving completions and we are //blocking anyway we may as well sync(). If successful that //should clear all outstanding sends. session.sync(); checkPendingSends(false); } //flush periodically and check for conmpleted sends if (++window > (capacity / 4)) {//TODO: make this configurable? checkPendingSends(true); window = 0; } }
uint32_t SenderImpl::checkPendingSends(bool flush) { sys::Mutex::ScopedLock l(lock); return checkPendingSends(flush, l); }