Adding locks around guac send instructions to resolve client disconnect issue

This commit is contained in:
Sion Chaudhuri 2013-04-30 01:10:01 -07:00 committed by Michael Jumper
parent ea8feac587
commit bbe552e847

View File

@ -39,6 +39,7 @@
#include <time.h> #include <time.h>
#include <syslog.h> #include <syslog.h>
#include <iconv.h> #include <iconv.h>
#include <pthread.h>
#include <cairo/cairo.h> #include <cairo/cairo.h>
@ -132,9 +133,14 @@ void guac_vnc_cursor(rfbClient* client, int x, int y, int w, int h, int bpp) {
/* Send cursor data*/ /* Send cursor data*/
surface = cairo_image_surface_create_for_data(buffer, CAIRO_FORMAT_ARGB32, w, h, stride); surface = cairo_image_surface_create_for_data(buffer, CAIRO_FORMAT_ARGB32, w, h, stride);
pthread_mutex_lock(&(gc->send_lock));
guac_protocol_send_png(socket, guac_protocol_send_png(socket,
GUAC_COMP_SRC, cursor_layer, 0, 0, surface); GUAC_COMP_SRC, cursor_layer, 0, 0, surface);
pthread_mutex_unlock(&(gc->send_lock));
/* Update cursor */ /* Update cursor */
guac_protocol_send_cursor(socket, x, y, cursor_layer, 0, 0, w, h); guac_protocol_send_cursor(socket, x, y, cursor_layer, 0, 0, w, h);
@ -231,8 +237,13 @@ void guac_vnc_update(rfbClient* client, int x, int y, int w, int h) {
/* For now, only use default layer */ /* For now, only use default layer */
surface = cairo_image_surface_create_for_data(buffer, CAIRO_FORMAT_RGB24, w, h, stride); surface = cairo_image_surface_create_for_data(buffer, CAIRO_FORMAT_RGB24, w, h, stride);
pthread_mutex_lock(&(gc->send_lock));
guac_protocol_send_png(socket, GUAC_COMP_OVER, GUAC_DEFAULT_LAYER, x, y, surface); guac_protocol_send_png(socket, GUAC_COMP_OVER, GUAC_DEFAULT_LAYER, x, y, surface);
pthread_mutex_unlock(&(gc->send_lock));
/* Free surface */ /* Free surface */
cairo_surface_destroy(surface); cairo_surface_destroy(surface);
free(buffer); free(buffer);
@ -244,11 +255,15 @@ void guac_vnc_copyrect(rfbClient* client, int src_x, int src_y, int w, int h, in
guac_client* gc = rfbClientGetClientData(client, __GUAC_CLIENT); guac_client* gc = rfbClientGetClientData(client, __GUAC_CLIENT);
guac_socket* socket = gc->socket; guac_socket* socket = gc->socket;
pthread_mutex_lock(&(gc->send_lock));
/* For now, only use default layer */ /* For now, only use default layer */
guac_protocol_send_copy(socket, guac_protocol_send_copy(socket,
GUAC_DEFAULT_LAYER, src_x, src_y, w, h, GUAC_DEFAULT_LAYER, src_x, src_y, w, h,
GUAC_COMP_OVER, GUAC_DEFAULT_LAYER, dest_x, dest_y); GUAC_COMP_OVER, GUAC_DEFAULT_LAYER, dest_x, dest_y);
pthread_mutex_unlock(&(gc->send_lock));
((vnc_guac_client_data*) gc->data)->copy_rect_used = 1; ((vnc_guac_client_data*) gc->data)->copy_rect_used = 1;
} }
@ -301,10 +316,14 @@ rfbBool guac_vnc_malloc_framebuffer(rfbClient* rfb_client) {
guac_client* gc = rfbClientGetClientData(rfb_client, __GUAC_CLIENT); guac_client* gc = rfbClientGetClientData(rfb_client, __GUAC_CLIENT);
vnc_guac_client_data* guac_client_data = (vnc_guac_client_data*) gc->data; vnc_guac_client_data* guac_client_data = (vnc_guac_client_data*) gc->data;
pthread_mutex_lock(&(gc->send_lock));
/* Send new size */ /* Send new size */
guac_protocol_send_size(gc->socket, guac_protocol_send_size(gc->socket,
GUAC_DEFAULT_LAYER, rfb_client->width, rfb_client->height); GUAC_DEFAULT_LAYER, rfb_client->width, rfb_client->height);
pthread_mutex_unlock(&(gc->send_lock));
/* Use original, wrapped proc */ /* Use original, wrapped proc */
return guac_client_data->rfb_MallocFrameBuffer(rfb_client); return guac_client_data->rfb_MallocFrameBuffer(rfb_client);
} }
@ -317,8 +336,12 @@ void guac_vnc_cut_text(rfbClient* client, const char* text, int textlen) {
/* Convert ASCII character data to UTF-8 */ /* Convert ASCII character data to UTF-8 */
char* utf8_text = convert("ISO_8859-1", "UTF-8", text); char* utf8_text = convert("ISO_8859-1", "UTF-8", text);
pthread_mutex_lock(&(gc->send_lock));
guac_protocol_send_clipboard(socket, utf8_text); guac_protocol_send_clipboard(socket, utf8_text);
pthread_mutex_unlock(&(gc->send_lock));
free(utf8_text); free(utf8_text);
} }