AT: Don't wait for a sync or an unsol request to return missing async status
authorPaul Kocialkowski <contact@paulk.fr>
Thu, 26 Jul 2012 21:22:40 +0000 (23:22 +0200)
committerPaul Kocialkowski <contact@paulk.fr>
Thu, 26 Jul 2012 21:22:40 +0000 (23:22 +0200)
Signed-off-by: Paul Kocialkowski <contact@paulk.fr>
at.c

diff --git a/at.c b/at.c
index 500c740..2356730 100644 (file)
--- a/at.c
+++ b/at.c
@@ -633,6 +633,8 @@ int at_request_expect_to_func_queue(struct at_async_request *request)
 
        at_responses_handling.async_queue.requests_count = count;
 
+       LOGD("%d elements left in the async queue", at_responses_handling.async_queue.requests_count);
+
        return 0;
 }
 
@@ -890,9 +892,9 @@ int at_response_expect_status(struct at_response *response)
        if(response == NULL)
                return -1;
 
-       if(at_responses_handling.sync_request == NULL) {
+       // If there is no request waiting for a status
+       if(at_responses_handling.sync_request == NULL && at_request_expect_to_func_find_handled(AT_RESPONSE_UNHANDELD_REASON_STATUS) == NULL)
                return -1;
-       }
 
        // If we get an unsol response while we expect a status, there is something going wrong
        if(response->command != NULL) {
@@ -907,7 +909,6 @@ int at_response_expect_status(struct at_response *response)
                }
        }
 
-
        if(response->status == AT_STATUS_UNDEF) {
                if((response->data == NULL || response->data_count <= 0) && response->command != NULL) {
                        rc = at_commands_compare(response->command, at_responses_handling.sync_request->command);
@@ -927,16 +928,23 @@ int at_response_expect_status(struct at_response *response)
                // If there is an async response that was unhandled because it lacked status, fill it
                request = at_request_expect_to_func_find_handled(AT_RESPONSE_UNHANDELD_REASON_STATUS);
                if(request != NULL) {
+                       LOGD("Found an async function that needs a status!");
+
                        request->status = response->status;
                        if(response->error != NULL)
                                request->error = strdup(response->error);
                        request->handled = AT_RESPONSE_WAITING;
 
-                       at_response_free(response);
-                       return 0;
+                       if(request->command != NULL)
+                               response->command = strdup(request->command);
+
+                       return -1;
                }
        }
 
+       if(at_responses_handling.sync_request == NULL)
+               return -1;
+
        at_responses_handling.sync_response = response;
 
        AT_SYNC_UNLOCK();