| 169 | std::atomic_bool _started = {false}; |
| 170 | |
| 171 | Result<Void> startServices() { |
| 172 | std::lock_guard<Mutex> lock(_mutex); |
| 173 | |
| 174 | if (_asioThread != nullptr) { |
| 175 | return Void(); |
| 176 | } |
| 177 | |
| 178 | _started = true; |
| 179 | // Allow io_service to be reused after a previous stop() |
| 180 | _ioService.reset(); |
| 181 | // Use a work guard to keep run() active until handler returns to |
| 182 | // prevent possible deadlock if asio thread exits (eg. error or other thread closure) |
| 183 | // and we post and wait indefinitely for the non-existent thread to complete. |
| 184 | _work = std::make_shared<boost::asio::io_service::work>(_ioService); |
| 185 | |
| 186 | auto threadResult = |
| 187 | Thread::create(STRING_LITERAL("TCP Client"), ThreadQoSClassNormal, [this]() { this->runIOService(); }); |
| 188 | if (!threadResult) { |
| 189 | _work.reset(); |
| 190 | return threadResult.moveError(); |
| 191 | } |
| 192 | _asioThread = threadResult.moveValue(); |
| 193 | return Void(); |
| 194 | } |
| 195 | |
| 196 | void runIOService() { |
| 197 | { |
nothing calls this directly
no test coverage detected