Verbessere SSLServer-Fehlerbehandlung und füge Verzögerung beim Start hinzu
- Ergänze eine Fehlerbehandlung im SSLServer-Thread, um Ausnahmen zu protokollieren, anstatt sie auszulösen. - Modifiziere die `startServer`-Methode, um bei einem Fehler beim Erstellen des LWS-Kontexts eine Fehlermeldung auszugeben und den Server ordnungsgemäß zu stoppen. - Füge eine Verzögerung von 100 Millisekunden in `main.cpp` hinzu, um dem SSL-Server Zeit zum Initialisieren zu geben.
This commit is contained in:
@@ -47,7 +47,13 @@ SSLServer::~SSLServer() {
|
|||||||
|
|
||||||
void SSLServer::run() {
|
void SSLServer::run() {
|
||||||
_running = true;
|
_running = true;
|
||||||
_serverThread = std::thread([this](){ startServer(); });
|
_serverThread = std::thread([this](){
|
||||||
|
try {
|
||||||
|
startServer();
|
||||||
|
} catch (const std::exception& e) {
|
||||||
|
std::cerr << "[YourChat] SSL Server thread error: " << e.what() << std::endl;
|
||||||
|
}
|
||||||
|
});
|
||||||
_messageThread = std::thread([this](){ processMessageQueue(); });
|
_messageThread = std::thread([this](){ processMessageQueue(); });
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -109,9 +115,13 @@ void SSLServer::startServer() {
|
|||||||
|
|
||||||
_context = lws_create_context(&info);
|
_context = lws_create_context(&info);
|
||||||
if (!_context) {
|
if (!_context) {
|
||||||
throw std::runtime_error("Failed to create LWS context");
|
std::cerr << "[YourChat] Failed to create LWS context" << std::endl;
|
||||||
|
_running = false; // Signal that we failed to start
|
||||||
|
return; // Don't throw, just return gracefully
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::cout << "[YourChat] SSL Server context created successfully" << std::endl;
|
||||||
|
|
||||||
while (_running) {
|
while (_running) {
|
||||||
// Use a shorter timeout to be more responsive to shutdown
|
// Use a shorter timeout to be more responsive to shutdown
|
||||||
int ret = lws_service(_context, 10);
|
int ret = lws_service(_context, 10);
|
||||||
|
|||||||
@@ -45,6 +45,9 @@ int main(int, char **) {
|
|||||||
g_sslServer = std::make_shared<Yc::Lib::SSLServer>(config, database);
|
g_sslServer = std::make_shared<Yc::Lib::SSLServer>(config, database);
|
||||||
g_sslServer->createRooms();
|
g_sslServer->createRooms();
|
||||||
g_sslServer->run();
|
g_sslServer->run();
|
||||||
|
|
||||||
|
// Give the SSL server a moment to initialize
|
||||||
|
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
||||||
} else {
|
} else {
|
||||||
std::cout << "[YourChat] Starting without SSL/TLS support" << std::endl;
|
std::cout << "[YourChat] Starting without SSL/TLS support" << std::endl;
|
||||||
g_server = std::make_shared<Yc::Lib::Server>(config, database);
|
g_server = std::make_shared<Yc::Lib::Server>(config, database);
|
||||||
|
|||||||
Reference in New Issue
Block a user