[Spice-commits] src/channel-main.c

Pavel Grunt pgrunt at kemper.freedesktop.org
Wed Sep 9 00:02:11 PDT 2015


 src/channel-main.c |   26 +++++++++-----------------
 1 file changed, 9 insertions(+), 17 deletions(-)

New commits:
commit c32ca1aa824dd3aa6be5dee4d328f83987412a06
Author: Pavel Grunt <pgrunt at redhat.com>
Date:   Tue Aug 25 18:39:53 2015 +0200

    file-xfer: Simplify time handling
    
    Use g_get_monotonic_time() instead of g_date_time_new_now_local().
    g_get_monotonic_time doesn't suffer discontinuities and it is sufficient
    for our purposes. There is no need for the complexity of GDateTime.

diff --git a/src/channel-main.c b/src/channel-main.c
index 145b081..42c9a65 100644
--- a/src/channel-main.c
+++ b/src/channel-main.c
@@ -71,8 +71,8 @@ typedef struct SpiceFileXferTask {
     char                           buffer[FILE_XFER_CHUNK_SIZE];
     uint64_t                       read_bytes;
     uint64_t                       file_size;
-    GDateTime                      *start_time;
-    GDateTime                      *last_update;
+    gint64                         start_time;
+    gint64                         last_update;
     GError                         *error;
 } SpiceFileXferTask;
 
@@ -1699,10 +1699,6 @@ static void file_xfer_task_free(SpiceFileXferTask *task)
     g_clear_object(&task->channel);
     g_clear_object(&task->file);
     g_clear_object(&task->file_stream);
-    if (spice_util_get_debug()) {
-        g_date_time_unref(task->start_time);
-        g_date_time_unref(task->last_update);
-    }
     g_free(task);
 }
 
@@ -1739,10 +1735,9 @@ static void file_xfer_close_cb(GObject      *object,
     } else {
         g_simple_async_result_set_op_res_gboolean(res, TRUE);
         if (spice_util_get_debug()) {
-            GDateTime *now = g_date_time_new_now_local();
+            gint64 now = g_get_monotonic_time();
             gchar *basename = g_file_get_basename(task->file);
-            double seconds =
-                (double) g_date_time_difference(now, task->start_time) / G_TIME_SPAN_SECOND;
+            double seconds = (double) (now - task->start_time) / G_TIME_SPAN_SECOND;
             gchar *file_size_str = g_format_size(task->file_size);
             gchar *transfer_speed_str = g_format_size(task->file_size / seconds);
 
@@ -1753,7 +1748,6 @@ static void file_xfer_close_cb(GObject      *object,
             g_free(basename);
             g_free(file_size_str);
             g_free(transfer_speed_str);
-            g_date_time_unref(now);
         }
     }
     g_simple_async_result_complete_in_idle(res);
@@ -1779,17 +1773,15 @@ static void file_xfer_data_flushed_cb(GObject *source_object,
 
     if (spice_util_get_debug()) {
         const GTimeSpan interval = 20 * G_TIME_SPAN_SECOND;
-        GDateTime *now = g_date_time_new_now_local();
+        gint64 now = g_get_monotonic_time();
 
-        if (interval < g_date_time_difference(now, task->last_update)) {
+        if (interval < now - task->last_update) {
             gchar *basename = g_file_get_basename(task->file);
-            g_date_time_unref(task->last_update);
-            task->last_update = g_date_time_ref(now);
+            task->last_update = now;
             SPICE_DEBUG("transferred %.2f%% of the file %s",
                         100.0 * task->read_bytes / task->file_size, basename);
             g_free(basename);
         }
-        g_date_time_unref(now);
     }
 
     if (task->progress_callback)
@@ -2958,8 +2950,8 @@ static void file_xfer_send_start_msg_async(SpiceMainChannel *channel,
 
         if (spice_util_get_debug()) {
             gchar *basename = g_file_get_basename(task->file);
-            task->start_time = g_date_time_new_now_local();
-            task->last_update = g_date_time_ref(task->start_time);
+            task->start_time = g_get_monotonic_time();
+            task->last_update = task->start_time;
 
             SPICE_DEBUG("transfer of file %s has started", basename);
             g_free(basename);


More information about the Spice-commits mailing list