[asterisk-commits] file: branch group/dns_pjsip r433994 - /team/group/dns_pjsip/main/

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Sat Apr 4 15:24:54 CDT 2015


Author: file
Date: Sat Apr  4 15:24:51 2015
New Revision: 433994

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=433994
Log:
Tweak cancellation of a query set.

Next up is tests which cover this!

Modified:
    team/group/dns_pjsip/main/dns_query_set.c

Modified: team/group/dns_pjsip/main/dns_query_set.c
URL: http://svnview.digium.com/svn/asterisk/team/group/dns_pjsip/main/dns_query_set.c?view=diff&rev=433994&r1=433993&r2=433994
==============================================================================
--- team/group/dns_pjsip/main/dns_query_set.c (original)
+++ team/group/dns_pjsip/main/dns_query_set.c Sat Apr  4 15:24:51 2015
@@ -54,6 +54,8 @@
 	AST_VECTOR(, struct dns_query_set_query) queries;
 	/*! \brief The total number of completed queries */
 	int queries_completed;
+	/*! \brief The total number of cancelled queries */
+	int queries_cancelled;
 	/*! \brief Callback to invoke upon completion */
 	ast_dns_query_set_callback callback;
 	/*! \brief User-specific data */
@@ -111,7 +113,9 @@
 	}
 
 	/* All queries have been completed, invoke final callback */
-	query_set->callback(query_set);
+	if (query_set->queries_cancelled != query_set->queries_completed) {
+		query_set->callback(query_set);
+	}
 
 	ao2_cleanup(query_set->user_data);
 	query_set->user_data = NULL;
@@ -237,20 +241,24 @@
 
 int ast_dns_query_set_resolve_cancel(struct ast_dns_query_set *query_set)
 {
-	int res = 0, idx;
+	int idx;
 
 	for (idx = 0; idx < AST_VECTOR_SIZE(&query_set->queries); ++idx) {
 		struct dns_query_set_query *query = AST_VECTOR_GET_ADDR(&query_set->queries, idx);
 
 		if (query->started) {
-			res |= query->query->resolver->cancel(query->query);
+			if (!query->query->resolver->cancel(query->query)) {
+				ast_atomic_fetchadd_int(&query_set->queries_cancelled, +1);
+				dns_query_set_callback(query->query);
+			}
+		} else {
+			ast_atomic_fetchadd_int(&query_set->queries_cancelled, +1);
 		}
-
-	}
-
-	if (!res) {
+	}
+
+	if (query_set->queries_cancelled == query_set->queries_completed) {
 		dns_query_set_release(query_set);
 	}
 
-	return res;
+	return (query_set->queries_cancelled == query_set->queries_completed) ? 0 : -1;
 }




More information about the asterisk-commits mailing list