| 41 | } |
| 42 | |
| 43 | bool ServerThread::start() { |
| 44 | if (mData->mRunning.load()) { |
| 45 | return true; |
| 46 | } |
| 47 | |
| 48 | if (!mData->mServer) { |
| 49 | return false; |
| 50 | } |
| 51 | |
| 52 | mData->mRunning.store(true); |
| 53 | // Pass shared_ptr to data so the thread keeps it alive even if |
| 54 | // the ServerThread object is destroyed before join completes. |
| 55 | mData->mThread = fl::thread(serverThreadFunc, mData); |
| 56 | |
| 57 | // Give the thread time to start |
| 58 | fl::this_thread::sleep_for(fl::chrono::milliseconds(100)); // ok sleep for |
| 59 | |
| 60 | return true; |
| 61 | } |
| 62 | |
| 63 | void ServerThread::stop() { |
| 64 | // Always set running to false and join, even if already false. |