ft: Don't try to read from the source file if the byte array already holds

Sun, 28 Feb 2010 08:22:12 +0000

author
Elliott Sales de Andrade <qulogic@pidgin.im>
date
Sun, 28 Feb 2010 08:22:12 +0000
changeset 29781
5ef6c9b585f8
parent 29780
9e5649728df5
child 29786
7f1b7429119c

ft: Don't try to read from the source file if the byte array already holds
enough data for the current write. I'm not sure if this check should be
added to the UI read side too.

libpurple/ft.c file | annotate | diff | comparison | revisions
--- a/libpurple/ft.c	Sun Feb 28 06:46:32 2010 +0000
+++ b/libpurple/ft.c	Sun Feb 28 08:22:12 2010 +0000
@@ -1085,7 +1085,7 @@
 			return;
 		}
 	} else if (xfer->type == PURPLE_XFER_SEND) {
-		size_t result;
+		size_t result = 0;
 		size_t s = MIN(purple_xfer_get_bytes_remaining(xfer), xfer->current_buffer_size);
 		PurpleXferPrivData *priv = g_hash_table_lookup(xfers_data, xfer);
 
@@ -1130,13 +1130,24 @@
 
 			result = tmp;
 		} else {
-			buffer = g_malloc0(s);
-			result = fread(buffer, 1, s, xfer->dest_fp);
-			if (result != s) {
-				purple_debug_error("filetransfer", "Unable to read whole buffer.\n");
-				purple_xfer_cancel_local(xfer);
-				g_free(buffer);
-				return;
+			gboolean read = TRUE;
+			if (priv->buffer) {
+				if (priv->buffer->len < s) {
+					s -= priv->buffer->len;
+					read = TRUE;
+				} else {
+					read = FALSE;
+				}
+			}
+			if (read) {
+				buffer = g_malloc(s);
+				result = fread(buffer, 1, s, xfer->dest_fp);
+				if (result != s) {
+					purple_debug_error("filetransfer", "Unable to read whole buffer.\n");
+					purple_xfer_cancel_local(xfer);
+					g_free(buffer);
+					return;
+				}
 			}
 		}
 	

mercurial