additional checks for fd > 0

This commit is contained in:
Denis 2023-12-21 22:55:00 +01:00
parent 6f9a16e694
commit 80331fa85a
No known key found for this signature in database
GPG key ID: DD9B63F805CF5C03

View file

@ -474,7 +474,7 @@ void *dev_out_thread_func(void *ptr) {
const int64_t kbd_time_diff_usecs = get_timediff_usec(&keyboard_last_hid_report_sent, &now); const int64_t kbd_time_diff_usecs = get_timediff_usec(&keyboard_last_hid_report_sent, &now);
gettimeofday(&now, NULL); gettimeofday(&now, NULL);
if (gamepad_time_diff_usecs >= gamepad_report_timing_us) { if ((current_gamepad_fd > 0) && (gamepad_time_diff_usecs >= gamepad_report_timing_us)) {
gamepad_last_hid_report_sent = now; gamepad_last_hid_report_sent = now;
if (current_gamepad == GAMEPAD_DUALSENSE) { if (current_gamepad == GAMEPAD_DUALSENSE) {
@ -487,7 +487,7 @@ void *dev_out_thread_func(void *ptr) {
// this does reset the for, ensuring every other device has nothing to say // this does reset the for, ensuring every other device has nothing to say
continue; continue;
} else if (mouse_time_diff_usecs >= mouse_report_timing_us) { } else if ((current_mouse_fd > 0) && (mouse_time_diff_usecs >= mouse_report_timing_us)) {
mouse_last_hid_report_sent = now; mouse_last_hid_report_sent = now;
virt_mouse_send(&mouse_data, &dev_out_data->dev_stats.mouse, &now); virt_mouse_send(&mouse_data, &dev_out_data->dev_stats.mouse, &now);
@ -498,7 +498,7 @@ void *dev_out_thread_func(void *ptr) {
// this does reset the for, ensuring every other device has nothing to say // this does reset the for, ensuring every other device has nothing to say
continue; continue;
} else if (kbd_time_diff_usecs >= kbd_report_timing_us) { } else if ((current_keyboard_fd > 0) && (kbd_time_diff_usecs >= kbd_report_timing_us)) {
keyboard_last_hid_report_sent = now; keyboard_last_hid_report_sent = now;
virt_kbd_send(&keyboard_data, &dev_out_data->dev_stats.kbd, &now); virt_kbd_send(&keyboard_data, &dev_out_data->dev_stats.kbd, &now);
@ -689,17 +689,23 @@ void *dev_out_thread_func(void *ptr) {
} }
// close the gamepad output device // close the gamepad output device
if (current_gamepad_fd > 0) {
if (current_gamepad == GAMEPAD_DUALSENSE) { if (current_gamepad == GAMEPAD_DUALSENSE) {
virt_dualsense_close(&controller_data.ds5); virt_dualsense_close(&controller_data.ds5);
} else if (current_gamepad == GAMEPAD_DUALSHOCK) { } else if (current_gamepad == GAMEPAD_DUALSHOCK) {
virt_dualshock_close(&controller_data.ds4); virt_dualshock_close(&controller_data.ds4);
} }
}
// close the mouse device // close the mouse device
if (current_mouse_fd > 0) {
virt_mouse_close(&mouse_data); virt_mouse_close(&mouse_data);
}
// close the keyboard device // close the keyboard device
if (current_keyboard_fd > 0) {
virt_kbd_close(&keyboard_data); virt_kbd_close(&keyboard_data);
}
// end communication // end communication
if (dev_out_data->communication.type == ipc_server_sockets) { if (dev_out_data->communication.type == ipc_server_sockets) {