Poco HTTPRequestHandler handleRequest 在多个请求后中止

问题描述 投票:0回答:1

我的服务器基于 HTTPTimeServer。当我尝试登录handleRequest时,我无法向服务器发送多个请求。第二个中止服务器。我认为这是一个多线程问题,因此存在互斥范围,但这没有什么区别。

这似乎是 Poco HTTPTimeServer 的常见模式,也是一个容易陷入的陷阱。我在这里缺少什么?

std::mutex g_log_mutex;

void WifiRequestHandler::handleRequest(HTTPServerRequest& request, HTTPServerResponse& response) {
  string uri = request.getURI();
  string method = request.getMethod();

//
// without this scope I can service responses fine; otherwise I get the following from curl and the server aborts
// curl: (52) Empty reply from server
//
  {
    std::lock_guard<std::mutex> guard(g_log_mutex);
    poco_information(*log_, "stuff");
  }
  
  if (frag_ == "/" && method == "GET") {
    response.setStatusAndReason(HTTPResponse::HTTP_OK);
    response.sendBuffer(NULL, 0);
  } else { 
    response.setStatusAndReason(HTTPResponse::HTTP_NOT_FOUND);
    response.sendBuffer(NULL, 0);
  }
}
poco poco-libraries
1个回答
0
投票

这似乎与我的构建有关。将所有内容转移到另一台机器上并进行重建使我能够正常记录并向服务器发送多个请求。我也静态链接所有内容,但我不明白这怎么会成为问题。

© www.soinside.com 2019 - 2024. All rights reserved.