Browse Source

Enhanced logging

Paul-Louis Ageneau 3 years ago
parent
commit
a2a88b1eed
2 changed files with 18 additions and 12 deletions
  1. 14 8
      src/impl/pollservice.cpp
  2. 4 4
      src/impl/wshandshake.cpp

+ 14 - 8
src/impl/pollservice.cpp

@@ -173,21 +173,27 @@ void PollService::runLoop() {
 		while (!mStopped) {
 			prepare(pfds, next);
 
-			PLOG_VERBOSE << "Entering poll";
 			int ret;
 			do {
-				int timeout = next ? duration_cast<milliseconds>(
-				                         std::max(clock::duration::zero(), *next - clock::now()))
-				                         .count()
-				                   : -1;
+				int timeout;
+				if (next) {
+					auto msecs = duration_cast<milliseconds>(
+					    std::max(clock::duration::zero(), *next - clock::now()));
+					PLOG_VERBOSE << "Entering poll, timeout=" << msecs.count() << "ms";
+					timeout = msecs.count();
+				} else {
+					PLOG_VERBOSE << "Entering poll";
+					timeout = -1;
+				}
+
 				ret = ::poll(pfds.data(), pfds.size(), timeout);
 
-			} while (ret < 0 && (sockerrno == SEINTR || sockerrno == SEAGAIN));
+				PLOG_VERBOSE << "Exiting poll";
 
-			PLOG_VERBOSE << "Exiting poll";
+			} while (ret < 0 && (sockerrno == SEINTR || sockerrno == SEAGAIN));
 
 			if (ret < 0)
-				throw std::runtime_error("Failed to wait for socket connection");
+				throw std::runtime_error("poll failed, errno=" + std::to_string(sockerrno));
 
 			process(pfds);
 		}

+ 4 - 4
src/impl/wshandshake.cpp

@@ -183,7 +183,7 @@ size_t WsHandshake::parseHttpRequest(const byte *buffer, size_t size) {
 
 	string method, path, protocol;
 	requestLine >> method >> path >> protocol;
-	PLOG_DEBUG << "WebSocket request method \"" << method << "\" for path: " << path;
+	PLOG_DEBUG << "WebSocket request method=\"" << method << "\", path=\"" << path << "\"";
 	if (method != "GET")
 		throw RequestError("Invalid request method \"" + method + "\" for WebSocket", 405);
 
@@ -205,7 +205,7 @@ size_t WsHandshake::parseHttpRequest(const byte *buffer, size_t size) {
 	std::transform(h->second.begin(), h->second.end(), std::back_inserter(upgrade),
 	               [](char c) { return std::tolower(c); });
 	if (upgrade != "websocket")
-		throw RequestError("WebSocket upgrade header mismatching: " + h->second, 426);
+		throw RequestError("WebSocket upgrade header mismatching", 426);
 
 	h = headers.find("sec-websocket-key");
 	if (h == headers.end())
@@ -236,7 +236,7 @@ size_t WsHandshake::parseHttpResponse(const byte *buffer, size_t size) {
 	string protocol;
 	unsigned int code = 0;
 	status >> protocol >> code;
-	PLOG_DEBUG << "WebSocket response code: " << code;
+	PLOG_DEBUG << "WebSocket response code=" << code;
 	if (code != 101)
 		throw std::runtime_error("Unexpected response code " + to_string(code) + " for WebSocket");
 
@@ -250,7 +250,7 @@ size_t WsHandshake::parseHttpResponse(const byte *buffer, size_t size) {
 	std::transform(h->second.begin(), h->second.end(), std::back_inserter(upgrade),
 	               [](char c) { return std::tolower(c); });
 	if (upgrade != "websocket")
-		throw Error("WebSocket update header mismatching: " + h->second);
+		throw Error("WebSocket update header mismatching");
 
 	h = headers.find("sec-websocket-accept");
 	if (h == headers.end())