Working sync control.
This commit is contained in:
parent
e463360aad
commit
12d497ca3f
@ -74,6 +74,11 @@ typedef struct GUACIO {
|
|||||||
*/
|
*/
|
||||||
int written;
|
int written;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The number of bytes written total, since this GUACIO was opened.
|
||||||
|
*/
|
||||||
|
int total_written;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The main write buffer. Bytes written go here before being flushed
|
* The main write buffer. Bytes written go here before being flushed
|
||||||
* to the open file descriptor.
|
* to the open file descriptor.
|
||||||
|
@ -291,6 +291,9 @@ void guac_start_client(guac_client* client) {
|
|||||||
/* Handle server messages */
|
/* Handle server messages */
|
||||||
if (client->handle_messages) {
|
if (client->handle_messages) {
|
||||||
|
|
||||||
|
/* Get previous GUACIO state */
|
||||||
|
int last_total_written = io->total_written;
|
||||||
|
|
||||||
/* Only handle messages if synced within threshold */
|
/* Only handle messages if synced within threshold */
|
||||||
if (last_sent_timestamp - last_received_timestamp < 200) {
|
if (last_sent_timestamp - last_received_timestamp < 200) {
|
||||||
|
|
||||||
@ -300,9 +303,11 @@ void guac_start_client(guac_client* client) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Send sync after updates */
|
/* If data was written during message handling */
|
||||||
|
if (io->total_written != last_total_written) {
|
||||||
last_sent_timestamp = __guac_current_timestamp();
|
last_sent_timestamp = __guac_current_timestamp();
|
||||||
guac_send_sync(io, last_sent_timestamp);
|
guac_send_sync(io, last_sent_timestamp);
|
||||||
|
}
|
||||||
|
|
||||||
guac_flush(io);
|
guac_flush(io);
|
||||||
}
|
}
|
||||||
|
@ -126,6 +126,7 @@ ssize_t guac_write_string(GUACIO* io, const char* str) {
|
|||||||
for (; *str != '\0'; str++) {
|
for (; *str != '\0'; str++) {
|
||||||
|
|
||||||
out_buf[io->written++] = *str;
|
out_buf[io->written++] = *str;
|
||||||
|
io->total_written++;
|
||||||
|
|
||||||
/* Flush when necessary, return on error */
|
/* Flush when necessary, return on error */
|
||||||
if (io->written > 8188 /* sizeof(out_buf) - 4 */) {
|
if (io->written > 8188 /* sizeof(out_buf) - 4 */) {
|
||||||
@ -152,23 +153,28 @@ ssize_t __guac_write_base64_triplet(GUACIO* io, int a, int b, int c) {
|
|||||||
|
|
||||||
/* Byte 1 */
|
/* Byte 1 */
|
||||||
out_buf[io->written++] = __GUACIO_BASE64_CHARACTERS[(a & 0xFC) >> 2]; /* [AAAAAA]AABBBB BBBBCC CCCCCC */
|
out_buf[io->written++] = __GUACIO_BASE64_CHARACTERS[(a & 0xFC) >> 2]; /* [AAAAAA]AABBBB BBBBCC CCCCCC */
|
||||||
|
io->total_written++;
|
||||||
|
|
||||||
if (b >= 0) {
|
if (b >= 0) {
|
||||||
out_buf[io->written++] = __GUACIO_BASE64_CHARACTERS[((a & 0x03) << 4) | ((b & 0xF0) >> 4)]; /* AAAAAA[AABBBB]BBBBCC CCCCCC */
|
out_buf[io->written++] = __GUACIO_BASE64_CHARACTERS[((a & 0x03) << 4) | ((b & 0xF0) >> 4)]; /* AAAAAA[AABBBB]BBBBCC CCCCCC */
|
||||||
|
io->total_written++;
|
||||||
|
|
||||||
if (c >= 0) {
|
if (c >= 0) {
|
||||||
out_buf[io->written++] = __GUACIO_BASE64_CHARACTERS[((b & 0x0F) << 2) | ((c & 0xC0) >> 6)]; /* AAAAAA AABBBB[BBBBCC]CCCCCC */
|
out_buf[io->written++] = __GUACIO_BASE64_CHARACTERS[((b & 0x0F) << 2) | ((c & 0xC0) >> 6)]; /* AAAAAA AABBBB[BBBBCC]CCCCCC */
|
||||||
out_buf[io->written++] = __GUACIO_BASE64_CHARACTERS[c & 0x3F]; /* AAAAAA AABBBB BBBBCC[CCCCCC] */
|
out_buf[io->written++] = __GUACIO_BASE64_CHARACTERS[c & 0x3F]; /* AAAAAA AABBBB BBBBCC[CCCCCC] */
|
||||||
|
io->total_written += 2;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
out_buf[io->written++] = __GUACIO_BASE64_CHARACTERS[((b & 0x0F) << 2)]; /* AAAAAA AABBBB[BBBB--]------ */
|
out_buf[io->written++] = __GUACIO_BASE64_CHARACTERS[((b & 0x0F) << 2)]; /* AAAAAA AABBBB[BBBB--]------ */
|
||||||
out_buf[io->written++] = '='; /* AAAAAA AABBBB BBBB--[------] */
|
out_buf[io->written++] = '='; /* AAAAAA AABBBB BBBB--[------] */
|
||||||
|
io->total_written += 2;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
out_buf[io->written++] = __GUACIO_BASE64_CHARACTERS[((a & 0x03) << 4)]; /* AAAAAA[AA----]------ ------ */
|
out_buf[io->written++] = __GUACIO_BASE64_CHARACTERS[((a & 0x03) << 4)]; /* AAAAAA[AA----]------ ------ */
|
||||||
out_buf[io->written++] = '='; /* AAAAAA AA----[------]------ */
|
out_buf[io->written++] = '='; /* AAAAAA AA----[------]------ */
|
||||||
out_buf[io->written++] = '='; /* AAAAAA AA---- ------[------] */
|
out_buf[io->written++] = '='; /* AAAAAA AA---- ------[------] */
|
||||||
|
io->total_written += 3;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* At this point, 4 bytes have been io->written */
|
/* At this point, 4 bytes have been io->written */
|
||||||
|
Loading…
Reference in New Issue
Block a user