diff --git a/libguac/include/protocol.h b/libguac/include/protocol.h index e59167f1..92d93ac9 100644 --- a/libguac/include/protocol.h +++ b/libguac/include/protocol.h @@ -123,6 +123,20 @@ 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 merely signals the client that its ready + * instruction has been handled. The ready exchange is intended to + * synchronize instruction handling (if needed) and serve as a health + * indicator for both client and server. + * + * Normally, this functino 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 fa4cf16d..647ddc96 100644 --- a/libguac/src/client.c +++ b/libguac/src/client.c @@ -236,18 +236,6 @@ void guac_start_client(guac_client* client) { /* VNC Client Loop */ for (;;) { - /* Handle server messages */ - if (client->handle_messages) { - - int retval = client->handle_messages(client); - if (retval) { - syslog(LOG_ERR, "Error handling server messages"); - return; - } - - guac_flush(io); - } - wait_result = guac_instructions_waiting(io); if (wait_result > 0) { @@ -258,7 +246,25 @@ 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) { + syslog(LOG_ERR, "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 4d3110e6..f4c6c2f5 100644 --- a/libguac/src/protocol.c +++ b/libguac/src/protocol.c @@ -175,6 +175,10 @@ void guac_send_size(GUACIO* io, int w, int h) { guac_write_string(io, ";"); } +void guac_send_ready(GUACIO* io) { + guac_write_string(io, "ready;"); +} + void guac_send_clipboard(GUACIO* io, const char* data) { char* escaped = guac_escape_string(data);