| 325 | } |
| 326 | |
| 327 | void ConsoleServer::shutdown() |
| 328 | { |
| 329 | if (!_server.is_open()) |
| 330 | return; |
| 331 | |
| 332 | _output_mutex.lock(); |
| 333 | _thread_exit.store(true); |
| 334 | _output_condition.signal(); |
| 335 | _output_mutex.unlock(); |
| 336 | |
| 337 | // Unlock input thread if it is stuck inside the select(). |
| 338 | _handlers_semaphore.post(); |
| 339 | if (_input_thread.is_running()) |
| 340 | _input_thread.stop(); |
| 341 | |
| 342 | // Unlock execute_message_handlers in sync mode. |
| 343 | _input_semaphore.post(); |
| 344 | |
| 345 | if (_output_thread.is_running()) |
| 346 | _output_thread.stop(); |
| 347 | |
| 348 | ScopedMutex scoped_mutex(_clients_mutex); |
| 349 | for (u32 i = 0; i < vector::size(_clients); ++i) |
| 350 | _clients[i].socket.close(); |
| 351 | |
| 352 | _server.close(); |
| 353 | } |
| 354 | |
| 355 | void ConsoleServer::send(u32 client_id, const char *json) |
| 356 | { |