void run_iterator_test() { StreamBuf b; // create a sample data boost::array<char, 20000> sample; std::generate(sample.begin(), sample.end(), make_randgen(boost::as_literal("0123456789"))); std::copy(sample.begin(), sample.begin() + 12000, ybuffers_begin(b.prepare(12000))); b.commit(12000); std::copy(sample.begin() + 12000, sample.begin() + 14000, ybuffers_begin(b.prepare(2000))); b.commit(1000); std::copy(sample.begin() + 13000, sample.begin() + 15000, ybuffers_begin(b.prepare(2000))); b.commit(2000); std::copy(sample.begin() + 15000, sample.begin() + 20000, ybuffers_begin(b.prepare(5000))); b.commit(5000); typename StreamBuf::const_buffers_type bufs = b.data(); assert(boost::equal(boost::make_iterator_range(sample.begin(), sample.end()), boost::make_iterator_range(ybuffers_begin(bufs), ybuffers_end(bufs))) ); assert(ybuffers_end(bufs) - ybuffers_begin(bufs) == 20000); assert(ybuffers_begin(bufs) - ybuffers_end(bufs) == -20000); }
void run_streambuf_test() { StreamBuf b; assert(b.size() == 0); std::size_t q = ystreambuf::chunk_size; assert( size(b.prepare(q-2)) == q-2 ); assert( size(b.prepare(1)) == 1 ); assert( size(b.prepare(q)) == q ); assert( size(b.prepare(q+1)) == q+1 ); assert( size(b.data()) == 0 && 0 == b.size()); b.commit(1); assert( size(b.data()) == 1 && 1 == b.size()); b.commit(q-1); assert( size(b.data()) == q && q == b.size()); b.commit(1); assert( size(b.data()) == q+1 && q+1 == b.size()); b.consume(1); assert( size(b.data()) == q && q == b.size()); b.consume(q-1); assert( size(b.data()) == 1 && 1 == b.size()); assert( size(b.prepare(2*q-1)) == 2*q-1 ); b.consume(1); assert( size(b.data()) == 0 && 0 == b.size()); b.commit(q); assert( size(b.data()) == q && q == b.size()); b.commit(q-1); assert( size(b.data()) == 2*q-1 && 2*q-1 == b.size()); b.consume(2*q-1); assert( size(b.data()) == 0 && 0 == b.size()); }
/// Start an asynchronous read operation. void asyncRead_() { auto connection = this->shared_from_this(); auto handler = std::bind(&Connection<Protocol, IsServer>::handleRead_, this, std::placeholders::_1, std::placeholders::_2); socket_->async_read_some(read_buffer_.prepare(1024), handler); }