I based my server off the HTTPTimeServer. The minute I try to log in the handleRequest I can't send the server multiple requests. The second one aborts the server. I thought it was a multi-threading issue hence the mutex scope but that didn't make a difference.
This seems to be a common pattern with the Poco HTTPTimeServer and an easy pitfall. What am I missing here?
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);
}
}
This was related to me saving the log pointer incorrectly. Afaict this works & based on the comments of saving the logger once & reusing it this follows that advice.