Removed daemon-specific functions
This commit is contained in:
parent
dd356d4fe2
commit
84254cfddf
@ -307,16 +307,6 @@ typedef int guac_client_init_handler(guac_client* client, int argc, char** argv)
|
||||
*/
|
||||
guac_client* guac_get_client(int client_fd);
|
||||
|
||||
/**
|
||||
* Enter the main network message handling loop for the given client.
|
||||
*
|
||||
* @param client The proxy client to start handling messages of/for.
|
||||
* @return Zero if the client successfully started, non-zero if an error
|
||||
* occurs during startup. Note that this function will still return
|
||||
* zero if an error occurs while the client is running.
|
||||
*/
|
||||
int guac_start_client(guac_client* client);
|
||||
|
||||
/**
|
||||
* Free all resources associated with the given client.
|
||||
*
|
||||
@ -336,15 +326,6 @@ void guac_free_client(guac_client* client);
|
||||
*/
|
||||
int guac_client_handle_instruction(guac_client* client, guac_instruction* instruction);
|
||||
|
||||
/**
|
||||
* Signal the given client to stop. This will set the state of the given client
|
||||
* to STOPPING, which signals the I/O threads to shutdown, and ultimately
|
||||
* results in shutdown of the client.
|
||||
*
|
||||
* @param client The proxy client to stop.
|
||||
*/
|
||||
void guac_client_stop(guac_client* client);
|
||||
|
||||
/**
|
||||
* Allocates a new buffer (invisible layer). An arbitrary index is
|
||||
* automatically assigned if no existing buffer is available for use.
|
||||
|
@ -303,10 +303,6 @@ guac_client* guac_get_client(int client_fd) {
|
||||
|
||||
}
|
||||
|
||||
void guac_client_stop(guac_client* client) {
|
||||
client->state = STOPPING;
|
||||
}
|
||||
|
||||
void guac_free_client(guac_client* client) {
|
||||
|
||||
if (client->free_handler) {
|
||||
@ -336,135 +332,6 @@ void guac_free_client(guac_client* client) {
|
||||
free(client);
|
||||
}
|
||||
|
||||
|
||||
void* __guac_client_output_thread(void* data) {
|
||||
|
||||
guac_client* client = (guac_client*) data;
|
||||
GUACIO* io = client->io;
|
||||
|
||||
guac_timestamp last_ping_timestamp = guac_current_timestamp();
|
||||
|
||||
/* Guacamole client output loop */
|
||||
while (client->state == RUNNING) {
|
||||
|
||||
/* Occasionally ping client with repeat of last sync */
|
||||
guac_timestamp timestamp = guac_current_timestamp();
|
||||
if (timestamp - last_ping_timestamp > GUAC_SYNC_FREQUENCY) {
|
||||
last_ping_timestamp = timestamp;
|
||||
if (
|
||||
guac_send_sync(io, client->last_sent_timestamp)
|
||||
|| guac_flush(io)
|
||||
) {
|
||||
guac_client_stop(client);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
/* Handle server messages */
|
||||
if (client->handle_messages) {
|
||||
|
||||
/* Get previous GUACIO state */
|
||||
int last_total_written = io->total_written;
|
||||
|
||||
/* Only handle messages if synced within threshold */
|
||||
if (client->last_sent_timestamp - client->last_received_timestamp
|
||||
< GUAC_SYNC_THRESHOLD) {
|
||||
|
||||
int retval = client->handle_messages(client);
|
||||
if (retval) {
|
||||
guac_log_error("Error handling server messages");
|
||||
guac_client_stop(client);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* If data was written during message handling */
|
||||
if (io->total_written != last_total_written) {
|
||||
|
||||
/* Sleep as necessary */
|
||||
guac_sleep(GUAC_SERVER_MESSAGE_HANDLE_FREQUENCY);
|
||||
|
||||
/* Send sync instruction */
|
||||
client->last_sent_timestamp = guac_current_timestamp();
|
||||
if (guac_send_sync(io, client->last_sent_timestamp)) {
|
||||
guac_client_stop(client);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (guac_flush(io)) {
|
||||
guac_client_stop(client);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/* If sync threshold exceeded, don't spin waiting for resync */
|
||||
else
|
||||
guac_sleep(GUAC_SERVER_MESSAGE_HANDLE_FREQUENCY);
|
||||
|
||||
}
|
||||
|
||||
/* If no message handler, just sleep until next sync ping */
|
||||
else
|
||||
guac_sleep(GUAC_SYNC_FREQUENCY);
|
||||
|
||||
} /* End of output loop */
|
||||
|
||||
guac_client_stop(client);
|
||||
return NULL;
|
||||
|
||||
}
|
||||
|
||||
void* __guac_client_input_thread(void* data) {
|
||||
|
||||
guac_client* client = (guac_client*) data;
|
||||
GUACIO* io = client->io;
|
||||
|
||||
guac_instruction instruction;
|
||||
|
||||
/* Guacamole client input loop */
|
||||
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;
|
||||
}
|
||||
|
||||
/* Free allocate instruction data */
|
||||
guac_free_instruction_data(&instruction);
|
||||
|
||||
}
|
||||
|
||||
guac_client_stop(client);
|
||||
return NULL;
|
||||
|
||||
}
|
||||
|
||||
int guac_start_client(guac_client* client) {
|
||||
|
||||
guac_thread input_thread, output_thread;
|
||||
|
||||
if (guac_thread_create(&output_thread, __guac_client_output_thread, (void*) client)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (guac_thread_create(&input_thread, __guac_client_input_thread, (void*) client)) {
|
||||
guac_client_stop(client);
|
||||
guac_thread_join(output_thread);
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Wait for I/O threads */
|
||||
guac_thread_join(input_thread);
|
||||
guac_thread_join(output_thread);
|
||||
|
||||
/* Done */
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
int guac_client_handle_instruction(guac_client* client, guac_instruction* instruction) {
|
||||
|
||||
/* For each defined instruction */
|
||||
|
Loading…
Reference in New Issue
Block a user