]> rtime.felk.cvut.cz Git - frescor/forb.git/commitdiff
forb: Split forb_port_destroy() to stop and destroy phases master
authorMichal Sojka <sojkam1@fel.cvut.cz>
Fri, 25 Feb 2011 07:20:28 +0000 (08:20 +0100)
committerMichal Sojka <sojkam1@fel.cvut.cz>
Fri, 25 Feb 2011 07:20:28 +0000 (08:20 +0100)
This allows for proper termination of forb. Now, there are no leaked
file descriptors in the tests.

src/discovery.c
src/forb.c
src/port.c
src/port.h

index 90196655c84e3bbd771748c19caff411f83f7c0b..ae2b88c5e558cca05e64d76b2898949a1657aee0 100644 (file)
@@ -268,6 +268,9 @@ void forb_peer_disconnected(forb_peer_t *peer)
 {
        forb_peer_delete(peer->port->forb, peer);
        forb_port_peer_delete(peer->port, peer);
-       forb_peer_put(peer);    /* This should release the peer and in case on proto_inet close the socker. */
+
+       /* This should release the peer and in case on proto_inet
+        * close the socket. */
+       forb_peer_put(peer);
 }
 
index 376651f44c269482d91d28848ae54e1223cf2bbf..309c6602e8f8b5a84b469be748058385e5b76e5e 100644 (file)
@@ -302,13 +302,13 @@ void forb_destroy(forb_orb orb)
        forb_regref_t *regref;
        forb_object obj;
 
-       /* Destroy ports to prevent remote requests from coming */
-       ul_list_for_each_cut(forb_port, forb, port) {
-               forb_destroy_port(port);
+       /* Stop ports to prevent remote requests from coming */
+       ul_list_for_each(forb_port, forb, port) {
+               forb_stop_port(port);
        }
 
-       /* Wait for executors to finish all requests (and thus close
-        * connections to peers). This is very inefficient for big
+       /* Wait for executors to finish all requests (and thus drop
+        * all references to peers). This is very inefficient for big
         * number of objects, but we do not care */
        gavl_cust_for_each(forb_objects_nolock, forb, obj) {
                forb_executor_t *executor;
@@ -317,6 +317,13 @@ void forb_destroy(forb_orb orb)
                        forb_executor_synchronize(executor);
        }
 
+       /* Destroy ports - this should drop all remaining references
+        * to peers and result in closing of all remote
+        * connections. */
+       ul_list_for_each_cut(forb_port, forb, port) {
+               forb_destroy_port(port);
+       }
+
        pthread_cancel(forb->execution_thread.pthread_id);
        pthread_join(forb->execution_thread.pthread_id, NULL);
        
index 637c22e3892b35081308162949355de57d8de18b..029f593faecf1e128d169fa8d8c177c1c59889c0 100644 (file)
@@ -140,13 +140,12 @@ err:
 }
 
 /** 
- * Destroys the port and all resources associated with it.
+ * Stop receiving requests on the port.
  * 
  * @param port 
  */
-void forb_destroy_port(forb_port_t *port)
+void forb_stop_port(forb_port_t *port)
 {
-       forb_t *forb = port->forb;
        void *thread_return;
 
        port->finish = true;    /* Exit all the threads */
@@ -157,8 +156,9 @@ void forb_destroy_port(forb_port_t *port)
        /* FIXME: Canceling discovery thread sometimes didn't
         * work. The discovery thread stayed forever in the
         * pthread_cond_timedwait(). */
-       //pthread_cancel(port->discovery_thread.pthread_id);
-
+#ifndef CONFIG_FORB_PROTO_INET_DEFAULT
+       pthread_cancel(port->discovery_thread.pthread_id);
+#endif
        /* Sometimes, cancelation doesn't work and the
         * discovery_thread hangs in pthread_cond_timedwait
         * infinitely. */
@@ -168,7 +168,18 @@ void forb_destroy_port(forb_port_t *port)
 #ifndef CONFIG_FORB_PROTO_INET_DEFAULT
        pthread_join(port->discovery_thread.pthread_id, &thread_return);
 #endif
+}
+
 
+/** 
+ * Destroys the port and all resources associated with it.
+ * 
+ * @param port 
+ */
+void forb_destroy_port(forb_port_t *port)
+{
+       forb_t *forb = port->forb;
+       
        /* Because of no locking of port->peers, this must be called
         * after receiver thread is stopped. */
        forb_peer_t *peer;
index b5b97fa90517580ff6cb1fc460c4e7880aecbaa2..4d0d010c8a6d2bdf9b10bcf34f0f33ad922668f7 100644 (file)
@@ -108,6 +108,7 @@ UL_LIST_CUST_DEC(forb_port, /* cust_prefix */
                 node)          /* cust_node_field */
 
 int forb_register_port(forb_orb orb, forb_port_t *port);
+void forb_stop_port(forb_port_t *port);
 void forb_destroy_port(forb_port_t *port);