Exemplo n.º 1
0
/**
 * Remove the first n bytes from the buffer
 */
void IOQueue::Pop(unsigned int n) {
  unsigned int bytes_popped = 0;
  BlockVector::iterator iter = m_blocks.begin();
  while (iter != m_blocks.end() && bytes_popped != n) {
    MemoryBlock *block = *iter;
    bytes_popped += block->PopFront(n - bytes_popped);
    if (block->Empty()) {
      m_pool->Release(block);
      iter = m_blocks.erase(iter);
    } else {
      iter++;
    }
  }
}
Exemplo n.º 2
0
/**
 * Remove bytes from the stack
 */
void IOStack::Pop(unsigned int bytes_to_remove) {
    unsigned int bytes_removed = 0;
    BlockVector::iterator iter = m_blocks.begin();
    while (iter != m_blocks.end() && bytes_removed != bytes_to_remove) {
        MemoryBlock *block = *iter;
        bytes_removed += block->PopFront(bytes_to_remove - bytes_removed);
        if (block->Empty()) {
            m_pool->Release(block);
            iter = m_blocks.erase(iter);
        } else {
            iter++;
        }
    }
}
Exemplo n.º 3
0
/**
 * Read up to n bytes into the memory location data and shrink the IOQueue by
 * the amount read.
 */
unsigned int IOQueue::Read(uint8_t *data, unsigned int n) {
  unsigned int bytes_read = 0;
  BlockVector::iterator iter = m_blocks.begin();
  while (iter != m_blocks.end() && bytes_read != n) {
    MemoryBlock *block = *iter;
    unsigned int bytes_copied = block->Copy(data + bytes_read, n - bytes_read);
    block->PopFront(bytes_copied);
    bytes_read += bytes_copied;
    if (block->Empty()) {
      m_pool->Release(block);
      iter = m_blocks.erase(iter);
    } else {
      iter++;
    }
  }
  return bytes_read;
}