boost::asio::streambuf::consume()
및 boost::asio::streambuf::commit()
호출을 이해하려고합니다. 입력 시퀀스에서 문자를 제거하는 consume()
전화 - 워드 프로세서에서, 우리는 예,언제 boost :: asio :: streambuf :: consume() 및 boost :: asio :: streambuf :: commit()을 호출할까요?
boost::asio::streambuf b;
std::ostream os(&b);
os << "Hello, World!\n";
// try sending some data in input sequence
size_t n = sock.send(b.data());
b.consume(n); // sent data is removed from input sequence
및
boost::asio::streambuf b;
// reserve 512 bytes in output sequence
boost::asio::streambuf::mutable_buffers_type bufs = b.prepare(512);
size_t n = sock.receive(bufs);
// received data is "committed" from output sequence to input sequence
b.commit(n);
std::istream is(&b);
std::string s;
is >> s;
나는이 문서가 그들에 대해 말하는 것을 이해 내가만큼이 두 통화를 이해할 수있다 boost::asio::streambuf
안에 있고 boost::asio::streambuf
의 출력 순서에서 입력 순서로 문자를 이동하려면 commit()
으로 전화하십시오. 공정하다.
언제 이 실제로입니까? boost::asio::read_until()
소스를 보면, 우리는 문서가 말한대로, boost::asio::read_until()
가 SyncReadStream
의 read_some()
의 관점에서 구현됩니다, 당신은 그것을 볼 수 있습니다
template <typename SyncReadStream, typename Allocator>
std::size_t read_until(SyncReadStream& s,
boost::asio::basic_streambuf<Allocator>& b, char delim,
boost::system::error_code& ec)
{
std::size_t search_position = 0;
for (;;)
{
// Determine the range of the data to be searched.
typedef typename boost::asio::basic_streambuf<
Allocator>::const_buffers_type const_buffers_type;
typedef boost::asio::buffers_iterator<const_buffers_type> iterator;
const_buffers_type buffers = b.data();
iterator begin = iterator::begin(buffers);
iterator start_pos = begin + search_position;
iterator end = iterator::end(buffers);
// Look for a match.
iterator iter = std::find(start_pos, end, delim);
if (iter != end)
{
// Found a match. We're done.
ec = boost::system::error_code();
return iter - begin + 1;
}
else
{
// No match. Next search can start with the new data.
search_position = end - begin;
}
// Check if buffer is full.
if (b.size() == b.max_size())
{
ec = error::not_found;
return 0;
}
// Need more data.
std::size_t bytes_to_read = read_size_helper(b, 65536);
b.commit(s.read_some(b.prepare(bytes_to_read), ec));
if (ec)
return 0;
}
}
있습니다. 도 boost::asio::read_until()
에서의 문서도 SyncReadStream
에서 '-
SyncReadStream::read_some()
이 어느 이들boost::asio::streambuf::commit()
- 전화 않습니다
boost::asio::streambuf::commit()
boost::asio::read_until()
를 호출하지 않는 것을 말한다 나에게은 문서화되어야하는 것 님의 문서
- 내가
boost::asio::streambuf::commit()
으로 전화해야하는지 여부를 모르겠다. 내 동기 코드와
나는 확실히 내가 무료 기능 boost::asio::read()
및 boost::asio::read_until()
를 호출하고있어하지 않을 때, 그것을 필요로하지 않는 것. 내 처리기의 비동기 코드에 주로 사용 된 예제가 있기 때문에 주로 처리기가 있지만,이 경우 호출하는 것은 확실하지 않습니다. boost::asio::streambuf
을 stringstream
및 std::string
과 함께 사용하려고 시도하면 commit()
이 역할을 수행하지 않는 것 같습니다. streambuf
에 commit()
을 호출하지 않고 중단되거나 멈추는 것이 없습니다.
누구든지 나를 이것을 분류 할 수 있습니까?
이에 대한 구체적인 문서를보고 싶습니다. 나는 아무것도 못 찾는다. – EML