Support flushing of task queue after building message in task fails
authorMartin Willi <martin@revosec.ch>
Thu, 15 Dec 2011 17:23:28 +0000 (18:23 +0100)
committerMartin Willi <martin@revosec.ch>
Tue, 20 Mar 2012 16:31:24 +0000 (17:31 +0100)
src/libcharon/sa/task_manager_v1.c

index c10f63d..e18a070 100644 (file)
@@ -277,8 +277,7 @@ METHOD(task_manager_t, initiate, status_t,
        host_t *me, *other;
        status_t status;
        exchange_type_t exchange = EXCHANGE_TYPE_UNDEFINED;
-       bool new_mid = FALSE;
-       bool expect_response = FALSE;
+       bool new_mid = FALSE, expect_response = FALSE, flushed = FALSE;
 
        if (!this->rng)
        {
@@ -431,6 +430,7 @@ METHOD(task_manager_t, initiate, status_t,
                                continue;
                        case ALREADY_DONE:
                                flush_queue(this, this->active_tasks);
+                               flushed = TRUE;
                                break;
                        case FAILED:
                        default:
@@ -454,6 +454,11 @@ METHOD(task_manager_t, initiate, status_t,
        {       /* tasks completed, no exchange active anymore */
                this->initiating.type = EXCHANGE_TYPE_UNDEFINED;
        }
+       if (flushed)
+       {
+               message->destroy(message);
+               return initiate(this);
+       }
        this->initiating.seqnr++;
 
        status = this->ike_sa->generate_message(this->ike_sa, message,
@@ -512,7 +517,7 @@ static status_t build_response(private_task_manager_t *this, message_t *request)
        task_t *task;
        message_t *message;
        host_t *me, *other;
-       bool delete = FALSE;
+       bool delete = FALSE, flushed = FALSE;
        status_t status;
 
        me = request->get_destination(request);
@@ -549,6 +554,7 @@ static status_t build_response(private_task_manager_t *this, message_t *request)
                                continue;
                        case ALREADY_DONE:
                                flush_queue(this, this->passive_tasks);
+                               flushed = TRUE;
                                break;
                        case FAILED:
                        default:
@@ -563,9 +569,13 @@ static status_t build_response(private_task_manager_t *this, message_t *request)
        }
        enumerator->destroy(enumerator);
 
-       /* message complete, send it */
        DESTROY_IF(this->responding.packet);
        this->responding.packet = NULL;
+       if (flushed)
+       {
+               message->destroy(message);
+               return initiate(this);
+       }
        status = this->ike_sa->generate_message(this->ike_sa, message,
                                                                                        &this->responding.packet);
        message->destroy(message);