diff --git a/src/core/ssl_server.cpp b/src/core/ssl_server.cpp index cd89d31..8474939 100644 --- a/src/core/ssl_server.cpp +++ b/src/core/ssl_server.cpp @@ -47,7 +47,13 @@ SSLServer::~SSLServer() { void SSLServer::run() { _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(); }); } @@ -109,9 +115,13 @@ void SSLServer::startServer() { _context = lws_create_context(&info); 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) { // Use a shorter timeout to be more responsive to shutdown int ret = lws_service(_context, 10); diff --git a/src/main.cpp b/src/main.cpp index 479b6c6..da3c51f 100755 --- a/src/main.cpp +++ b/src/main.cpp @@ -45,6 +45,9 @@ int main(int, char **) { g_sslServer = std::make_shared(config, database); g_sslServer->createRooms(); g_sslServer->run(); + + // Give the SSL server a moment to initialize + std::this_thread::sleep_for(std::chrono::milliseconds(100)); } else { std::cout << "[YourChat] Starting without SSL/TLS support" << std::endl; g_server = std::make_shared(config, database);