message -> instruction ... terminology fix

This commit is contained in:
Michael Jumper
2010-09-06 19:47:55 -07:00
parent e1e0045085
commit 2bf6651fb3
5 changed files with 51 additions and 51 deletions

View File

@@ -29,10 +29,10 @@ GUACIO* guac_open(int fd) {
flags = fcntl(io->fd, F_GETFL, 0);
fcntl(io->fd, F_SETFL, flags | O_NONBLOCK);
/* Allocate message buffer */
io->messagebuf_size = 1024;
io->messagebuf = malloc(io->messagebuf_size);
io->messagebuf_used_length = 0;
/* Allocate instruction buffer */
io->instructionbuf_size = 1024;
io->instructionbuf = malloc(io->instructionbuf_size);
io->instructionbuf_used_length = 0;
return io;

View File

@@ -14,9 +14,9 @@ typedef struct GUACIO {
int written;
char out_buf[8192];
int messagebuf_size;
int messagebuf_used_length;
char* messagebuf;
int instructionbuf_size;
int instructionbuf_used_length;
char* instructionbuf;
} GUACIO;

View File

@@ -176,76 +176,76 @@ void guac_send_png(GUACIO* io, int x, int y, png_byte** png_rows, int w, int h)
}
int __guac_fill_messagebuf(GUACIO* io) {
int __guac_fill_instructionbuf(GUACIO* io) {
int retval;
/* Attempt to fill buffer */
retval = read(
io->fd,
io->messagebuf + io->messagebuf_used_length,
io->messagebuf_size - io->messagebuf_used_length
io->instructionbuf + io->instructionbuf_used_length,
io->instructionbuf_size - io->instructionbuf_used_length
);
if (retval < 0)
return retval;
io->messagebuf_used_length += retval;
io->instructionbuf_used_length += retval;
/* Expand buffer if necessary */
if (io->messagebuf_used_length > io->messagebuf_size / 2) {
io->messagebuf_size *= 2;
io->messagebuf = realloc(io->messagebuf, io->messagebuf_size);
if (io->instructionbuf_used_length > io->instructionbuf_size / 2) {
io->instructionbuf_size *= 2;
io->instructionbuf = realloc(io->instructionbuf, io->instructionbuf_size);
}
return retval;
}
guac_message* guac_read_message(GUACIO* io) {
guac_instruction* guac_read_instruction(GUACIO* io) {
guac_message* parsed_message;
guac_instruction* parsed_instruction;
int retval;
int i = 0;
/* Loop until a message is read */
/* Loop until a instruction is read */
for (;;) {
/* Search for end of message */
for (; i < io->messagebuf_used_length; i++) {
/* Search for end of instruction */
for (; i < io->instructionbuf_used_length; i++) {
if (io->messagebuf[i] == ';') {
if (io->instructionbuf[i] == ';') {
/* Parse new message */
char* message = malloc(i+1);
memcpy(message, io->messagebuf, i+1);
message[i] = '\0'; /* Replace semicolon with null terminator. */
/* Parse new instruction */
char* instruction = malloc(i+1);
memcpy(instruction, io->instructionbuf, i+1);
instruction[i] = '\0'; /* Replace semicolon with null terminator. */
parsed_message = malloc(sizeof(guac_message));
parsed_message->opcode = message;
parsed_message->argc = 0;
parsed_message->argv = NULL;
parsed_instruction = malloc(sizeof(guac_instruction));
parsed_instruction->opcode = instruction;
parsed_instruction->argc = 0;
parsed_instruction->argv = NULL;
/* Found. Reset buffer */
memmove(io->messagebuf, io->messagebuf + i + 1, io->messagebuf_used_length - i - 1);
io->messagebuf_used_length -= i + 1;
memmove(io->instructionbuf, io->instructionbuf + i + 1, io->instructionbuf_used_length - i - 1);
io->instructionbuf_used_length -= i + 1;
/* Done */
return parsed_message;
return parsed_instruction;
}
}
/* No message yet? Get more data ... */
/* No instruction yet? Get more data ... */
retval = guac_select(io, 1000);
if (retval < 0)
return NULL;
/* Break if descriptor doesn't have enough data */
if (retval == 0)
return NULL; /* SOFT FAIL: No message ... yet, but is still in buffer */
return NULL; /* SOFT FAIL: No instruction ... yet, but is still in buffer */
retval = __guac_fill_messagebuf(io);
retval = __guac_fill_instructionbuf(io);
if (retval < 0 && errno != EAGAIN && errno != EWOULDBLOCK)
return NULL;
@@ -253,19 +253,19 @@ guac_message* guac_read_message(GUACIO* io) {
}
void guac_free_message(guac_message* message) {
free(message->opcode);
void guac_free_instruction(guac_instruction* instruction) {
free(instruction->opcode);
if (message->argv)
free(message->argv);
if (instruction->argv)
free(instruction->argv);
free(message);
free(instruction);
}
int guac_messages_waiting(GUACIO* io) {
int guac_instructions_waiting(GUACIO* io) {
if (io->messagebuf_used_length > 0)
if (io->instructionbuf_used_length > 0)
return 1;
return guac_select(io, 1000);

View File

@@ -6,25 +6,25 @@
#include "guacio.h"
typedef struct guac_message {
typedef struct guac_instruction {
char* opcode;
int argc;
char** argv;
} guac_message;
} guac_instruction;
void guac_free_message(guac_message* message);
void guac_free_instruction(guac_instruction* instruction);
char* guac_escape_string(const char* str);
void guac_send_name(GUACIO* io, const char* name);
void guac_send_size(GUACIO* io, int w, int h);
void guac_send_copy(GUACIO* io, int srcx, int srcy, int w, int h, int dstx, int dsty);
void guac_send_png(GUACIO* io, int x, int y, png_byte** png_rows, int w, int h);
int guac_messages_waiting(GUACIO* io);
guac_message* guac_read_message(GUACIO* io);
int guac_instructions_waiting(GUACIO* io);
guac_instruction* guac_read_instruction(GUACIO* io);
#endif

View File

@@ -179,12 +179,12 @@ void proxy(int client_fd) {
}
wait_result = guac_messages_waiting(io);
wait_result = guac_instructions_waiting(io);
if (wait_result > 0) {
guac_message* message = guac_read_message(io);
if (message) {
fprintf(stderr, "NEW READ MESSAGE: %s\n", message->opcode);
guac_free_message(message);
guac_instruction* instruction = guac_read_instruction(io);
if (instruction) {
fprintf(stderr, "NEW READ INSTRUCTION: %s\n", instruction->opcode);
guac_free_instruction(instruction);
}
}