<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Sun, Aug 6, 2017 at 8:08 AM, Aleksander Morgado <span dir="ltr"><<a href="mailto:aleksander@aleksander.es" target="_blank">aleksander@aleksander.es</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Lets check if the operation timed out on the main state machine,<br>
instead of when the open command response is processed. This will<br>
allow us to queue up new steps sending/receiving messages and have<br>
a single place to check the timeout for all of them.<br></blockquote><div><br></div><div>lgtm</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
---<br>
 src/libmbim-glib/mbim-device.c | 39 ++++++++++++++++++++++++------<wbr>---------<br>
 1 file changed, 24 insertions(+), 15 deletions(-)<br>
<br>
diff --git a/src/libmbim-glib/mbim-<wbr>device.c b/src/libmbim-glib/mbim-<wbr>device.c<br>
index 4b7d431..775c2fd 100644<br>
--- a/src/libmbim-glib/mbim-<wbr>device.c<br>
+++ b/src/libmbim-glib/mbim-<wbr>device.c<br>
@@ -1214,14 +1214,16 @@ typedef enum {<br>
 } DeviceOpenContextStep;<br>
<br>
 typedef struct {<br>
-    DeviceOpenContextStep step;<br>
-    MbimDeviceOpenFlags flags;<br>
-    gint timeout;<br>
+    DeviceOpenContextStep  step;<br>
+    MbimDeviceOpenFlags    flags;<br>
+    guint                  timeout;<br>
+    GTimer                *timer;<br>
 } DeviceOpenContext;<br>
<br>
 static void<br>
 device_open_context_free (DeviceOpenContext *ctx)<br>
 {<br>
+    g_timer_destroy (ctx->timer);<br>
     g_slice_free (DeviceOpenContext, ctx);<br>
 }<br>
<br>
@@ -1278,20 +1280,14 @@ open_message_ready (MbimDevice   *self,<br>
<br>
     response = mbim_device_command_finish (self, res, &error);<br>
     if (!response) {<br>
-        /* Check if we should be retrying */<br>
+        /* Check if we should be retrying after a timeout */<br>
         if (g_error_matches (error, MBIM_CORE_ERROR, MBIM_CORE_ERROR_TIMEOUT)) {<br>
-            /* The timeout will tell us how many retries we should do */<br>
-            ctx->timeout -= RETRY_TIMEOUT_SECS;<br>
-            if (ctx->timeout > 0) {<br>
-                g_error_free (error);<br>
-                open_message (task);<br>
-                return;<br>
-            }<br>
-<br>
-            /* No more seconds left in the timeout... return error */<br>
+            /* Retry same step */<br>
+            device_open_context_step (task);<br>
+            return;<br>
         }<br>
<br>
-        g_debug ("open operation timed out: closed");<br>
+        g_debug ("error reported in open operation: closed");<br>
         self->priv->open_status = OPEN_STATUS_CLOSED;<br>
         g_task_return_error (task, error);<br>
         g_object_unref (task);<br>
@@ -1416,6 +1412,18 @@ device_open_context_step (GTask *task)<br>
     self = g_task_get_source_object (task);<br>
     ctx = g_task_get_task_data (task);<br>
<br>
+    /* Timed out? */<br>
+    if (g_timer_elapsed (ctx->timer, NULL) > ctx->timeout) {<br>
+        g_debug ("open operation timed out: closed");<br>
+        self->priv->open_status = OPEN_STATUS_CLOSED;<br>
+        g_task_return_new_error (task,<br>
+                                 MBIM_CORE_ERROR,<br>
+                                 MBIM_CORE_ERROR_TIMEOUT,<br>
+                                 "Operation timed out: device is closed");<br>
+        g_object_unref (task);<br>
+        return;<br>
+    }<br>
+<br>
     switch (ctx->step) {<br>
     case DEVICE_OPEN_CONTEXT_STEP_<wbr>FIRST:<br>
         if (self->priv->open_status == OPEN_STATUS_OPEN) {<br>
@@ -1512,10 +1520,11 @@ mbim_device_open_full (MbimDevice          *self,<br>
     g_return_if_fail (MBIM_IS_DEVICE (self));<br>
     g_return_if_fail (timeout > 0);<br>
<br>
-    ctx = g_slice_new (DeviceOpenContext);<br>
+    ctx = g_slice_new0 (DeviceOpenContext);<br>
     ctx->step = DEVICE_OPEN_CONTEXT_STEP_<wbr>FIRST;<br>
     ctx->flags = flags;<br>
     ctx->timeout = timeout;<br>
+    ctx->timer = g_timer_new ();<br>
<br>
     task = g_task_new (self, cancellable, callback, user_data);<br>
     g_task_set_task_data (task, ctx, (GDestroyNotify)device_open_<wbr>context_free);<br>
<span class="HOEnZb"><font color="#888888">--<br>
2.13.3<br>
<br>
</font></span></blockquote></div><br></div></div>