pidgin: d6b03d30: ft: Don't try to read from the source fi...

qulogic at pidgin.im qulogic at pidgin.im
Sun Feb 28 03:35:32 EST 2010


-----------------------------------------------------------------
Revision: d6b03d30f4751e3fa383c0e15a03515536f9b57c
Ancestor: b720fa4847a76b6b396861200c0abd6d2d90d4be
Author: qulogic at pidgin.im
Date: 2010-02-28T08:22:12
Branch: im.pidgin.pidgin
URL: http://d.pidgin.im/viewmtn/revision/info/d6b03d30f4751e3fa383c0e15a03515536f9b57c

Modified files:
        libpurple/ft.c

ChangeLog: 

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.

-------------- next part --------------
============================================================
--- libpurple/ft.c	f590937c4f192f2c5ea20f9272aaba96cf9e7345
+++ libpurple/ft.c	3431026e58910a3b731ff08b977596630f57aad8
@@ -1085,7 +1085,7 @@ do_transfer(PurpleXfer *xfer)
 			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,14 +1130,25 @@ do_transfer(PurpleXfer *xfer)
 
 			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;
+				}
+			}
 		}
 	
 		if (priv->buffer) {


More information about the Commits mailing list