Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
A
asterisk
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Issue analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Voice
asterisk
Commits
d5f09fca
Commit
d5f09fca
authored
9 years ago
by
Matt Jordan
Committed by
Gerrit Code Review
9 years ago
Browse files
Options
Downloads
Plain Diff
Merge "dns: Make query sets hold on to queries for their lifetime."
parents
86d5556b
7216e3c6
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
main/dns_query_set.c
+15
-12
15 additions, 12 deletions
main/dns_query_set.c
tests/test_dns_query_set.c
+6
-1
6 additions, 1 deletion
tests/test_dns_query_set.c
with
21 additions
and
13 deletions
main/dns_query_set.c
+
15
−
12
View file @
d5f09fca
...
@@ -43,9 +43,10 @@ ASTERISK_REGISTER_FILE()
...
@@ -43,9 +43,10 @@ ASTERISK_REGISTER_FILE()
/*! \brief The default number of expected queries to be added to the query set */
/*! \brief The default number of expected queries to be added to the query set */
#define DNS_QUERY_SET_EXPECTED_QUERY_COUNT 5
#define DNS_QUERY_SET_EXPECTED_QUERY_COUNT 5
/*! \brief
Release all queries held in a
query set */
/*! \brief
Destructor for DNS
query set */
static
void
dns_query_set_
release
(
struct
ast_dns_query_set
*
query_set
)
static
void
dns_query_set_
destroy
(
void
*
data
)
{
{
struct
ast_dns_query_set
*
query_set
=
data
;
int
idx
;
int
idx
;
for
(
idx
=
0
;
idx
<
AST_VECTOR_SIZE
(
&
query_set
->
queries
);
++
idx
)
{
for
(
idx
=
0
;
idx
<
AST_VECTOR_SIZE
(
&
query_set
->
queries
);
++
idx
)
{
...
@@ -53,16 +54,8 @@ static void dns_query_set_release(struct ast_dns_query_set *query_set)
...
@@ -53,16 +54,8 @@ static void dns_query_set_release(struct ast_dns_query_set *query_set)
ao2_ref
(
query
->
query
,
-
1
);
ao2_ref
(
query
->
query
,
-
1
);
}
}
AST_VECTOR_FREE
(
&
query_set
->
queries
);
AST_VECTOR_FREE
(
&
query_set
->
queries
);
}
/*! \brief Destructor for DNS query set */
static
void
dns_query_set_destroy
(
void
*
data
)
{
struct
ast_dns_query_set
*
query_set
=
data
;
dns_query_set_release
(
query_set
);
ao2_cleanup
(
query_set
->
user_data
);
ao2_cleanup
(
query_set
->
user_data
);
}
}
...
@@ -88,7 +81,15 @@ static void dns_query_set_callback(const struct ast_dns_query *query)
...
@@ -88,7 +81,15 @@ static void dns_query_set_callback(const struct ast_dns_query *query)
{
{
struct
ast_dns_query_set
*
query_set
=
ast_dns_query_get_data
(
query
);
struct
ast_dns_query_set
*
query_set
=
ast_dns_query_get_data
(
query
);
/* The reference count of the query set is bumped here in case this query holds the last reference */
ao2_ref
(
query_set
,
+
1
);
/* Drop the query set from the query so the query set can be destroyed if this is the last one */
ao2_cleanup
(((
struct
ast_dns_query
*
)
query
)
->
user_data
);
((
struct
ast_dns_query
*
)
query
)
->
user_data
=
NULL
;
if
(
ast_atomic_fetchadd_int
(
&
query_set
->
queries_completed
,
+
1
)
!=
(
AST_VECTOR_SIZE
(
&
query_set
->
queries
)
-
1
))
{
if
(
ast_atomic_fetchadd_int
(
&
query_set
->
queries_completed
,
+
1
)
!=
(
AST_VECTOR_SIZE
(
&
query_set
->
queries
)
-
1
))
{
ao2_ref
(
query_set
,
-
1
);
return
;
return
;
}
}
...
@@ -100,7 +101,7 @@ static void dns_query_set_callback(const struct ast_dns_query *query)
...
@@ -100,7 +101,7 @@ static void dns_query_set_callback(const struct ast_dns_query *query)
ao2_cleanup
(
query_set
->
user_data
);
ao2_cleanup
(
query_set
->
user_data
);
query_set
->
user_data
=
NULL
;
query_set
->
user_data
=
NULL
;
dns_query_set_release
(
query_set
);
ao2_ref
(
query_set
,
-
1
);
}
}
int
ast_dns_query_set_add
(
struct
ast_dns_query_set
*
query_set
,
const
char
*
name
,
int
rr_type
,
int
rr_class
)
int
ast_dns_query_set_add
(
struct
ast_dns_query_set
*
query_set
,
const
char
*
name
,
int
rr_type
,
int
rr_class
)
...
@@ -116,7 +117,7 @@ int ast_dns_query_set_add(struct ast_dns_query_set *query_set, const char *name,
...
@@ -116,7 +117,7 @@ int ast_dns_query_set_add(struct ast_dns_query_set *query_set, const char *name,
return
-
1
;
return
-
1
;
}
}
query
.
query
=
dns_query_alloc
(
name
,
rr_type
,
rr_class
,
dns_query_set_callback
,
query_set
);
query
.
query
=
dns_query_alloc
(
name
,
rr_type
,
rr_class
,
dns_query_set_callback
,
NULL
);
if
(
!
query
.
query
)
{
if
(
!
query
.
query
)
{
return
-
1
;
return
-
1
;
}
}
...
@@ -169,6 +170,8 @@ void ast_dns_query_set_resolve_async(struct ast_dns_query_set *query_set, ast_dn
...
@@ -169,6 +170,8 @@ void ast_dns_query_set_resolve_async(struct ast_dns_query_set *query_set, ast_dn
for
(
idx
=
0
;
idx
<
AST_VECTOR_SIZE
(
&
query_set
->
queries
);
++
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
);
struct
dns_query_set_query
*
query
=
AST_VECTOR_GET_ADDR
(
&
query_set
->
queries
,
idx
);
query
->
query
->
user_data
=
ao2_bump
(
query_set
);
if
(
!
query
->
query
->
resolver
->
resolve
(
query
->
query
))
{
if
(
!
query
->
query
->
resolver
->
resolve
(
query
->
query
))
{
query
->
started
=
1
;
query
->
started
=
1
;
continue
;
continue
;
...
...
This diff is collapsed.
Click to expand it.
tests/test_dns_query_set.c
+
6
−
1
View file @
d5f09fca
...
@@ -131,9 +131,14 @@ static int query_set_resolve(struct ast_dns_query *query)
...
@@ -131,9 +131,14 @@ static int query_set_resolve(struct ast_dns_query *query)
static
int
query_set_cancel
(
struct
ast_dns_query
*
query
)
static
int
query_set_cancel
(
struct
ast_dns_query
*
query
)
{
{
struct
ast_dns_query_set
*
query_set
=
ast_dns_query_get_data
(
query
);
struct
ast_dns_query_set
*
query_set
=
ast_dns_query_get_data
(
query
);
struct
query_set_data
*
qsdata
=
query_set
->
user_data
;
struct
query_set_data
*
qsdata
;
int
res
=
-
1
;
int
res
=
-
1
;
if
(
!
query_set
)
{
return
-
1
;
}
qsdata
=
query_set
->
user_data
;
if
(
qsdata
->
cancel
++
<
qsdata
->
cancel_allowed
)
{
if
(
qsdata
->
cancel
++
<
qsdata
->
cancel_allowed
)
{
res
=
0
;
res
=
0
;
}
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment