Enhance error response handling in WebSocket server
- Add detailed logging for error responses during WebSocket callbacks, improving visibility into the error handling process. - Ensure that error responses are queued correctly without immediate sending, enhancing stability during callback execution. - Utilize lws_cancel_service to notify the service of pending messages, ensuring proper message delivery after error handling.
This commit is contained in:
committed by
Torsten (PC)
parent
2d3d120f81
commit
bb81126cd8
@@ -325,21 +325,26 @@ int WebSocketServer::wsCallback(struct lws *wsi,
|
||||
// Sende Fehlerantwort nicht während des Callbacks, sondern lege sie in die Queue
|
||||
// und triggere den WRITEABLE-Callback später
|
||||
try {
|
||||
std::cout << "[RECEIVE] getConnections: make response" << std::endl;
|
||||
json errorResponse = {
|
||||
{"event", "getConnectionsResponse"},
|
||||
{"success", false},
|
||||
{"error", "User-ID nicht gesetzt"}
|
||||
};
|
||||
std::cout << "errorResponse: " << errorResponse.dump() << std::endl;
|
||||
if (instance && wsi && ud) {
|
||||
std::cout << "instance: " << instance << std::endl;
|
||||
// Lege Nachricht in die Queue, ohne sofort lws_callback_on_writable aufzurufen
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(ud->messageQueueMutex);
|
||||
ud->messageQueue.push(errorResponse.dump());
|
||||
}
|
||||
std::cout << "ud->messageQueue.size(): " << ud->messageQueue.size() << std::endl;
|
||||
// Verwende lws_cancel_service, um den Service zu benachrichtigen
|
||||
if (instance->context) {
|
||||
lws_cancel_service(instance->context);
|
||||
}
|
||||
std::cout << "lws_cancel_service(instance->context) done" << std::endl;
|
||||
}
|
||||
} catch (const std::exception &e) {
|
||||
std::cerr << "[RECEIVE] Fehler beim Senden der Fehlerantwort: " << e.what() << std::endl;
|
||||
|
||||
Reference in New Issue
Block a user