incubator-etch-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fitz...@apache.org
Subject svn commit: r1032943 - /incubator/etch/trunk/binding-c/runtime/c/src/main/transport/etch_plain_mailbox_manager.c
Date Tue, 09 Nov 2010 11:53:52 GMT
Author: fitzner
Date: Tue Nov  9 11:53:52 2010
New Revision: 1032943

URL: http://svn.apache.org/viewvc?rev=1032943&view=rev
Log:
[ETCH-114] Bug fix plain_mailbox_manager; do cleanup all registered mailboxes if connection
goes down

Modified:
    incubator/etch/trunk/binding-c/runtime/c/src/main/transport/etch_plain_mailbox_manager.c

Modified: incubator/etch/trunk/binding-c/runtime/c/src/main/transport/etch_plain_mailbox_manager.c
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-c/runtime/c/src/main/transport/etch_plain_mailbox_manager.c?rev=1032943&r1=1032942&r2=1032943&view=diff
==============================================================================
--- incubator/etch/trunk/binding-c/runtime/c/src/main/transport/etch_plain_mailbox_manager.c
(original)
+++ incubator/etch/trunk/binding-c/runtime/c/src/main/transport/etch_plain_mailbox_manager.c
Tue Nov  9 11:53:52 2010
@@ -645,18 +645,20 @@ int pmboxmgr_unregister (void* data, i_m
 int pmboxmgr_register_mailbox(etch_plainmailboxmgr* mgr, i_mailbox* ibox)
 {
     int result = -1;
+    etch_hashtable* mboxs = mgr->mailboxes;
 
-    if (mgr->is_connection_up)
-    {   etch_hashtable* map = mgr->mailboxes;
+    hashtable_getlock(mboxs);
+    if (mgr->is_connection_up) {
         int64 message_id  = ibox->get_message_id(ibox);
         etch_int64* idobj = new_int64(message_id);
         /* insert mailbox to synchronized map */
         ((etch_object*)idobj)->get_hashkey(idobj);
-        result = ((struct i_hashtable*)((etch_object*)map)->vtab)->inserth(map->realtable,
idobj, ibox, map, 0);
+        result = ((struct i_hashtable*)((etch_object*)mboxs)->vtab)->inserth(mboxs->realtable,
idobj, ibox, mboxs, 0);
         if (-1 == result) etch_free(idobj); /* duplicate id */
     }
     else
         ETCH_LOG(LOG_CATEGORY, ETCH_LOG_ERROR, "attempt to register disconnected mailbox\n");
+    hashtable_rellock(mboxs);
 
     return result;
 }
@@ -684,19 +686,33 @@ int pmboxmgr_register_mailbox(etch_plain
 {
     etch_hashtable* map = mgr->mailboxes;
     etch_iterator iterator;
+    i_mailbox** mboxs = NULL;
+    int count = 0;
+    int i = 0;
+    
     hashtable_getlock(map);
-    set_iterator(&iterator, map, &map->iterable);
+    count = pmboxmgr_size(mgr);
+    if(count != 0) {
+        mboxs = malloc(sizeof(i_mailbox*) * count);
+        // copy mailboxes
+        set_iterator(&iterator, map, &map->iterable);
+        while(iterator.has_next(&iterator)) {
+            i_mailbox* ibox = (i_mailbox*) iterator.current_value;
+            mboxs[i++] = ibox;
+            iterator.next(&iterator);
+        }
+    }
+    hashtable_rellock(map);
 
-    while(iterator.has_next(&iterator))
-    {
-        i_mailbox* ibox = (i_mailbox*) iterator.current_value;
-        if (ibox)
+    // close delivery
+    for(i = 0; i < count; i++) {
+        i_mailbox* ibox = mboxs[i];
+        if(ibox != NULL) {
             ibox->close_delivery(ibox);
-
-        iterator.next(&iterator);
+        }
     }
+    free(mboxs);
 
-    hashtable_rellock(map);
     return 0;
 }
 



Mime
View raw message