#include <forb/config.h>
#include "iop.h"
#include <ul_log.h>
+#include "discovery.h"
extern UL_LOG_CUST(ulogd_forb_port);
}
/**
- * 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
+}
- if (port->desc.proto->port_destroy) {
- port->desc.proto->port_destroy(port);
- }
+/**
+ * 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_delete_by_port(forb, port);
+ forb_peer_t *peer;
+ ul_list_for_each_cut(forb_port_peer, port, peer) {
+ forb_peer_get(peer);
+ 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);
+ }
FORB_CDR_codec_release_buffer(&port->codec);