Exemple #1
0
/**
 * Read up to n bytes into the string output.
 */
unsigned int IOStack::Read(string *output, unsigned int length) {
    unsigned int bytes_remaining = length;
    BlockVector::iterator iter = m_blocks.begin();
    while (iter != m_blocks.end() && bytes_remaining) {
        MemoryBlock *block = *iter;
        unsigned int bytes_to_copy = std::min(block->Size(), bytes_remaining);
        output->append(reinterpret_cast<char*>(block->Data()), bytes_to_copy);
        bytes_remaining -= bytes_to_copy;
        if (block->Empty()) {
            m_pool->Release(block);
            iter = m_blocks.erase(iter);
        } else {
            iter++;
        }
    }
    return length - bytes_remaining;
}