AT: Check async requests before canceling a sync request
authorPaul Kocialkowski <contact@paulk.fr>
Wed, 25 Jul 2012 17:10:14 +0000 (19:10 +0200)
committerPaul Kocialkowski <contact@paulk.fr>
Wed, 25 Jul 2012 17:10:14 +0000 (19:10 +0200)
Signed-off-by: Paul Kocialkowski <contact@paulk.fr>
at.c

diff --git a/at.c b/at.c
index 1a2b650..3e0b6b3 100644 (file)
--- a/at.c
+++ b/at.c
@@ -684,7 +684,7 @@ int at_request_expect_to_func(char *command, void *data, RIL_Token t, at_async_r
        return 0;
 }
 
-int at_response_expect_to_func(struct at_response *response)
+struct at_async_request *at_request_expect_to_func_find(char *command)
 {
        struct at_async_request *request = NULL;
        struct at_async_request **requests = NULL;
@@ -692,8 +692,8 @@ int at_response_expect_to_func(struct at_response *response)
        int rc;
        int i;
 
-       if(response == NULL)
-               return -1;
+       if(command == NULL)
+               return NULL;
 
        AT_ASYNC_LOCK();
 
@@ -703,13 +703,13 @@ int at_response_expect_to_func(struct at_response *response)
 
        if(requests == NULL) {
                AT_ASYNC_UNLOCK();
-               return -1;
+               return NULL;
        }
 
        for(i=0 ; i < requests_count ; i++) {
                if(requests[i] != NULL) {
-                       if(requests[i]->command != NULL && response->command != NULL) {
-                               rc = at_commands_compare(response->command, requests[i]->command);
+                       if(requests[i]->command != NULL) {
+                               rc = at_commands_compare(command, requests[i]->command);
                                if(rc) {
                                        LOGD("Found a matching request!");
                                        request = requests[i];
@@ -719,14 +719,24 @@ int at_response_expect_to_func(struct at_response *response)
                }
        }
 
+       AT_ASYNC_UNLOCK();
+
+       return request;
+}
+
+int at_response_expect_to_func(struct at_response *response)
+{
+       struct at_async_request *request = NULL;
+       int rc;
+
+       if(response == NULL || response->command == NULL)
+               return -1;
+
+       request = at_request_expect_to_func_find(response->command);
        if(request == NULL || request->func == NULL) {
-               LOGD("Found no valid matching request, aborting!");
-               AT_ASYNC_UNLOCK();
                return -1;
        }
 
-       AT_ASYNC_UNLOCK();
-
        // This must run out of any mutex
        rc = request->func(response, request->data, request->token);
 
@@ -817,7 +827,10 @@ int at_expect_status(struct at_request *request)
        if(at_responses_handling.sync_response->command != NULL) {
                rc = at_commands_compare(at_responses_handling.sync_response->command, request->command);
                if(!rc) {
-                       LOGE("Obtained command doesn't match, aborting!");
+                       // Only fail is there is no async request waiting with this command!
+                       if(at_request_expect_to_func_find(at_responses_handling.sync_response->command) != NULL)
+                               LOGE("Obtained command doesn't match, aborting!");
+
                        return -1;
                }
        }