Additional logging, moderate cleanup.
This commit is contained in:
parent
76e55c5a51
commit
9c5f1da646
@ -45,6 +45,11 @@
|
|||||||
#include "client.h"
|
#include "client.h"
|
||||||
#include "thread.h"
|
#include "thread.h"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sleep for the given number of milliseconds.
|
||||||
|
*
|
||||||
|
* @param millis The number of milliseconds to sleep.
|
||||||
|
*/
|
||||||
void __guacd_sleep(int millis) {
|
void __guacd_sleep(int millis) {
|
||||||
|
|
||||||
struct timespec sleep_period;
|
struct timespec sleep_period;
|
||||||
@ -79,14 +84,18 @@ void* __guac_client_output_thread(void* data) {
|
|||||||
|
|
||||||
/* Send sync */
|
/* Send sync */
|
||||||
if (guac_protocol_send_sync(socket, client->last_sent_timestamp)) {
|
if (guac_protocol_send_sync(socket, client->last_sent_timestamp)) {
|
||||||
guac_client_log_error(client, "Error sending \"sync\" instruction: %s", guac_status_string(guac_error));
|
guac_client_log_error(client,
|
||||||
|
"Error sending \"sync\" instruction: %s",
|
||||||
|
guac_status_string(guac_error));
|
||||||
guac_client_stop(client);
|
guac_client_stop(client);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Flush */
|
/* Flush */
|
||||||
if (guac_socket_flush(socket)) {
|
if (guac_socket_flush(socket)) {
|
||||||
guac_client_log_error(client, "Error flushing output: %s", guac_status_string(guac_error));
|
guac_client_log_error(client,
|
||||||
|
"Error flushing output: %s",
|
||||||
|
guac_status_string(guac_error));
|
||||||
guac_client_stop(client);
|
guac_client_stop(client);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
@ -102,33 +111,36 @@ void* __guac_client_output_thread(void* data) {
|
|||||||
|
|
||||||
int retval = client->handle_messages(client);
|
int retval = client->handle_messages(client);
|
||||||
if (retval) {
|
if (retval) {
|
||||||
guac_client_log_error(client, "Error handling server messages: %s", guac_status_string(guac_error));
|
guac_client_log_error(client,
|
||||||
|
"Error handling server messages: %s",
|
||||||
|
guac_status_string(guac_error));
|
||||||
guac_client_stop(client);
|
guac_client_stop(client);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Sleep as necessary */
|
|
||||||
__guacd_sleep(GUAC_SERVER_MESSAGE_HANDLE_FREQUENCY);
|
|
||||||
|
|
||||||
/* Send sync instruction */
|
/* Send sync instruction */
|
||||||
client->last_sent_timestamp = guac_protocol_get_timestamp();
|
client->last_sent_timestamp = guac_protocol_get_timestamp();
|
||||||
if (guac_protocol_send_sync(socket, client->last_sent_timestamp)) {
|
if (guac_protocol_send_sync(socket, client->last_sent_timestamp)) {
|
||||||
guac_client_log_error(client, "Error sending \"sync\" instruction: %s", guac_status_string(guac_error));
|
guac_client_log_error(client,
|
||||||
|
"Error sending \"sync\" instruction: %s",
|
||||||
|
guac_status_string(guac_error));
|
||||||
guac_client_stop(client);
|
guac_client_stop(client);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Flush */
|
||||||
if (guac_socket_flush(socket)) {
|
if (guac_socket_flush(socket)) {
|
||||||
guac_client_log_error(client, "Error flushing output: %s", guac_status_string(guac_error));
|
guac_client_log_error(client,
|
||||||
|
"Error flushing output: %s",
|
||||||
|
guac_status_string(guac_error));
|
||||||
guac_client_stop(client);
|
guac_client_stop(client);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* If sync threshold exceeded, don't spin waiting for resync */
|
/* Sleep before handling more messages */
|
||||||
else
|
__guacd_sleep(GUAC_SERVER_MESSAGE_HANDLE_FREQUENCY);
|
||||||
__guacd_sleep(GUAC_SERVER_MESSAGE_HANDLE_FREQUENCY);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -157,14 +169,18 @@ void* __guac_client_input_thread(void* data) {
|
|||||||
|
|
||||||
/* Stop on error */
|
/* Stop on error */
|
||||||
if (instruction == NULL) {
|
if (instruction == NULL) {
|
||||||
guac_client_log_error(client, "Error reading instruction: %s", guac_status_string(guac_error));
|
guac_client_log_error(client,
|
||||||
|
"Error reading instruction: %s",
|
||||||
|
guac_status_string(guac_error));
|
||||||
guac_client_stop(client);
|
guac_client_stop(client);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Call handler, stop on error */
|
/* Call handler, stop on error */
|
||||||
if (guac_client_handle_instruction(client, instruction) < 0) {
|
if (guac_client_handle_instruction(client, instruction) < 0) {
|
||||||
guac_client_log_error(client, "Error in client \"%s\" instruction handler: %s", instruction->opcode, guac_status_string(guac_error));
|
guac_client_log_error(client,
|
||||||
|
"Error in client \"%s\" instruction handler: %s",
|
||||||
|
instruction->opcode, guac_status_string(guac_error));
|
||||||
guac_instruction_free(instruction);
|
guac_instruction_free(instruction);
|
||||||
guac_client_stop(client);
|
guac_client_stop(client);
|
||||||
return NULL;
|
return NULL;
|
||||||
@ -184,10 +200,12 @@ int guac_start_client(guac_client* client) {
|
|||||||
guac_thread input_thread, output_thread;
|
guac_thread input_thread, output_thread;
|
||||||
|
|
||||||
if (guac_thread_create(&output_thread, __guac_client_output_thread, (void*) client)) {
|
if (guac_thread_create(&output_thread, __guac_client_output_thread, (void*) client)) {
|
||||||
|
guac_client_log_error(client, "Unable to start output thread");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (guac_thread_create(&input_thread, __guac_client_input_thread, (void*) client)) {
|
if (guac_thread_create(&input_thread, __guac_client_input_thread, (void*) client)) {
|
||||||
|
guac_client_log_error(client, "Unable to start input thread");
|
||||||
guac_client_stop(client);
|
guac_client_stop(client);
|
||||||
guac_thread_join(output_thread);
|
guac_thread_join(output_thread);
|
||||||
return -1;
|
return -1;
|
||||||
@ -202,4 +220,3 @@ int guac_start_client(guac_client* client) {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -64,13 +64,14 @@ void* start_client_thread(void* data) {
|
|||||||
|
|
||||||
guac_client* client;
|
guac_client* client;
|
||||||
guac_client_plugin* plugin;
|
guac_client_plugin* plugin;
|
||||||
client_thread_data* thread_data = (client_thread_data*) data;
|
|
||||||
guac_socket* socket;
|
|
||||||
guac_instruction* select;
|
guac_instruction* select;
|
||||||
guac_instruction* connect;
|
guac_instruction* connect;
|
||||||
|
|
||||||
|
/* Get thread data */
|
||||||
|
client_thread_data* thread_data = (client_thread_data*) data;
|
||||||
|
|
||||||
/* Open guac_socket */
|
/* Open guac_socket */
|
||||||
socket = guac_socket_open(thread_data->fd);
|
guac_socket* socket = guac_socket_open(thread_data->fd);
|
||||||
|
|
||||||
/* Get protocol from select instruction */
|
/* Get protocol from select instruction */
|
||||||
select = guac_protocol_expect_instruction(
|
select = guac_protocol_expect_instruction(
|
||||||
@ -171,10 +172,12 @@ void* start_client_thread(void* data) {
|
|||||||
|
|
||||||
/* Start client threads */
|
/* Start client threads */
|
||||||
syslog(LOG_INFO, "Starting client");
|
syslog(LOG_INFO, "Starting client");
|
||||||
guac_start_client(client);
|
if (guac_start_client(client))
|
||||||
|
syslog(LOG_ERR, "Client finished abnormally");
|
||||||
|
else
|
||||||
|
syslog(LOG_INFO, "Client finished normally");
|
||||||
|
|
||||||
/* Clean up */
|
/* Clean up */
|
||||||
syslog(LOG_INFO, "Client finished");
|
|
||||||
guac_client_free(client);
|
guac_client_free(client);
|
||||||
if (guac_client_plugin_close(plugin))
|
if (guac_client_plugin_close(plugin))
|
||||||
syslog(LOG_ERR, "Error closing client plugin");
|
syslog(LOG_ERR, "Error closing client plugin");
|
||||||
@ -290,7 +293,7 @@ int main(int argc, char* argv[]) {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Otherwise, this is the daemon */
|
/* Otherwise, this is the daemon */
|
||||||
syslog(LOG_INFO, "Started, listening on port %i", listen_port);
|
syslog(LOG_INFO, "Listening on port %i", listen_port);
|
||||||
|
|
||||||
/* Ignore SIGPIPE */
|
/* Ignore SIGPIPE */
|
||||||
if (signal(SIGPIPE, SIG_IGN) == SIG_ERR) {
|
if (signal(SIGPIPE, SIG_IGN) == SIG_ERR) {
|
||||||
|
Loading…
Reference in New Issue
Block a user