PROPERLY detect EOF, remove copyrect (again)

This commit is contained in:
Michael Jumper
2010-09-07 23:49:19 -07:00
parent 5b1f538f10
commit af0b4d933d
4 changed files with 33 additions and 25 deletions

View File

@@ -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;
int retval;
retval = guac_read_instruction(io, &instruction); /* 0 if no instructions finished yet, <0 if error or EOF */
if ((instruction = guac_read_instruction(io))) {
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)

View File

@@ -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 */
}
}

View File

@@ -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

View File

@@ -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;