64-bit timestamps and output

This commit is contained in:
Michael Jumper 2011-04-29 00:45:38 -07:00
parent 3239f032ae
commit 8242c37f11
7 changed files with 14 additions and 13 deletions

View File

@ -151,13 +151,13 @@ struct guac_client {
* The time (in milliseconds) of receipt of the last sync message from * The time (in milliseconds) of receipt of the last sync message from
* the client. * the client.
*/ */
long last_received_timestamp; guac_timestamp_t last_received_timestamp;
/** /**
* The time (in milliseconds) that the last sync message was sent to the * The time (in milliseconds) that the last sync message was sent to the
* client. * client.
*/ */
long last_sent_timestamp; guac_timestamp_t last_sent_timestamp;
/** /**
* Reference to dlopen'd client plugin. * Reference to dlopen'd client plugin.

View File

@ -123,7 +123,7 @@ GUACIO* guac_open(int fd);
* @param i The unsigned int to write. * @param i The unsigned int to write.
* @return Zero on success, or non-zero if an error occurs while writing. * @return Zero on success, or non-zero if an error occurs while writing.
*/ */
ssize_t guac_write_int(GUACIO* io, long i); ssize_t guac_write_int(GUACIO* io, int64_t i);
/** /**
* Writes the given string to the given GUACIO object. The data * Writes the given string to the given GUACIO object. The data

View File

@ -64,6 +64,7 @@
*/ */
#define GUAC_USEC_TIMEOUT (GUAC_TIMEOUT*1000) #define GUAC_USEC_TIMEOUT (GUAC_TIMEOUT*1000)
typedef int64_t guac_timestamp_t;
/** /**
* Composite modes used by Guacamole draw instructions. Each * Composite modes used by Guacamole draw instructions. Each
@ -192,7 +193,7 @@ int guac_send_name(GUACIO* io, const char* name);
* @param timestamp The current timestamp (in milliseconds). * @param timestamp The current timestamp (in milliseconds).
* @return Zero on success, non-zero on error. * @return Zero on success, non-zero on error.
*/ */
int guac_send_sync(GUACIO* io, long timestamp); int guac_send_sync(GUACIO* io, guac_timestamp_t timestamp);
/** /**
* Sends an error instruction over the given GUACIO connection. The * Sends an error instruction over the given GUACIO connection. The
@ -298,7 +299,7 @@ int guac_instructions_waiting(GUACIO* io);
*/ */
int guac_read_instruction(GUACIO* io, guac_instruction* parsed_instruction); int guac_read_instruction(GUACIO* io, guac_instruction* parsed_instruction);
long guac_current_timestamp(); guac_timestamp_t guac_current_timestamp();
void guac_sleep(int millis); void guac_sleep(int millis);
#endif #endif

View File

@ -55,7 +55,7 @@ __guac_instruction_handler_mapping __guac_instruction_handler_map[] = {
/* Guacamole instruction handlers */ /* Guacamole instruction handlers */
int __guac_handle_sync(guac_client* client, guac_instruction* instruction) { int __guac_handle_sync(guac_client* client, guac_instruction* instruction) {
long timestamp = atol(instruction->argv[0]); guac_timestamp_t timestamp = atol(instruction->argv[0]);
/* Error if timestamp is in future */ /* Error if timestamp is in future */
if (timestamp > client->last_sent_timestamp) if (timestamp > client->last_sent_timestamp)

View File

@ -267,7 +267,7 @@ void* __guac_client_output_thread(void* data) {
while (client->state == RUNNING) { while (client->state == RUNNING) {
/* Occasionally ping client with sync */ /* Occasionally ping client with sync */
long timestamp = guac_current_timestamp(); guac_timestamp_t timestamp = guac_current_timestamp();
if (timestamp - client->last_sent_timestamp > GUAC_SYNC_FREQUENCY) { if (timestamp - client->last_sent_timestamp > GUAC_SYNC_FREQUENCY) {
client->last_sent_timestamp = timestamp; client->last_sent_timestamp = timestamp;
if ( if (

View File

@ -98,11 +98,11 @@ ssize_t __guac_write(GUACIO* io, const char* buf, int count) {
return retval; return retval;
} }
ssize_t guac_write_int(GUACIO* io, long i) { ssize_t guac_write_int(GUACIO* io, int64_t i) {
char buffer[128]; char buffer[128];
char* ptr = &(buffer[127]); char* ptr = &(buffer[127]);
long nonneg; int64_t nonneg;
/* Obtain non-negative value */ /* Obtain non-negative value */
if (i < 0) nonneg = -i; if (i < 0) nonneg = -i;

View File

@ -263,7 +263,7 @@ int guac_send_error(GUACIO* io, const char* error) {
} }
int guac_send_sync(GUACIO* io, long timestamp) { int guac_send_sync(GUACIO* io, guac_timestamp_t timestamp) {
return return
guac_write_string(io, "sync:") guac_write_string(io, "sync:")
@ -503,7 +503,7 @@ int guac_instructions_waiting(GUACIO* io) {
return guac_select(io, GUAC_USEC_TIMEOUT); return guac_select(io, GUAC_USEC_TIMEOUT);
} }
long guac_current_timestamp() { guac_timestamp_t guac_current_timestamp() {
#ifdef HAVE_CLOCK_GETTIME #ifdef HAVE_CLOCK_GETTIME
@ -513,7 +513,7 @@ long guac_current_timestamp() {
clock_gettime(CLOCK_REALTIME, &current); clock_gettime(CLOCK_REALTIME, &current);
/* Calculate milliseconds */ /* Calculate milliseconds */
return current.tv_sec * 1000 + current.tv_nsec / 1000000; return (guac_timestamp_t) current.tv_sec * 1000 + current.tv_nsec / 1000000;
#else #else
@ -523,7 +523,7 @@ long guac_current_timestamp() {
gettimeofday(&current, NULL); gettimeofday(&current, NULL);
/* Calculate milliseconds */ /* Calculate milliseconds */
return current.tv_sec * 1000 + current.tv_usec / 1000; return (guac_timestamp_t) current.tv_sec * 1000 + current.tv_usec / 1000;
#endif #endif