diff --git a/src/xrt/ipc/server/ipc_server.h b/src/xrt/ipc/server/ipc_server.h index 4e61295af..dd69a7dee 100644 --- a/src/xrt/ipc/server/ipc_server.h +++ b/src/xrt/ipc/server/ipc_server.h @@ -431,11 +431,16 @@ ipc_server_client_destroy_compositor(volatile struct ipc_client_state *ics); * @{ */ /*! - * Start a thread for a client connected at the other end of the ipc handle @p ipc_handle. + * Called when a client has connected, it takes the client's ipc handle. + * Handles all things needed to be done for a client connecting, like starting + * it's thread. + * + * @param vs The IPC server. + * @param ipc_handle Handle to communicate over. * @memberof ipc_server */ void -ipc_server_start_client_listener_thread(struct ipc_server *vs, xrt_ipc_handle_t ipc_handle); +ipc_server_handle_client_connected(struct ipc_server *vs, xrt_ipc_handle_t ipc_handle); /*! * Perform whatever needs to be done when the mainloop polling encounters a failure. diff --git a/src/xrt/ipc/server/ipc_server_mainloop_android.c b/src/xrt/ipc/server/ipc_server_mainloop_android.c index d87080198..ce08cc3d1 100644 --- a/src/xrt/ipc/server/ipc_server_mainloop_android.c +++ b/src/xrt/ipc/server/ipc_server_mainloop_android.c @@ -91,9 +91,14 @@ handle_listen(struct ipc_server *vs, struct ipc_server_mainloop *ml) if (read(ml->pipe_read, &newfd, sizeof(newfd)) == sizeof(newfd)) { // client_push_mutex should prevent dropping acknowledgements assert(ml->last_accepted_fd == 0); + // Release the thread that gave us this fd. ml->last_accepted_fd = newfd; - ipc_server_start_client_listener_thread(vs, newfd); + + // Call into the generic client connected handling code. + ipc_server_handle_client_connected(vs, newfd); + + // If we are waiting to shutdown, wake that thread up. pthread_cond_broadcast(&ml->accept_cond); } else { U_LOG_E("error on pipe read"); diff --git a/src/xrt/ipc/server/ipc_server_mainloop_linux.c b/src/xrt/ipc/server/ipc_server_mainloop_linux.c index 05197b889..e3ef01c59 100644 --- a/src/xrt/ipc/server/ipc_server_mainloop_linux.c +++ b/src/xrt/ipc/server/ipc_server_mainloop_linux.c @@ -211,7 +211,9 @@ handle_listen(struct ipc_server *vs, struct ipc_server_mainloop *ml) ipc_server_handle_failure(vs); return; } - ipc_server_start_client_listener_thread(vs, ret); + + // Call into the generic client connected handling code. + ipc_server_handle_client_connected(vs, ret); } #define NUM_POLL_EVENTS 8 diff --git a/src/xrt/ipc/server/ipc_server_mainloop_windows.cpp b/src/xrt/ipc/server/ipc_server_mainloop_windows.cpp index 7ca0ee928..0766a81df 100644 --- a/src/xrt/ipc/server/ipc_server_mainloop_windows.cpp +++ b/src/xrt/ipc/server/ipc_server_mainloop_windows.cpp @@ -192,7 +192,10 @@ handle_connected_client(struct ipc_server *vs, struct ipc_server_mainloop *ml) bRet = SetNamedPipeHandleState(ml->pipe_handle, &mode, nullptr, nullptr); if (bRet) { - ipc_server_start_client_listener_thread(vs, ml->pipe_handle); + // Call into the generic client connected handling code. + ipc_server_handle_client_connected(vs, ml->pipe_handle); + + // Create another pipe to wait on. create_another_pipe_instance(vs, ml); return; } diff --git a/src/xrt/ipc/server/ipc_server_process.c b/src/xrt/ipc/server/ipc_server_process.c index 4a683cdb7..6bcfa9601 100644 --- a/src/xrt/ipc/server/ipc_server_process.c +++ b/src/xrt/ipc/server/ipc_server_process.c @@ -385,7 +385,7 @@ ipc_server_handle_shutdown_signal(struct ipc_server *vs) } void -ipc_server_start_client_listener_thread(struct ipc_server *vs, xrt_ipc_handle_t ipc_handle) +ipc_server_handle_client_connected(struct ipc_server *vs, xrt_ipc_handle_t ipc_handle) { volatile struct ipc_client_state *ics = NULL; int32_t cs_index = -1;