Removed transfer limit, improved cross-platform logging, added check for png_structp.
This commit is contained in:
parent
fd1485e220
commit
9c7c09cd7f
@ -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;
|
||||
|
||||
/**
|
||||
|
@ -20,16 +20,16 @@
|
||||
#ifndef _GUACLOG_H
|
||||
#define _GUACLOG_H
|
||||
|
||||
#ifndef __MINGW32__
|
||||
#ifdef HAVE_SYSLOG_H
|
||||
|
||||
// Logging for UNIX
|
||||
/* Logging for UNIX */
|
||||
#include <syslog.h>
|
||||
#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__)
|
||||
|
||||
|
@ -23,8 +23,13 @@
|
||||
#include <fcntl.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include <time.h>
|
||||
#ifdef __MINGW32__
|
||||
#include <winsock2.h>
|
||||
#else
|
||||
#include <sys/select.h>
|
||||
#endif
|
||||
|
||||
#include <time.h>
|
||||
#include <sys/time.h>
|
||||
|
||||
#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;
|
||||
}
|
||||
|
||||
|
@ -23,8 +23,18 @@
|
||||
#include <errno.h>
|
||||
#include <png.h>
|
||||
|
||||
/* If png_structp not defined in png.h, try to include pngstruct.h */
|
||||
#ifndef png_structp
|
||||
#include <pngstruct.h>
|
||||
#endif
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
#ifdef __MINGW32__
|
||||
#include <winsock2.h>
|
||||
#else
|
||||
#include <sys/socket.h>
|
||||
#endif
|
||||
|
||||
#include "guacio.h"
|
||||
#include "protocol.h"
|
||||
|
Loading…
Reference in New Issue
Block a user