From 47762889cfc7f626065ae8912bd9c289260e5145 Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Sat, 5 Mar 2011 14:47:02 -0800 Subject: [PATCH] Reinstated ready instruction --- libguac/include/protocol.h | 13 +++++++++++++ libguac/src/client.c | 39 +++++++++++++++++++++++--------------- libguac/src/protocol.c | 4 ++++ 3 files changed, 41 insertions(+), 15 deletions(-) diff --git a/libguac/include/protocol.h b/libguac/include/protocol.h index 6b631ca3..e92c5ee4 100644 --- a/libguac/include/protocol.h +++ b/libguac/include/protocol.h @@ -141,6 +141,19 @@ void guac_send_name(GUACIO* io, const char* name); */ void guac_send_error(GUACIO* io, const char* error); +/** + * Sends a ready instruction over the given GUACIO connection. The + * ready instruction signals the client that the proxy is ready to + * handle server messages, and thus is ready to handle the client's + * ready message. + * + * Normally, this function should not be called by client plugins, + * as the ready instruction will be handled automatically. + * + * @param io The GUACIO connection to use. + */ +void guac_send_ready(GUACIO* io); + /** * Sends a clipboard instruction over the given GUACIO connection. The * clipboard data given will be automatically escaped for transmission. diff --git a/libguac/src/client.c b/libguac/src/client.c index ca32c468..76a436c7 100644 --- a/libguac/src/client.c +++ b/libguac/src/client.c @@ -213,6 +213,11 @@ guac_client* guac_get_client(int client_fd) { } guac_free_instruction_data(&instruction); + + /* Send ready message */ + guac_send_ready(io); + guac_flush(io); + return client; } /* end if connect */ @@ -249,22 +254,9 @@ void guac_start_client(guac_client* client) { guac_instruction instruction; int wait_result; - /* VNC Client Loop */ + /* Client loop */ for (;;) { - /* Handle server messages */ - if (client->handle_messages) { - - int retval = client->handle_messages(client); - if (retval) { - GUAC_LOG_ERROR("Error handling server messages"); - return; - } - - guac_flush(io); - - } - wait_result = guac_instructions_waiting(io); if (wait_result > 0) { @@ -275,7 +267,24 @@ void guac_start_client(guac_client* client) { do { - if (strcmp(instruction.opcode, "mouse") == 0) { + if (strcmp(instruction.opcode, "ready") == 0) { + + /* Handle server messages */ + if (client->handle_messages) { + + int retval = client->handle_messages(client); + if (retval) { + GUAC_LOG_ERROR("Error handling server messages"); + return; + } + + guac_send_ready(io); + guac_flush(io); + + } + + } + else if (strcmp(instruction.opcode, "mouse") == 0) { if (client->mouse_handler) if ( client->mouse_handler( diff --git a/libguac/src/protocol.c b/libguac/src/protocol.c index e942648b..8a79c2c3 100644 --- a/libguac/src/protocol.c +++ b/libguac/src/protocol.c @@ -226,6 +226,10 @@ void guac_send_error(GUACIO* io, const char* error) { } +void guac_send_ready(GUACIO* io) { + guac_write_string(io, "ready;"); +} + void guac_send_copy(GUACIO* io, int srcl, int srcx, int srcy, int w, int h, int dstl, int dstx, int dsty) { guac_write_string(io, "copy:"); guac_write_int(io, srcl);