diff options
author | Aleksander Morgado <aleksander@lanedo.com> | 2012-06-29 15:13:30 +0200 |
---|---|---|
committer | Aleksander Morgado <aleksander@lanedo.com> | 2012-07-03 16:08:58 +0200 |
commit | b39e73880033c293e750a411f7625fe2b7cfe6fa (patch) | |
tree | 7472237357614b3e1401a365883c190910819e95 | |
parent | f69785ff789dedc2387bf15e6de42f1b1b0924fb (diff) |
device: when opening, run several version checks if requested
When early requests arrive to the modem, when it is still internally
initializing, the modem may completely discard the requests and our
actions get timed out.
In order to try to avoid that, instead of a single version-check with
N seconds timeout, we'll try N version-check requests with 1s timeout.
-rw-r--r-- | src/qmi-device.c | 24 |
1 files changed, 22 insertions, 2 deletions
diff --git a/src/qmi-device.c b/src/qmi-device.c index 36bdf44..8ed3bd4 100644 --- a/src/qmi-device.c +++ b/src/qmi-device.c @@ -1082,6 +1082,7 @@ typedef struct { GCancellable *cancellable; QmiDeviceOpenFlags flags; guint timeout; + guint version_check_retries; } DeviceOpenContext; static void @@ -1160,6 +1161,23 @@ version_info_ready (QmiClientCtl *client_ctl, /* Check result of the async operation */ output = qmi_client_ctl_get_version_info_finish (client_ctl, res, &error); if (!output) { + if (g_error_matches (error, QMI_CORE_ERROR, QMI_CORE_ERROR_TIMEOUT)) { + /* Update retries... */ + ctx->version_check_retries--; + /* If retries left, retry */ + if (ctx->version_check_retries > 0) { + qmi_client_ctl_get_version_info (ctx->self->priv->client_ctl, + NULL, + 1, + ctx->cancellable, + (GAsyncReadyCallback)version_info_ready, + ctx); + return; + } + + /* Otherwise, propagate the error */ + } + g_simple_async_result_take_error (ctx->result, error); device_open_context_complete_and_free (ctx); return; @@ -1206,11 +1224,13 @@ process_open_flags (DeviceOpenContext *ctx) { /* Query version info? */ if (ctx->flags & QMI_DEVICE_OPEN_FLAGS_VERSION_INFO) { - g_debug ("Checking version info..."); ctx->flags &= ~QMI_DEVICE_OPEN_FLAGS_VERSION_INFO; + /* Setup how many times to retry... We'll retry once per second */ + ctx->version_check_retries = ctx->timeout > 0 ? ctx->timeout : 1; + g_debug ("Checking version info (%u retries)...", ctx->version_check_retries); qmi_client_ctl_get_version_info (ctx->self->priv->client_ctl, NULL, - ctx->timeout, + 1, ctx->cancellable, (GAsyncReadyCallback)version_info_ready, ctx); |