From 9c7c09cd7f47bd5fd0470614232d5d7c6f5eefde Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Tue, 8 Feb 2011 18:23:10 -0800 Subject: [PATCH] Removed transfer limit, improved cross-platform logging, added check for png_structp. --- libguac/include/guacio.h | 7 ------ libguac/include/guaclog.h | 6 ++--- libguac/src/guacio.c | 49 +++++---------------------------------- libguac/src/protocol.c | 10 ++++++++ 4 files changed, 19 insertions(+), 53 deletions(-) diff --git a/libguac/include/guacio.h b/libguac/include/guacio.h index 8499ea3e..da4aa8f5 100644 --- a/libguac/include/guacio.h +++ b/libguac/include/guacio.h @@ -79,13 +79,6 @@ typedef struct GUACIO { */ char* instructionbuf; - /** - * The transfer limit, in kilobytes per second. If 0, there is no - * transfer limit. If non-zero, sleep calls are used at the end of - * a write to ensure output never exceeds the specified limit. - */ - unsigned int transfer_limit; /* KB/sec */ - } GUACIO; /** diff --git a/libguac/include/guaclog.h b/libguac/include/guaclog.h index 22dd637a..a59c2318 100644 --- a/libguac/include/guaclog.h +++ b/libguac/include/guaclog.h @@ -20,16 +20,16 @@ #ifndef _GUACLOG_H #define _GUACLOG_H -#ifndef __MINGW32__ +#ifdef HAVE_SYSLOG_H - // Logging for UNIX + /* Logging for UNIX */ #include #define GUAC_LOG_ERROR(...) syslog(LOG_ERR, __VA_ARGS__) #define GUAC_LOG_INFO(...) syslog(LOG_INFO, __VA_ARGS__) #else - // Logging for W32 + /* Logging for W32 */ #define GUAC_LOG_ERROR(...) fprintf(stderr, __VA_ARGS__) #define GUAC_LOG_INFO(...) fprintf(stderr, __VA_ARGS__) diff --git a/libguac/src/guacio.c b/libguac/src/guacio.c index e9f0e5b9..c0a14b8e 100644 --- a/libguac/src/guacio.c +++ b/libguac/src/guacio.c @@ -23,8 +23,13 @@ #include #include -#include +#ifdef __MINGW32__ +#include +#else #include +#endif + +#include #include #include "guacio.h" @@ -48,9 +53,6 @@ GUACIO* guac_open(int fd) { io->instructionbuf = malloc(io->instructionbuf_size); io->instructionbuf_used_length = 0; - /* Set limit */ - io->transfer_limit = 0; - return io; } @@ -64,41 +66,10 @@ void guac_close(GUACIO* io) { /* Write bytes, limit rate */ ssize_t __guac_write(GUACIO* io, const char* buf, int count) { - struct timeval start, end; int retval; /* Write and time how long the write takes (microseconds) */ - gettimeofday(&start, NULL); retval = write(io->fd, buf, count); - gettimeofday(&end, NULL); - - if (retval < 0) - return retval; - - if (io->transfer_limit > 0) { - - suseconds_t elapsed; - suseconds_t required_usecs; - - /* Get elapsed time */ - elapsed = (end.tv_sec - start.tv_sec) * 1000000 + end.tv_usec - start.tv_usec; - - /* Calculate how much time we must sleep */ - required_usecs = retval * 1000 / io->transfer_limit - elapsed; /* useconds at transfer_limit KB/s*/ - - /* Sleep as necessary */ - if (required_usecs > 0) { - - struct timespec required_sleep; - - required_sleep.tv_sec = required_usecs / 1000000; - required_sleep.tv_nsec = (required_usecs % 1000000) * 1000; - - nanosleep(&required_sleep, NULL); - - } - - } return retval; } @@ -136,19 +107,11 @@ ssize_t guac_write_string(GUACIO* io, const char* str) { /* Flush when necessary, return on error */ if (io->written > 8188 /* sizeof(out_buf) - 4 */) { - struct timeval start, end; - suseconds_t elapsed; - - gettimeofday(&start, NULL); retval = __guac_write(io, out_buf, io->written); - gettimeofday(&end, NULL); if (retval < 0) return retval; - /* Get elapsed time */ - elapsed = (end.tv_sec - start.tv_sec) * 1000000 + end.tv_usec - start.tv_usec; - io->written = 0; } diff --git a/libguac/src/protocol.c b/libguac/src/protocol.c index 4d3110e6..f050a868 100644 --- a/libguac/src/protocol.c +++ b/libguac/src/protocol.c @@ -23,8 +23,18 @@ #include #include +/* If png_structp not defined in png.h, try to include pngstruct.h */ +#ifndef png_structp +#include +#endif + #include + +#ifdef __MINGW32__ +#include +#else #include +#endif #include "guacio.h" #include "protocol.h"