]> rtime.felk.cvut.cz Git - frescor/forb.git/blobdiff - src/port.c
forb: Split forb_port_destroy() to stop and destroy phases
[frescor/forb.git] / src / port.c
index 0c54c40018096202e0fd1a25164ff926589eb1c4..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;
@@ -177,6 +188,8 @@ void forb_destroy_port(forb_port_t *port)
                forb_peer_disconnected(peer);
                forb_peer_put(peer);
        }
+       if (port->new_peer)
+               forb_peer_put(port->new_peer);
 
        if (port->desc.proto->port_destroy) {
                port->desc.proto->port_destroy(port);