Mercurial > pidgin.yaz
changeset 29895:1326fd4dfdc9
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.
author | Elliott Sales de Andrade <qulogic@pidgin.im> |
---|---|
date | Sun, 28 Feb 2010 08:22:12 +0000 |
parents | a0adf0bb19b7 |
children | 5802999803db |
files | libpurple/ft.c |
diffstat | 1 files changed, 19 insertions(+), 8 deletions(-) [+] |
line wrap: on
line diff
--- 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; + } } }