From: Daniel Wagner <[email protected]>

We need to track the Connect()/Disconnect() on a global session level
and not only in the info. This is needed when we were not able to
select and connect to a matching service in the first place. It might
happen that a valid service is added in time and then we want to use
it.
---
 src/session.c |   19 ++++++++++++++++++-
 1 files changed, 18 insertions(+), 1 deletions(-)

diff --git a/src/session.c b/src/session.c
index d9da3c3..a9edd2c 100644
--- a/src/session.c
+++ b/src/session.c
@@ -84,6 +84,7 @@ struct session_info {
        unsigned int marker;
 
        struct service_entry *entry;
+       enum connman_session_reason reason;
 };
 
 struct connman_session {
@@ -655,8 +656,8 @@ static void cleanup_session(gpointer user_data)
 
        DBG("remove %s", session->session_path);
 
-       g_hash_table_destroy(session->service_hash);
        g_sequence_free(session->service_list);
+       g_hash_table_destroy(session->service_hash);
 
        if (info->entry != NULL &&
                        info->entry->reason == CONNMAN_SESSION_REASON_CONNECT) {
@@ -769,6 +770,8 @@ static void select_and_connect(struct connman_session 
*session,
 
        DBG("session %p reason %s", session, reason2string(reason));
 
+       info->reason = reason;
+
        iter = g_sequence_get_begin_iter(session->service_list);
 
        while (g_sequence_iter_is_end(iter) == FALSE) {
@@ -887,6 +890,20 @@ static void session_changed(struct connman_session 
*session,
                        break;
                }
 
+               if (info->reason == CONNMAN_SESSION_REASON_CONNECT) {
+                       DBG("Retry to find a matching session");
+                       /*
+                        * The user called Connect() but there was no
+                        * matching session available at this point.
+                        * Now there might be a new one. Let's retry
+                        * to select and connect
+                        */
+                       select_and_connect(session,
+                                       CONNMAN_SESSION_REASON_CONNECT);
+
+                       break;
+               }
+
                if (info->stay_connected == TRUE) {
                        DBG("StayConnected");
                        select_and_connect(session,
-- 
1.7.6

_______________________________________________
connman mailing list
[email protected]
http://lists.connman.net/listinfo/connman

Reply via email to