当前位置: 首页>>代码示例>>C++>>正文


C++ HttpResponse::IsPeerConnected方法代码示例

本文整理汇总了C++中HttpResponse::IsPeerConnected方法的典型用法代码示例。如果您正苦于以下问题:C++ HttpResponse::IsPeerConnected方法的具体用法?C++ HttpResponse::IsPeerConnected怎么用?C++ HttpResponse::IsPeerConnected使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在HttpResponse的用法示例。


在下文中一共展示了HttpResponse::IsPeerConnected方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: HandleRequest

bool EventsHandler::HandleRequest(const ApiUser::Ptr& user, HttpRequest& request, HttpResponse& response, const Dictionary::Ptr& params)
{
	if (request.RequestUrl->GetPath().size() != 2)
		return false;

	if (request.RequestMethod != "POST")
		return false;

	if (request.ProtocolVersion == HttpVersion10) {
		HttpUtility::SendJsonError(response, 400, "HTTP/1.0 not supported for event streams.");
		return true;
	}

	Array::Ptr types = params->Get("types");

	if (!types) {
		HttpUtility::SendJsonError(response, 400, "'types' query parameter is required.");
		return true;
	}

	{
		ObjectLock olock(types);
		for (const String& type : types) {
			FilterUtility::CheckPermission(user, "events/" + type);
		}
	}

	String queueName = HttpUtility::GetLastParameter(params, "queue");

	if (queueName.IsEmpty()) {
		HttpUtility::SendJsonError(response, 400, "'queue' query parameter is required.");
		return true;
	}

	String filter = HttpUtility::GetLastParameter(params, "filter");

	Expression *ufilter = NULL;

	if (!filter.IsEmpty())
		ufilter = ConfigCompiler::CompileText("<API query>", filter);

	/* create a new queue or update an existing one */
	EventQueue::Ptr queue = EventQueue::GetByName(queueName);

	if (!queue) {
		queue = new EventQueue(queueName);
		EventQueue::Register(queueName, queue);
	}

	queue->SetTypes(types->ToSet<String>());
	queue->SetFilter(ufilter);

	queue->AddClient(&request);

	response.SetStatus(200, "OK");
	response.AddHeader("Content-Type", "application/json");

	for (;;) {
		Dictionary::Ptr result = queue->WaitForEvent(&request);

		if (!response.IsPeerConnected()) {
			queue->RemoveClient(&request);
			EventQueue::UnregisterIfUnused(queueName, queue);
			return true;
		}

		if (!result)
			continue;

		String body = JsonEncode(result);

		boost::algorithm::replace_all(body, "\n", "");

		try {
			response.WriteBody(body.CStr(), body.GetLength());
			response.WriteBody("\n", 1);
		} catch (const std::exception&) {
			queue->RemoveClient(&request);
			EventQueue::UnregisterIfUnused(queueName, queue);
			throw;
		}
	}
}
开发者ID:TheFlyingCorpse,项目名称:icinga2,代码行数:83,代码来源:eventshandler.cpp


注:本文中的HttpResponse::IsPeerConnected方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。