···368368 // Should we exit when a client disconnects.
369369 bool exit_on_disconnect;
370370371371+ // Should we exit when no clients are connected.
372372+ bool exit_when_idle;
373373+371374 enum u_logging_level log_level;
372375373376 struct ipc_thread threads[IPC_MAX_CLIENTS];
···381384 {
382385 int active_client_index;
383386 int last_active_client_index;
387387+388388+ // Counter for total number of connected clients
389389+ uint32_t connected_client_count;
384390385391 struct os_mutex lock;
386392 } global_state;
+8
src/xrt/ipc/server/ipc_server_per_client_thread.c
···5151 ics->server_thread_index = -1;
5252 memset((void *)&ics->client_state, 0, sizeof(struct ipc_app_state));
53535454+ // Decrement the connected client counter
5555+ ics->server->global_state.connected_client_count--;
5656+5457 os_mutex_unlock(&ics->server->global_state.lock);
55585659···114117115118 // Should we stop the server when a client disconnects?
116119 if (ics->server->exit_on_disconnect) {
120120+ ics->server->running = false;
121121+ }
122122+123123+ // Should we stop the server when all clients disconnect?
124124+ if (ics->server->exit_when_idle && ics->server->global_state.connected_client_count == 0) {
117125 ics->server->running = false;
118126 }
119127
+7
src/xrt/ipc/server/ipc_server_process.c
···5656 */
57575858DEBUG_GET_ONCE_BOOL_OPTION(exit_on_disconnect, "IPC_EXIT_ON_DISCONNECT", false)
5959+DEBUG_GET_ONCE_BOOL_OPTION(exit_when_idle, "IPC_EXIT_ON_IDLE", false)
5960DEBUG_GET_ONCE_LOG_OPTION(ipc_log, "IPC_LOG", U_LOGGING_INFO)
60616162···453454454455 s->global_state.active_client_index = -1; // we start off with no active client.
455456 s->global_state.last_active_client_index = -1;
457457+ s->global_state.connected_client_count = 0; // No clients connected initially
456458 s->current_slot_index = 0;
457459458460 for (uint32_t i = 0; i < IPC_MAX_CLIENTS; i++) {
···490492 // Yes we should be running.
491493 s->running = true;
492494 s->exit_on_disconnect = debug_get_bool_option_exit_on_disconnect();
495495+ s->exit_when_idle = debug_get_bool_option_exit_when_idle();
493496494497 xret = xrt_instance_create(NULL, &s->xinst);
495498 if (xret != XRT_SUCCESS) {
···539542 u_var_add_root(s, "IPC Server", false);
540543 u_var_add_log_level(s, &s->log_level, "Log level");
541544 u_var_add_bool(s, &s->exit_on_disconnect, "exit_on_disconnect");
545545+ u_var_add_bool(s, &s->exit_when_idle, "exit_when_idle");
542546 u_var_add_bool(s, (bool *)&s->running, "running");
543547544548 return 0;
···912916 int32_t cs_index = -1;
913917914918 os_mutex_lock(&vs->global_state.lock);
919919+920920+ // Increment the connected client counter
921921+ vs->global_state.connected_client_count++;
915922916923 // find the next free thread in our array (server_thread_index is -1)
917924 // and have it handle this connection