Improved termination code

This commit is contained in:
Denis 2023-12-13 15:48:55 +01:00
parent 07ba1a4903
commit 9774abdebf
No known key found for this signature in database
GPG key ID: DD9B63F805CF5C03
2 changed files with 36 additions and 7 deletions

View file

@ -520,6 +520,25 @@ void* dev_in_thread_func(void *ptr) {
}
}
// end communication
if (dev_in_data->communication.type == ipc_server_sockets) {
// close every client socket
if (pthread_mutex_lock(&dev_in_data->communication.endpoint.ssocket.mutex) == 0) {
for (int i = 0; i < MAX_CONNECTED_CLIENTS; ++i) {
close(dev_in_data->communication.endpoint.ssocket.clients[i]);
dev_in_data->communication.endpoint.ssocket.clients[i] = -1;
}
pthread_mutex_unlock(&dev_in_data->communication.endpoint.ssocket.mutex);
}
} else if (dev_in_data->communication.type == ipc_unix_pipe) {
close(dev_in_data->communication.endpoint.pipe.in_message_pipe_fd);
close(dev_in_data->communication.endpoint.pipe.out_message_pipe_fd);
} else if (dev_in_data->communication.type == ipc_client_socket) {
close(dev_in_data->communication.endpoint.socket.fd);
dev_in_data->communication.endpoint.socket.fd = -1;
}
// close every opened device
for (size_t i = 0; i < max_devices; ++i) {
if (devices[i].type == DEV_IN_TYPE_EV) {

View file

@ -1,6 +1,7 @@
#include "dev_out.h"
#include "devices_status.h"
#include "ipc.h"
#include "message.h"
#include "virt_ds4.h"
#include "virt_ds5.h"
@ -378,7 +379,9 @@ void *dev_out_thread_func(void *ptr) {
virt_dualshock_close(&controller_data.ds4);
}
// close every thread
// end communication
if (dev_out_data->communication.type == ipc_server_sockets) {
// close every client socket
if (pthread_mutex_lock(&dev_out_data->communication.endpoint.ssocket.mutex) == 0) {
for (int i = 0; i < MAX_CONNECTED_CLIENTS; ++i) {
close(dev_out_data->communication.endpoint.ssocket.clients[i]);
@ -387,6 +390,13 @@ void *dev_out_thread_func(void *ptr) {
pthread_mutex_unlock(&dev_out_data->communication.endpoint.ssocket.mutex);
}
} else if (dev_out_data->communication.type == ipc_unix_pipe) {
close(dev_out_data->communication.endpoint.pipe.in_message_pipe_fd);
close(dev_out_data->communication.endpoint.pipe.out_message_pipe_fd);
} else if (dev_out_data->communication.type == ipc_client_socket) {
close(dev_out_data->communication.endpoint.socket.fd);
dev_out_data->communication.endpoint.socket.fd = -1;
}
return NULL;
}