GUACAMOLE-249: Remove lock around usage of FreeRDP (new library appears threadsafe).
This commit is contained in:
parent
ee4d91ea98
commit
a7352b1429
@ -66,9 +66,6 @@ int guac_client_init(guac_client* client, int argc, char** argv) {
|
|||||||
pthread_mutexattr_settype(&(rdp_client->attributes),
|
pthread_mutexattr_settype(&(rdp_client->attributes),
|
||||||
PTHREAD_MUTEX_RECURSIVE);
|
PTHREAD_MUTEX_RECURSIVE);
|
||||||
|
|
||||||
/* Init RDP lock */
|
|
||||||
pthread_mutex_init(&(rdp_client->rdp_lock), &(rdp_client->attributes));
|
|
||||||
|
|
||||||
/* Set handlers */
|
/* Set handlers */
|
||||||
client->join_handler = guac_rdp_user_join_handler;
|
client->join_handler = guac_rdp_user_join_handler;
|
||||||
client->free_handler = guac_rdp_client_free_handler;
|
client->free_handler = guac_rdp_client_free_handler;
|
||||||
|
@ -38,14 +38,10 @@ int guac_rdp_user_mouse_handler(guac_user* user, int x, int y, int mask) {
|
|||||||
guac_client* client = user->client;
|
guac_client* client = user->client;
|
||||||
guac_rdp_client* rdp_client = (guac_rdp_client*) client->data;
|
guac_rdp_client* rdp_client = (guac_rdp_client*) client->data;
|
||||||
|
|
||||||
pthread_mutex_lock(&(rdp_client->rdp_lock));
|
|
||||||
|
|
||||||
/* Skip if not yet connected */
|
/* Skip if not yet connected */
|
||||||
freerdp* rdp_inst = rdp_client->rdp_inst;
|
freerdp* rdp_inst = rdp_client->rdp_inst;
|
||||||
if (rdp_inst == NULL) {
|
if (rdp_inst == NULL)
|
||||||
pthread_mutex_unlock(&(rdp_client->rdp_lock));
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
|
||||||
|
|
||||||
/* Store current mouse location/state */
|
/* Store current mouse location/state */
|
||||||
guac_common_cursor_update(rdp_client->display->cursor, user, x, y, mask);
|
guac_common_cursor_update(rdp_client->display->cursor, user, x, y, mask);
|
||||||
@ -118,8 +114,6 @@ int guac_rdp_user_mouse_handler(guac_user* user, int x, int y, int mask) {
|
|||||||
rdp_client->mouse_button_mask = mask;
|
rdp_client->mouse_button_mask = mask;
|
||||||
}
|
}
|
||||||
|
|
||||||
pthread_mutex_unlock(&(rdp_client->rdp_lock));
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -155,9 +149,7 @@ int guac_rdp_user_size_handler(guac_user* user, int width, int height) {
|
|||||||
height = height * settings->resolution / user->info.optimal_resolution;
|
height = height * settings->resolution / user->info.optimal_resolution;
|
||||||
|
|
||||||
/* Send display update */
|
/* Send display update */
|
||||||
pthread_mutex_lock(&(rdp_client->rdp_lock));
|
|
||||||
guac_rdp_disp_set_size(rdp_client->disp, settings, rdp_inst, width, height);
|
guac_rdp_disp_set_size(rdp_client->disp, settings, rdp_inst, width, height);
|
||||||
pthread_mutex_unlock(&(rdp_client->rdp_lock));
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
@ -102,21 +102,15 @@ static void guac_rdp_send_key_event(guac_rdp_client* rdp_client,
|
|||||||
else
|
else
|
||||||
pressed_flags = KBD_FLAGS_RELEASE;
|
pressed_flags = KBD_FLAGS_RELEASE;
|
||||||
|
|
||||||
pthread_mutex_lock(&(rdp_client->rdp_lock));
|
|
||||||
|
|
||||||
/* Skip if not yet connected */
|
/* Skip if not yet connected */
|
||||||
freerdp* rdp_inst = rdp_client->rdp_inst;
|
freerdp* rdp_inst = rdp_client->rdp_inst;
|
||||||
if (rdp_inst == NULL) {
|
if (rdp_inst == NULL)
|
||||||
pthread_mutex_unlock(&(rdp_client->rdp_lock));
|
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
|
|
||||||
/* Send actual key */
|
/* Send actual key */
|
||||||
rdp_inst->input->KeyboardEvent(rdp_inst->input,
|
rdp_inst->input->KeyboardEvent(rdp_inst->input,
|
||||||
flags | pressed_flags, scancode);
|
flags | pressed_flags, scancode);
|
||||||
|
|
||||||
pthread_mutex_unlock(&(rdp_client->rdp_lock));
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -136,22 +130,16 @@ static void guac_rdp_send_key_event(guac_rdp_client* rdp_client,
|
|||||||
static void guac_rdp_send_unicode_event(guac_rdp_client* rdp_client,
|
static void guac_rdp_send_unicode_event(guac_rdp_client* rdp_client,
|
||||||
int codepoint) {
|
int codepoint) {
|
||||||
|
|
||||||
pthread_mutex_lock(&(rdp_client->rdp_lock));
|
|
||||||
|
|
||||||
/* Skip if not yet connected */
|
/* Skip if not yet connected */
|
||||||
freerdp* rdp_inst = rdp_client->rdp_inst;
|
freerdp* rdp_inst = rdp_client->rdp_inst;
|
||||||
if (rdp_inst == NULL) {
|
if (rdp_inst == NULL)
|
||||||
pthread_mutex_unlock(&(rdp_client->rdp_lock));
|
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
|
|
||||||
/* Send Unicode event */
|
/* Send Unicode event */
|
||||||
rdp_inst->input->UnicodeKeyboardEvent(
|
rdp_inst->input->UnicodeKeyboardEvent(
|
||||||
rdp_inst->input,
|
rdp_inst->input,
|
||||||
0, codepoint);
|
0, codepoint);
|
||||||
|
|
||||||
pthread_mutex_unlock(&(rdp_client->rdp_lock));
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -171,20 +159,14 @@ static void guac_rdp_send_unicode_event(guac_rdp_client* rdp_client,
|
|||||||
static void guac_rdp_send_synchronize_event(guac_rdp_client* rdp_client,
|
static void guac_rdp_send_synchronize_event(guac_rdp_client* rdp_client,
|
||||||
int flags) {
|
int flags) {
|
||||||
|
|
||||||
pthread_mutex_lock(&(rdp_client->rdp_lock));
|
|
||||||
|
|
||||||
/* Skip if not yet connected */
|
/* Skip if not yet connected */
|
||||||
freerdp* rdp_inst = rdp_client->rdp_inst;
|
freerdp* rdp_inst = rdp_client->rdp_inst;
|
||||||
if (rdp_inst == NULL) {
|
if (rdp_inst == NULL)
|
||||||
pthread_mutex_unlock(&(rdp_client->rdp_lock));
|
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
|
|
||||||
/* Synchronize lock key states */
|
/* Synchronize lock key states */
|
||||||
rdp_inst->input->SynchronizeEvent(rdp_inst->input, flags);
|
rdp_inst->input->SynchronizeEvent(rdp_inst->input, flags);
|
||||||
|
|
||||||
pthread_mutex_unlock(&(rdp_client->rdp_lock));
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -405,9 +405,7 @@ static int guac_rdp_handle_connection(guac_client* client) {
|
|||||||
&& !guac_rdp_disp_reconnect_needed(rdp_client->disp)) {
|
&& !guac_rdp_disp_reconnect_needed(rdp_client->disp)) {
|
||||||
|
|
||||||
/* Update remote display size */
|
/* Update remote display size */
|
||||||
pthread_mutex_lock(&(rdp_client->rdp_lock));
|
|
||||||
guac_rdp_disp_update_size(rdp_client->disp, settings, rdp_inst);
|
guac_rdp_disp_update_size(rdp_client->disp, settings, rdp_inst);
|
||||||
pthread_mutex_unlock(&(rdp_client->rdp_lock));
|
|
||||||
|
|
||||||
/* Wait for data and construct a reasonable frame */
|
/* Wait for data and construct a reasonable frame */
|
||||||
int wait_result = rdp_guac_client_wait_for_messages(client,
|
int wait_result = rdp_guac_client_wait_for_messages(client,
|
||||||
@ -423,20 +421,15 @@ static int guac_rdp_handle_connection(guac_client* client) {
|
|||||||
guac_timestamp frame_end;
|
guac_timestamp frame_end;
|
||||||
int frame_remaining;
|
int frame_remaining;
|
||||||
|
|
||||||
pthread_mutex_lock(&(rdp_client->rdp_lock));
|
|
||||||
|
|
||||||
/* Check the libfreerdp fds */
|
/* Check the libfreerdp fds */
|
||||||
if (!freerdp_check_event_handles(rdp_inst->context)) {
|
if (!freerdp_check_event_handles(rdp_inst->context)) {
|
||||||
|
|
||||||
/* Flag connection failure */
|
/* Flag connection failure */
|
||||||
wait_result = -1;
|
wait_result = -1;
|
||||||
pthread_mutex_unlock(&(rdp_client->rdp_lock));
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pthread_mutex_unlock(&(rdp_client->rdp_lock));
|
|
||||||
|
|
||||||
/* Calculate time remaining in frame */
|
/* Calculate time remaining in frame */
|
||||||
frame_end = guac_timestamp_current();
|
frame_end = guac_timestamp_current();
|
||||||
frame_remaining = frame_start + GUAC_RDP_FRAME_DURATION
|
frame_remaining = frame_start + GUAC_RDP_FRAME_DURATION
|
||||||
@ -469,9 +462,7 @@ static int guac_rdp_handle_connection(guac_client* client) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Test whether the RDP server is closing the connection */
|
/* Test whether the RDP server is closing the connection */
|
||||||
pthread_mutex_lock(&(rdp_client->rdp_lock));
|
|
||||||
int connection_closing = freerdp_shall_disconnect(rdp_inst);
|
int connection_closing = freerdp_shall_disconnect(rdp_inst);
|
||||||
pthread_mutex_unlock(&(rdp_client->rdp_lock));
|
|
||||||
|
|
||||||
/* Close connection cleanly if server is disconnecting */
|
/* Close connection cleanly if server is disconnecting */
|
||||||
if (connection_closing)
|
if (connection_closing)
|
||||||
@ -497,8 +488,6 @@ static int guac_rdp_handle_connection(guac_client* client) {
|
|||||||
guac_rdp_print_job_free(rdp_client->active_job);
|
guac_rdp_print_job_free(rdp_client->active_job);
|
||||||
}
|
}
|
||||||
|
|
||||||
pthread_mutex_lock(&(rdp_client->rdp_lock));
|
|
||||||
|
|
||||||
/* Disconnect client and channels */
|
/* Disconnect client and channels */
|
||||||
freerdp_disconnect(rdp_inst);
|
freerdp_disconnect(rdp_inst);
|
||||||
|
|
||||||
@ -521,8 +510,6 @@ static int guac_rdp_handle_connection(guac_client* client) {
|
|||||||
/* Free display */
|
/* Free display */
|
||||||
guac_common_display_free(rdp_client->display);
|
guac_common_display_free(rdp_client->display);
|
||||||
|
|
||||||
pthread_mutex_unlock(&(rdp_client->rdp_lock));
|
|
||||||
|
|
||||||
/* Client is now disconnected */
|
/* Client is now disconnected */
|
||||||
guac_client_log(client, GUAC_LOG_INFO, "Internal RDP client disconnected");
|
guac_client_log(client, GUAC_LOG_INFO, "Internal RDP client disconnected");
|
||||||
|
|
||||||
|
@ -153,13 +153,6 @@ typedef struct guac_rdp_client {
|
|||||||
*/
|
*/
|
||||||
guac_common_list* available_svc;
|
guac_common_list* available_svc;
|
||||||
|
|
||||||
/**
|
|
||||||
* Lock which is locked and unlocked for each RDP message, and for each
|
|
||||||
* part of the RDP client instance which may be dynamically freed and
|
|
||||||
* reallocated during reconnection.
|
|
||||||
*/
|
|
||||||
pthread_mutex_t rdp_lock;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Common attributes for locks.
|
* Common attributes for locks.
|
||||||
*/
|
*/
|
||||||
|
Loading…
Reference in New Issue
Block a user