diff --git a/src/protocols/rdp/client.h b/src/protocols/rdp/client.h index ae7c7c58..d067ac60 100644 --- a/src/protocols/rdp/client.h +++ b/src/protocols/rdp/client.h @@ -51,6 +51,10 @@ #include "rdp_keymap.h" #include "rdp_settings.h" +/** + * The maximum duration of a frame in milliseconds. + */ +#define GUAC_RDP_FRAME_DURATION 30 /** * Client data that will remain accessible through the guac_client. diff --git a/src/protocols/rdp/guac_handlers.c b/src/protocols/rdp/guac_handlers.c index 4ad843ae..2ab885be 100644 --- a/src/protocols/rdp/guac_handlers.c +++ b/src/protocols/rdp/guac_handlers.c @@ -198,8 +198,12 @@ int rdp_guac_client_handle_messages(guac_client* client) { /* Wait for messages */ int wait_result = rdp_guac_client_wait_for_messages(client, 250000); + guac_timestamp frame_start = guac_timestamp_current(); while (wait_result > 0) { + guac_timestamp frame_end; + int frame_remaining; + pthread_mutex_lock(&(guac_client_data->rdp_lock)); /* Check the libfreerdp fds */ @@ -247,9 +251,18 @@ int rdp_guac_client_handle_messages(guac_client* client) { if (guac_client_data->audio != NULL) guac_socket_flush(guac_client_data->audio->stream->socket); - /* Wait again */ pthread_mutex_unlock(&(guac_client_data->rdp_lock)); - wait_result = rdp_guac_client_wait_for_messages(client, 0); + + /* Calculate time remaining in frame */ + frame_end = guac_timestamp_current(); + frame_remaining = frame_start + GUAC_RDP_FRAME_DURATION - frame_end; + + /* Wait again if frame remaining */ + if (frame_remaining > 0) + wait_result = rdp_guac_client_wait_for_messages(client, + frame_remaining*1000); + else + break; } diff --git a/src/protocols/vnc/client.h b/src/protocols/vnc/client.h index 4bf63c8d..6e906b68 100644 --- a/src/protocols/vnc/client.h +++ b/src/protocols/vnc/client.h @@ -44,6 +44,11 @@ #include +/** + * The maximum duration of a frame in milliseconds. + */ +#define GUAC_VNC_FRAME_DURATION 30 + extern char* __GUAC_CLIENT; typedef struct vnc_guac_client_data { diff --git a/src/protocols/vnc/guac_handlers.c b/src/protocols/vnc/guac_handlers.c index 662e5e0f..a66ea7eb 100644 --- a/src/protocols/vnc/guac_handlers.c +++ b/src/protocols/vnc/guac_handlers.c @@ -53,21 +53,31 @@ int vnc_guac_client_handle_messages(guac_client* client) { - int wait_result; rfbClient* rfb_client = ((vnc_guac_client_data*) client->data)->rfb_client; /* Initially wait for messages */ - wait_result = WaitForMessage(rfb_client, 1000000); + int wait_result = WaitForMessage(rfb_client, 1000000); + guac_timestamp frame_start = guac_timestamp_current(); while (wait_result > 0) { + guac_timestamp frame_end; + int frame_remaining; + /* Handle any message received */ if (!HandleRFBServerMessage(rfb_client)) { guac_client_log_error(client, "Error handling VNC server message\n"); return 1; } - /* Check for additional messages */ - wait_result = WaitForMessage(rfb_client, 0); + /* Calculate time remaining in frame */ + frame_end = guac_timestamp_current(); + frame_remaining = frame_start + GUAC_VNC_FRAME_DURATION - frame_end; + + /* Wait again if frame remaining */ + if (frame_remaining > 0) + wait_result = WaitForMessage(rfb_client, frame_remaining*1000); + else + break; }