本文整理汇总了C++中std::iostream::peek方法的典型用法代码示例。如果您正苦于以下问题:C++ iostream::peek方法的具体用法?C++ iostream::peek怎么用?C++ iostream::peek使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类std::iostream
的用法示例。
在下文中一共展示了iostream::peek方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: on_connected
void on_connected(socket& /*socket*/, std::iostream& stream)
{
for (std::size_t keep_alive_count = config_.maximum_keep_alive_requests; keep_alive_count != 0; --keep_alive_count)
{
stream.exceptions(std::ios_base::badbit);
if (stream.peek() == EOF)
{
stream.clear();
break;
}
stream.exceptions(std::ios_base::eofbit | std::ios_base::failbit | std::ios_base::badbit);
http_server_context context(stream, config_);
http_request& req = context.request();
http_response& res = context.response();
bool head = false;
bool keep_alive = false;
try
{
context.read_headers();
switch (req.get_method())
{
case http_method::head:
head = true;
break;
case http_method::get:
case http_method::post:
break;
default:
BOOST_THROW_EXCEPTION(http_exception(http_status_code::method_not_allowed));
}
if (req.is_connection_keep_alive())
{
res.set_keep_alive_requests(keep_alive_count);
keep_alive = true;
}
context.validate_headers();
if (config_.logger)
config_.logger->http_server_request(req);
try
{
switch (req.get_method())
{
case http_method::head:
case http_method::get:
derived().on_get(context, head);
break;
case http_method::post:
derived().on_post(context);
break;
default:
BOOST_THROW_EXCEPTION(http_exception(http_status_code::method_not_allowed));
}
}
catch(http_exception&)
{
throw;
}
catch (interrupted_exception&)
{
throw;
}
catch (std::exception&)
{
BOOST_THROW_EXCEPTION(http_exception(http_status_code::internal_service_error));
}
}
catch (http_exception& e)
{
if (config_.logger)
config_.logger->exception();
res.set_status_code(e.status_code());
try
{
auto it = config_.error_document.find(e.status_code());
if (it != config_.error_document.end())
BOOST_THROW_EXCEPTION(http_exception(http_status_code::not_found));
req.set_path(it->second);
derived().on_get(context, head);
}
catch (http_exception&)
{
null_content().on_get(context, head);
}
}
context.finish_write();
//.........这里部分代码省略.........