diff --git a/guacamole/proxy/client.c b/guacamole/proxy/client.c index 253eb4d33..0a6b37d81 100644 --- a/guacamole/proxy/client.c +++ b/guacamole/proxy/client.c @@ -78,6 +78,7 @@ void guac_free_client(guac_client* client) { void guac_start_client(guac_client* client) { + guac_instruction instruction; GUACIO* io = client->io; int wait_result; @@ -93,36 +94,42 @@ void guac_start_client(guac_client* client) { wait_result = guac_instructions_waiting(io); if (wait_result > 0) { - guac_instruction* instruction; - - if ((instruction = guac_read_instruction(io))) { + int retval; + retval = guac_read_instruction(io, &instruction); /* 0 if no instructions finished yet, <0 if error or EOF */ + if (retval > 0) { + do { - if (strcmp(instruction->opcode, "mouse") == 0) { + + if (strcmp(instruction.opcode, "mouse") == 0) { if (client->mouse_handler) client->mouse_handler( client, - atoi(instruction->argv[0]), /* x */ - atoi(instruction->argv[1]), /* y */ - atoi(instruction->argv[2]) /* mask */ + atoi(instruction.argv[0]), /* x */ + atoi(instruction.argv[1]), /* y */ + atoi(instruction.argv[2]) /* mask */ ); } - else if (strcmp(instruction->opcode, "key") == 0) { + else if (strcmp(instruction.opcode, "key") == 0) { if (client->key_handler) client->key_handler( client, - atoi(instruction->argv[0]), /* keysym */ - atoi(instruction->argv[1]) /* pressed */ + atoi(instruction.argv[0]), /* keysym */ + atoi(instruction.argv[1]) /* pressed */ ); } - guac_free_instruction(instruction); - } while ((instruction = guac_read_instruction(io))); + } while ((retval = guac_read_instruction(io, &instruction)) > 0); + if (retval < 0) + return; } - else - return; + + if (retval < 0) + return; /* EOF or error */ + + /* Otherwise, retval == 0 implies unfinished instruction */ } else if (wait_result < 0) diff --git a/guacamole/proxy/protocol.c b/guacamole/proxy/protocol.c index 89bee60c8..a091f51a1 100644 --- a/guacamole/proxy/protocol.c +++ b/guacamole/proxy/protocol.c @@ -290,9 +290,8 @@ int __guac_fill_instructionbuf(GUACIO* io) { } /* Returns new instruction if one exists, or NULL if no more instructions. */ -guac_instruction* guac_read_instruction(GUACIO* io) { +int guac_read_instruction(GUACIO* io, guac_instruction* parsed_instruction) { - guac_instruction* parsed_instruction; int retval; int i = 0; int argcount = 0; @@ -319,7 +318,6 @@ guac_instruction* guac_read_instruction(GUACIO* io) { memcpy(instruction, io->instructionbuf, i+1); instruction[i] = '\0'; /* Replace semicolon with null terminator. */ - parsed_instruction = malloc(sizeof(guac_instruction)); parsed_instruction->opcode = NULL; parsed_instruction->argc = argcount; @@ -350,19 +348,22 @@ guac_instruction* guac_read_instruction(GUACIO* io) { io->instructionbuf_used_length -= i + 1; /* Done */ - return parsed_instruction; + return 1; } } /* No instruction yet? Get more data ... */ - while ((retval = guac_select(io, 2500000)) == 0); - if (retval < 0) - return NULL; /* If error, no more instructions */ + retval = guac_select(io, 1000); + if (retval <= 0) + return retval; retval = __guac_fill_instructionbuf(io); - if (retval <= 0) - return NULL; /* If error, or no more data, no instructions remain */ + if (retval < 0) + return retval; + + if (retval == 0) + return -1; /* EOF */ } } diff --git a/guacamole/proxy/protocol.h b/guacamole/proxy/protocol.h index dcfc3055a..798eaa571 100644 --- a/guacamole/proxy/protocol.h +++ b/guacamole/proxy/protocol.h @@ -43,7 +43,7 @@ void guac_send_png(GUACIO* io, int x, int y, png_byte** png_rows, int w, int h); void guac_send_cursor(GUACIO* io, int x, int y, png_byte** png_rows, int w, int h); int guac_instructions_waiting(GUACIO* io); -guac_instruction* guac_read_instruction(GUACIO* io); +int guac_read_instruction(GUACIO* io, guac_instruction* parsed_instruction); #endif diff --git a/guacamole/proxy/vnc_client.c b/guacamole/proxy/vnc_client.c index 683eb1ff3..ab4c441fe 100644 --- a/guacamole/proxy/vnc_client.c +++ b/guacamole/proxy/vnc_client.c @@ -241,7 +241,7 @@ void vnc_guac_client_init(guac_client* client, const char* hostname, int port) { /* Framebuffer update handler */ rfb_client->GotFrameBufferUpdate = guac_vnc_update; - rfb_client->GotCopyRect = guac_vnc_copyrect; + /*rfb_client->GotCopyRect = guac_vnc_copyrect;*/ /* Enable client-side cursor */ rfb_client->GotCursorShape = guac_vnc_cursor;