From 1aa594bd8b8e56b24f61adb718d68082f271f8fe Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Thu, 15 Mar 2012 11:30:52 -0700 Subject: [PATCH] __guac_fill_instructionbuf() should report errors. --- libguac/src/protocol.c | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/libguac/src/protocol.c b/libguac/src/protocol.c index 9644aa4f..47da5860 100644 --- a/libguac/src/protocol.c +++ b/libguac/src/protocol.c @@ -180,21 +180,28 @@ int __guac_fill_instructionbuf(guac_socket* socket) { /* Attempt to fill buffer */ retval = recv( - socket->fd, - socket->__instructionbuf + socket->__instructionbuf_used_length, - socket->__instructionbuf_size - socket->__instructionbuf_used_length, - 0 + socket->fd, + socket->__instructionbuf + socket->__instructionbuf_used_length, + socket->__instructionbuf_size - socket->__instructionbuf_used_length, + 0 ); - if (retval < 0) + /* Set guac_error if recv() unsuccessful */ + if (retval < 0) { + guac_error = GUAC_STATUS_SEE_ERRNO; + guac_error_message = "Error filling instruction buffer"; return retval; + } socket->__instructionbuf_used_length += retval; /* Expand buffer if necessary */ - if (socket->__instructionbuf_used_length > socket->__instructionbuf_size / 2) { + if (socket->__instructionbuf_used_length > + socket->__instructionbuf_size / 2) { + socket->__instructionbuf_size *= 2; - socket->__instructionbuf = realloc(socket->__instructionbuf, socket->__instructionbuf_size); + socket->__instructionbuf = realloc(socket->__instructionbuf, + socket->__instructionbuf_size); } return retval; @@ -203,7 +210,8 @@ int __guac_fill_instructionbuf(guac_socket* socket) { /* Returns new instruction if one exists, or NULL if no more instructions. */ -guac_instruction* guac_protocol_read_instruction(guac_socket* socket, int usec_timeout) { +guac_instruction* guac_protocol_read_instruction(guac_socket* socket, + int usec_timeout) { int retval;