Diff between c229ba89a1b127461a9e38d425d9f8dab7ee1495 and e3c028a44d1c3c0b7661ab12917e1b1864b2d1fa

Changed Files

File Additions Deletions Status
src/shared/mgmt.c +29 -24 modified

Full Patch

diff --git a/src/shared/mgmt.c b/src/shared/mgmt.c
index f96897d..8352550 100644
--- a/src/shared/mgmt.c
+++ b/src/shared/mgmt.c
@@ -101,14 +101,6 @@ static gint compare_request_id(gconstpointer a, gconstpointer b)
 	return request->id - id;
 }
 
-static gint compare_request_index(gconstpointer a, gconstpointer b)
-{
-	const struct mgmt_request *request = a;
-	uint16_t index = GPOINTER_TO_UINT(b);
-
-	return request->index - index;
-}
-
 static void destroy_notify(gpointer data, gpointer user_data)
 {
 	struct mgmt_notify *notify = data;
@@ -252,6 +244,9 @@ static void process_notify(struct mgmt *mgmt, uint16_t event, uint16_t index,
 		if (notify->callback)
 			notify->callback(index, length, param,
 							notify->user_data);
+
+		if (mgmt->destroyed)
+			break;
 	}
 
 	mgmt->in_notify = false;
@@ -578,27 +573,32 @@ unsigned int mgmt_reply(struct mgmt *mgmt, uint16_t opcode, uint16_t index,
 	return request->id;
 }
 
-static bool cancel_request(struct mgmt *mgmt, gconstpointer data,
-							GCompareFunc func)
+bool mgmt_cancel(struct mgmt *mgmt, unsigned int id)
 {
 	struct mgmt_request *request;
 	GList *list;
 
-	list = g_queue_find_custom(mgmt->request_queue, data, func);
+	if (!mgmt || !id)
+		return false;
+
+	list = g_queue_find_custom(mgmt->request_queue, GUINT_TO_POINTER(id),
+							compare_request_id);
 	if (list) {
 		request = list->data;
 		g_queue_delete_link(mgmt->request_queue, list);
 		goto done;
 	}
 
-	list = g_queue_find_custom(mgmt->reply_queue, data, func);
+	list = g_queue_find_custom(mgmt->reply_queue, GUINT_TO_POINTER(id),
+							compare_request_id);
 	if (list) {
 		request = list->data;
 		g_queue_delete_link(mgmt->reply_queue, list);
 		goto done;
 	}
 
-	list = g_list_find_custom(mgmt->pending_list, data, func);
+	list = g_list_find_custom(mgmt->pending_list, GUINT_TO_POINTER(id),
+							compare_request_id);
 	if (!list)
 		return false;
 
@@ -614,23 +614,28 @@ done:
 	return true;
 }
 
-bool mgmt_cancel(struct mgmt *mgmt, unsigned int id)
-{
-	if (!mgmt || !id)
-		return false;
-
-	return cancel_request(mgmt, GUINT_TO_POINTER(id), compare_request_id);
-}
-
 bool mgmt_cancel_index(struct mgmt *mgmt, uint16_t index)
 {
-	unsigned int id = index;
+	GList *list, *next;
 
 	if (!mgmt)
 		return false;
 
-	return cancel_request(mgmt, GUINT_TO_POINTER(id),
-						compare_request_index);
+	for (list = g_list_first(mgmt->pending_list); list; list = next) {
+		struct mgmt_request *request = list->data;
+
+		next = g_list_next(list);
+
+		if (request->index != index)
+			continue;
+
+		mgmt->pending_list = g_list_delete_link(mgmt->pending_list,
+									list);
+
+		destroy_request(request, NULL);
+	}
+
+	return true;
 }
 
 bool mgmt_cancel_all(struct mgmt *mgmt)