/soc/2015/mmcc/main: acd5549cf5d6: remove bytes_remaining from P...
Michael McConville
mmcconville at mykolab.com
Tue Jun 23 16:02:35 EDT 2015
Changeset: acd5549cf5d679395ba8d9d39803ac811d61a686
Author: Michael McConville <mmcconville at mykolab.com>
Date: 2015-06-23 16:02 -0400
Branch: default
URL: https://hg.pidgin.im/soc/2015/mmcc/main/rev/acd5549cf5d6
Description:
remove bytes_remaining from PurpleXferPrivate, fix transfer accounting with single completeness check
diffstat:
libpurple/xfer.c | 42 +++++++++++++++++++-----------------------
1 files changed, 19 insertions(+), 23 deletions(-)
diffs (132 lines):
diff --git a/libpurple/xfer.c b/libpurple/xfer.c
--- a/libpurple/xfer.c
+++ b/libpurple/xfer.c
@@ -69,7 +69,6 @@ struct _PurpleXferPrivate {
int watcher; /* Watcher. */
goffset bytes_sent; /* The number of bytes sent. */
- goffset bytes_remaining; /* The number of bytes remaining. */
time_t start_time; /* When the transfer of data began. */
time_t end_time; /* When the transfer of data ended. */
@@ -825,7 +824,7 @@ purple_xfer_get_bytes_remaining(const Pu
g_return_val_if_fail(priv != NULL, 0);
- return priv->bytes_remaining;
+ return priv->size - priv->bytes_sent;
}
goffset
@@ -1028,7 +1027,6 @@ purple_xfer_set_size(PurpleXfer *xfer, g
g_return_if_fail(priv != NULL);
priv->size = size;
- priv->bytes_remaining = priv->size - purple_xfer_get_bytes_sent(xfer);
g_object_notify_by_pspec(G_OBJECT(xfer), properties[PROP_FILE_SIZE]);
}
@@ -1054,9 +1052,6 @@ purple_xfer_set_bytes_sent(PurpleXfer *x
priv->bytes_sent = bytes_sent;
- if (purple_xfer_get_size(xfer) > 0)
- priv->bytes_remaining = purple_xfer_get_size(xfer) - bytes_sent;
-
g_object_notify_by_pspec(G_OBJECT(xfer), properties[PROP_BYTES_SENT]);
}
@@ -1229,10 +1224,6 @@ purple_xfer_write(PurpleXfer *xfer, cons
if (r < 0 && errno == EAGAIN)
r = 0;
}
- if (r >= 0 && (purple_xfer_get_bytes_sent(xfer)+r) >= purple_xfer_get_size(xfer) &&
- !purple_xfer_is_completed(xfer))
- purple_xfer_set_completed(xfer, TRUE);
-
return r;
}
@@ -1355,9 +1346,6 @@ do_transfer(PurpleXfer *xfer)
return;
}
- if ((purple_xfer_get_size(xfer) > 0) &&
- ((purple_xfer_get_bytes_sent(xfer)+r) >= purple_xfer_get_size(xfer)))
- purple_xfer_set_completed(xfer, TRUE);
} else if(r < 0) {
purple_xfer_cancel_remote(xfer);
g_free(buffer);
@@ -1450,8 +1438,6 @@ do_transfer(PurpleXfer *xfer)
}
if (r > 0) {
- purple_xfer_set_bytes_sent(xfer, priv->bytes_sent + r);
-
if (priv->ops.ack != NULL)
priv->ops.ack(xfer, buffer, r);
@@ -1462,8 +1448,14 @@ do_transfer(PurpleXfer *xfer)
purple_xfer_get_progress(xfer));
}
- if (purple_xfer_is_completed(xfer))
+ if (purple_xfer_get_bytes_sent(xfer) >= purple_xfer_get_size(xfer) &&
+ !purple_xfer_is_completed(xfer)) {
+ purple_xfer_set_completed(xfer, TRUE);
+ }
+
+ if (purple_xfer_is_completed(xfer)) {
purple_xfer_end(xfer);
+ }
}
static void
@@ -1652,6 +1644,7 @@ void
purple_xfer_end(PurpleXfer *xfer)
{
PurpleXferPrivate *priv = PURPLE_XFER_GET_PRIVATE(xfer);
+ int err;
g_return_if_fail(priv != NULL);
@@ -1673,11 +1666,18 @@ purple_xfer_end(PurpleXfer *xfer)
purple_xfer_set_watcher(xfer, 0);
}
- if (priv->fd != -1)
- close(priv->fd);
+ if (priv->fd != -1) {
+ err = close(priv->fd);
+ if (err != 0) {
+ purple_debug_error("xfer", "closing file descr in purple_xfer_end() failed");
+ }
+ }
if (priv->dest_fp != NULL) {
- fclose(priv->dest_fp);
+ err = fclose(priv->dest_fp);
+ if (err != 0) {
+ purple_debug_error("xfer", "closing dest file in purple_xfer_end() failed");
+ }
priv->dest_fp = NULL;
}
@@ -1766,8 +1766,6 @@ purple_xfer_cancel_local(PurpleXfer *xfe
if (ui_ops != NULL && ui_ops->cancel_local != NULL)
ui_ops->cancel_local(xfer);
- priv->bytes_remaining = 0;
-
g_object_unref(xfer);
}
@@ -1834,8 +1832,6 @@ purple_xfer_cancel_remote(PurpleXfer *xf
if (ui_ops != NULL && ui_ops->cancel_remote != NULL)
ui_ops->cancel_remote(xfer);
- priv->bytes_remaining = 0;
-
g_object_unref(xfer);
}
More information about the Commits
mailing list