diff --git a/guacamole/proxy/Makefile b/guacamole/proxy/Makefile index aea65d8b4..9145ad73f 100644 --- a/guacamole/proxy/Makefile +++ b/guacamole/proxy/Makefile @@ -1,5 +1,5 @@ -CFLAGS=-O2 -ansi -pedantic -Wall -Werror +CFLAGS=-g -ansi -pedantic -Wall -Werror LDFLAGS=-lpng -lvncclient .PHONY: clean diff --git a/guacamole/proxy/client.c b/guacamole/proxy/client.c index 343e2a83b..253eb4d33 100644 --- a/guacamole/proxy/client.c +++ b/guacamole/proxy/client.c @@ -60,6 +60,7 @@ guac_client* guac_get_client(int client_fd, void (*client_init)(guac_client* cli client->io = guac_open(client_fd); client_init(client, hostname, port); + guac_flush(client->io); return client; @@ -84,38 +85,48 @@ void guac_start_client(guac_client* client) { for (;;) { /* Handle server messages */ - if (client->handle_messages) + if (client->handle_messages) { client->handle_messages(client); + guac_flush(client->io); + } wait_result = guac_instructions_waiting(io); if (wait_result > 0) { guac_instruction* instruction; - while ((instruction = guac_read_instruction(io))) { + if ((instruction = guac_read_instruction(io))) { - 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 */ - ); - } + do { + 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 */ + ); + } - 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 */ - ); - } + 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 */ + ); + } + + guac_free_instruction(instruction); + } while ((instruction = guac_read_instruction(io))); - guac_free_instruction(instruction); } + else + return; + } + else if (wait_result < 0) + return; } diff --git a/guacamole/proxy/guacio.c b/guacamole/proxy/guacio.c index 1b0be0fb7..f8f2400da 100644 --- a/guacamole/proxy/guacio.c +++ b/guacamole/proxy/guacio.c @@ -227,6 +227,9 @@ int guac_select(GUACIO* io, int usec_timeout) { fd_set fds; struct timeval timeout; + if (usec_timeout < 0) + return select(io->fd + 1, &fds, NULL, NULL, NULL); + timeout.tv_sec = usec_timeout/1000000; timeout.tv_usec = usec_timeout%1000000; diff --git a/guacamole/proxy/protocol.c b/guacamole/proxy/protocol.c index d0e1c91ef..89bee60c8 100644 --- a/guacamole/proxy/protocol.c +++ b/guacamole/proxy/protocol.c @@ -289,6 +289,7 @@ 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) { guac_instruction* parsed_instruction; @@ -355,18 +356,13 @@ guac_instruction* guac_read_instruction(GUACIO* io) { } /* No instruction yet? Get more data ... */ - retval = guac_select(io, 1000); + while ((retval = guac_select(io, 2500000)) == 0); if (retval < 0) - return NULL; - - /* Break if descriptor doesn't have enough data */ - if (retval == 0) - return NULL; /* SOFT FAIL: No instruction ... yet, but is still in buffer */ + return NULL; /* If error, no more instructions */ retval = __guac_fill_instructionbuf(io); - if (retval < 0 && errno != EAGAIN && errno != EWOULDBLOCK) - return NULL; - + if (retval <= 0) + return NULL; /* If error, or no more data, no instructions remain */ } } diff --git a/guacamole/proxy/vnc_client.c b/guacamole/proxy/vnc_client.c index 5bcc073ca..683eb1ff3 100644 --- a/guacamole/proxy/vnc_client.c +++ b/guacamole/proxy/vnc_client.c @@ -98,7 +98,6 @@ void guac_vnc_cursor(rfbClient* client, int x, int y, int w, int h, int bpp) { /* SEND CURSOR */ guac_send_cursor(io, x, y, png_buffer, w, h); - guac_flush(io); } void guac_vnc_update(rfbClient* client, int x, int y, int w, int h) { @@ -150,7 +149,6 @@ void guac_vnc_update(rfbClient* client, int x, int y, int w, int h) { } guac_send_png(io, x, y, png_buffer, w, h); - guac_flush(io); } @@ -159,7 +157,6 @@ void guac_vnc_copyrect(rfbClient* client, int src_x, int src_y, int w, int h, in GUACIO* io = rfbClientGetClientData(client, __GUAC_VNC_TAG_IO); guac_send_copy(io, src_x, src_y, w, h, dest_x, dest_y); - guac_flush(io); } @@ -244,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; @@ -288,7 +285,6 @@ void vnc_guac_client_init(guac_client* client, const char* hostname, int port) { /* Send size */ guac_send_size(client->io, rfb_client->width, rfb_client->height); - guac_flush(client->io); }