diff --git a/libguac/include/protocol.h b/libguac/include/protocol.h index a640c72d..d7512d1a 100644 --- a/libguac/include/protocol.h +++ b/libguac/include/protocol.h @@ -248,9 +248,10 @@ int guac_instructions_waiting(GUACIO* io); * will be populated with data read from the given * GUACIO connection. * @return A positive value if data was successfully read, negative on - * error, or zero if the instrucion could not be read completely, - * in which case, subsequent calls to guac_read_instruction() will - * return the parsed instruction once enough data is available. + * error, or zero if the instruction could not be read completely + * because GUAC_TIMEOUT elapsed, in which case subsequent calls to + * guac_read_instruction() will return the parsed instruction once + * enough data is available. */ int guac_read_instruction(GUACIO* io, guac_instruction* parsed_instruction); diff --git a/libguac/src/client.c b/libguac/src/client.c index d37c1a66..c9065c6c 100644 --- a/libguac/src/client.c +++ b/libguac/src/client.c @@ -308,6 +308,7 @@ guac_client* guac_get_client(int client_fd) { } void guac_client_stop(guac_client* client) { + fprintf(stderr, "***************** STOPPING! *********************\n"); client->state = STOPPING; } @@ -397,25 +398,16 @@ void* __guac_client_input_thread(void* data) { guac_instruction instruction; /* Guacamole client input loop */ - while (client->state == RUNNING && guac_instructions_waiting(io) > 0) { - - int retval; - while ((retval = guac_read_instruction(io, &instruction)) > 0) { - - if (guac_client_handle_instruction(client, &instruction) < 0) { - guac_free_instruction_data(&instruction); - guac_client_stop(client); - return NULL; - } + while (client->state == RUNNING && guac_read_instruction(io, &instruction) > 0) { + /* Call handler, stop on error */ + if (guac_client_handle_instruction(client, &instruction) < 0) { guac_free_instruction_data(&instruction); - + break; } - if (retval < 0) - break; - - /* Otherwise, retval == 0 implies unfinished instruction */ + /* Free allocate instruction data */ + guac_free_instruction_data(&instruction); } diff --git a/libguac/src/protocol.c b/libguac/src/protocol.c index 674f5596..dec704be 100644 --- a/libguac/src/protocol.c +++ b/libguac/src/protocol.c @@ -497,16 +497,15 @@ int guac_read_instruction(GUACIO* io, guac_instruction* parsed_instruction) { } /* No instruction yet? Get more data ... */ - retval = guac_select(io, 1000); + retval = guac_select(io, GUAC_USEC_TIMEOUT); if (retval <= 0) return retval; + /* If more data is available, fill into buffer */ retval = __guac_fill_instructionbuf(io); - if (retval < 0) - return retval; + if (retval < 0) return retval; /* Error */ + if (retval == 0) return -1; /* EOF */ - if (retval == 0) - return -1; /* EOF */ } }