本文整理汇总了C++中http_parser::incoming方法的典型用法代码示例。如果您正苦于以下问题:C++ http_parser::incoming方法的具体用法?C++ http_parser::incoming怎么用?C++ http_parser::incoming使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类http_parser
的用法示例。
在下文中一共展示了http_parser::incoming方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: ret
// TODO: 3 use span here instead of zero-terminated string
std::tuple<int, int, bool> feed_bytes(http_parser& parser, char const* str)
{
std::tuple<int, int, bool> ret(0, 0, false);
std::tuple<int, int, bool> prev(0, 0, false);
for (int chunks = 1; chunks < 70; ++chunks)
{
ret = std::make_tuple(0, 0, false);
parser.reset();
span<char const> recv_buf(str, 0);
for (;;)
{
int chunk_size = (std::min)(chunks, int(strlen(recv_buf.end())));
if (chunk_size == 0) break;
recv_buf = span<char const>(recv_buf.data(), recv_buf.size() + chunk_size);
int payload, protocol;
bool error = false;
std::tie(payload, protocol) = parser.incoming(recv_buf, error);
std::get<0>(ret) += payload;
std::get<1>(ret) += protocol;
std::get<2>(ret) |= error;
// std::cerr << payload << ", " << protocol << ", " << chunk_size << std::endl;
TORRENT_ASSERT(payload + protocol == chunk_size || std::get<2>(ret));
}
TEST_CHECK(prev == std::make_tuple(0, 0, false) || ret == prev || std::get<2>(ret));
if (!std::get<2>(ret))
{
TEST_EQUAL(std::get<0>(ret) + std::get<1>(ret), int(strlen(str)));
}
prev = ret;
}
return ret;
}
示例2: recv_buf
tuple<int, int, bool> feed_bytes(http_parser& parser, char const* str)
{
tuple<int, int, bool> ret(0, 0, false);
tuple<int, int, bool> prev(0, 0, false);
for (int chunks = 1; chunks < 70; ++chunks)
{
ret = make_tuple(0, 0, false);
parser.reset();
buffer::const_interval recv_buf(str, str);
for (; *str;)
{
int chunk_size = (std::min)(chunks, int(strlen(recv_buf.end)));
if (chunk_size == 0) break;
recv_buf.end += chunk_size;
int payload, protocol;
bool error = false;
tie(payload, protocol) = parser.incoming(recv_buf, error);
ret.get<0>() += payload;
ret.get<1>() += protocol;
ret.get<2>() += error;
// std::cerr << payload << ", " << protocol << ", " << chunk_size << std::endl;
TORRENT_ASSERT(payload + protocol == chunk_size);
}
TEST_CHECK(prev == make_tuple(0, 0, false) || ret == prev);
prev = ret;
}
return ret;
}