comparison libpurple/ft.c @ 29497: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 422889fb57e0
children 1cc870f328ab
comparison
equal deleted inserted replaced
29496:a0adf0bb19b7 29497:1326fd4dfdc9
1083 purple_xfer_cancel_remote(xfer); 1083 purple_xfer_cancel_remote(xfer);
1084 g_free(buffer); 1084 g_free(buffer);
1085 return; 1085 return;
1086 } 1086 }
1087 } else if (xfer->type == PURPLE_XFER_SEND) { 1087 } else if (xfer->type == PURPLE_XFER_SEND) {
1088 size_t result; 1088 size_t result = 0;
1089 size_t s = MIN(purple_xfer_get_bytes_remaining(xfer), xfer->current_buffer_size); 1089 size_t s = MIN(purple_xfer_get_bytes_remaining(xfer), xfer->current_buffer_size);
1090 PurpleXferPrivData *priv = g_hash_table_lookup(xfers_data, xfer); 1090 PurpleXferPrivData *priv = g_hash_table_lookup(xfers_data, xfer);
1091 1091
1092 /* this is so the prpl can keep the connection open 1092 /* this is so the prpl can keep the connection open
1093 if it needs to for some odd reason. */ 1093 if it needs to for some odd reason. */
1128 return; 1128 return;
1129 } 1129 }
1130 1130
1131 result = tmp; 1131 result = tmp;
1132 } else { 1132 } else {
1133 buffer = g_malloc0(s); 1133 gboolean read = TRUE;
1134 result = fread(buffer, 1, s, xfer->dest_fp); 1134 if (priv->buffer) {
1135 if (result != s) { 1135 if (priv->buffer->len < s) {
1136 purple_debug_error("filetransfer", "Unable to read whole buffer.\n"); 1136 s -= priv->buffer->len;
1137 purple_xfer_cancel_local(xfer); 1137 read = TRUE;
1138 g_free(buffer); 1138 } else {
1139 return; 1139 read = FALSE;
1140 }
1141 }
1142 if (read) {
1143 buffer = g_malloc(s);
1144 result = fread(buffer, 1, s, xfer->dest_fp);
1145 if (result != s) {
1146 purple_debug_error("filetransfer", "Unable to read whole buffer.\n");
1147 purple_xfer_cancel_local(xfer);
1148 g_free(buffer);
1149 return;
1150 }
1140 } 1151 }
1141 } 1152 }
1142 1153
1143 if (priv->buffer) { 1154 if (priv->buffer) {
1144 priv->buffer = g_byte_array_append(priv->buffer, buffer, result); 1155 priv->buffer = g_byte_array_append(priv->buffer, buffer, result);