{
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);
}
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;
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);
}
/**
- * 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 */
/* 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. */
#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;
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);