Enhance message queuing with improved error handling and logging in WebSocket server

- Implement detailed logging for message queuing attempts, including message size and copy operations.
- Add comprehensive null checks for user data and message queue validity before pushing messages to the queue.
- Introduce exception handling to manage potential errors during message queuing, improving stability and error visibility.
This commit is contained in:
Torsten Schulz (local)
2025-11-20 17:49:17 +01:00
committed by Torsten (PC)
parent 5ce1cc4e6a
commit 7f65f5e40e

View File

@@ -411,8 +411,37 @@ int WebSocketServer::wsCallback(struct lws *wsi,
break; break;
} }
udCopy->messageQueue.push(messageToQueue); // Versuche, die Nachricht zur Queue hinzuzufügen
std::cout << "ud->messageQueue.size(): " << udCopy->messageQueue.size() << std::endl; try {
std::cout << "Versuche push() aufzurufen mit Nachricht: " << messageToQueue.length() << " Bytes" << std::endl;
// Erstelle eine Kopie der Nachricht, um sicherzustellen, dass sie gültig ist
std::string msgCopy = messageToQueue;
std::cout << "Nachricht kopiert für push: " << msgCopy.length() << " Bytes" << std::endl;
// Prüfe ob udCopy noch gültig ist
if (!udCopy) {
std::cerr << "[RECEIVE] udCopy ist nullptr vor push()" << std::endl;
break;
}
// Prüfe ob messageQueue noch gültig ist
try {
volatile size_t testSize2 = udCopy->messageQueue.size();
(void)testSize2;
} catch (...) {
std::cerr << "[RECEIVE] messageQueue ist ungültig vor push()" << std::endl;
break;
}
udCopy->messageQueue.push(msgCopy);
std::cout << "push() erfolgreich, neue Größe: " << udCopy->messageQueue.size() << std::endl;
} catch (const std::exception &e) {
std::cerr << "[RECEIVE] Exception beim push(): " << e.what() << std::endl;
break;
} catch (...) {
std::cerr << "[RECEIVE] Unbekannte Exception beim push()" << std::endl;
break;
}
} catch (const std::exception &e) { } catch (const std::exception &e) {
std::cerr << "[RECEIVE] Fehler beim Zugriff auf messageQueue: " << e.what() << std::endl; std::cerr << "[RECEIVE] Fehler beim Zugriff auf messageQueue: " << e.what() << std::endl;
break; break;