Changed semantics of guac_read_instruction, fixed timeout.

This commit is contained in:
Michael Jumper 2011-03-17 00:25:35 -07:00
parent 3e14b52b1c
commit a08cd5b8b7
3 changed files with 15 additions and 23 deletions

View File

@ -248,9 +248,10 @@ int guac_instructions_waiting(GUACIO* io);
* will be populated with data read from the given * will be populated with data read from the given
* GUACIO connection. * GUACIO connection.
* @return A positive value if data was successfully read, negative on * @return A positive value if data was successfully read, negative on
* error, or zero if the instrucion could not be read completely, * error, or zero if the instruction could not be read completely
* in which case, subsequent calls to guac_read_instruction() will * because GUAC_TIMEOUT elapsed, in which case subsequent calls to
* return the parsed instruction once enough data is available. * guac_read_instruction() will return the parsed instruction once
* enough data is available.
*/ */
int guac_read_instruction(GUACIO* io, guac_instruction* parsed_instruction); int guac_read_instruction(GUACIO* io, guac_instruction* parsed_instruction);

View File

@ -308,6 +308,7 @@ guac_client* guac_get_client(int client_fd) {
} }
void guac_client_stop(guac_client* client) { void guac_client_stop(guac_client* client) {
fprintf(stderr, "***************** STOPPING! *********************\n");
client->state = STOPPING; client->state = STOPPING;
} }
@ -397,25 +398,16 @@ void* __guac_client_input_thread(void* data) {
guac_instruction instruction; guac_instruction instruction;
/* Guacamole client input loop */ /* Guacamole client input loop */
while (client->state == RUNNING && guac_instructions_waiting(io) > 0) { while (client->state == RUNNING && guac_read_instruction(io, &instruction) > 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;
}
/* Call handler, stop on error */
if (guac_client_handle_instruction(client, &instruction) < 0) {
guac_free_instruction_data(&instruction); guac_free_instruction_data(&instruction);
break;
} }
if (retval < 0) /* Free allocate instruction data */
break; guac_free_instruction_data(&instruction);
/* Otherwise, retval == 0 implies unfinished instruction */
} }

View File

@ -497,16 +497,15 @@ int guac_read_instruction(GUACIO* io, guac_instruction* parsed_instruction) {
} }
/* No instruction yet? Get more data ... */ /* No instruction yet? Get more data ... */
retval = guac_select(io, 1000); retval = guac_select(io, GUAC_USEC_TIMEOUT);
if (retval <= 0) if (retval <= 0)
return retval; return retval;
/* If more data is available, fill into buffer */
retval = __guac_fill_instructionbuf(io); retval = __guac_fill_instructionbuf(io);
if (retval < 0) if (retval < 0) return retval; /* Error */
return retval; if (retval == 0) return -1; /* EOF */
if (retval == 0)
return -1; /* EOF */
} }
} }