Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
L
libnice
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
cpp-libs
libnice
Commits
6171f250
Commit
6171f250
authored
May 08, 2019
by
Olivier Crête
Committed by
Olivier Crête
May 09, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
agent: Replace closed signal with GASyncResult type function
This makes the API more GIO style
parent
e78a4923
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
49 additions
and
58 deletions
+49
-58
agent/agent.c
agent/agent.c
+17
-27
agent/agent.h
agent/agent.h
+9
-2
agent/discovery.c
agent/discovery.c
+2
-2
agent/discovery.h
agent/discovery.h
+1
-1
tests/test-fullmode.c
tests/test-fullmode.c
+10
-12
tests/test-turn.c
tests/test-turn.c
+10
-14
No files found.
agent/agent.c
View file @
6171f250
...
@@ -136,7 +136,6 @@ enum
...
@@ -136,7 +136,6 @@ enum
SIGNAL_NEW_SELECTED_PAIR_FULL
,
SIGNAL_NEW_SELECTED_PAIR_FULL
,
SIGNAL_NEW_CANDIDATE_FULL
,
SIGNAL_NEW_CANDIDATE_FULL
,
SIGNAL_NEW_REMOTE_CANDIDATE_FULL
,
SIGNAL_NEW_REMOTE_CANDIDATE_FULL
,
SIGNAL_CLOSED
,
N_SIGNALS
,
N_SIGNALS
,
};
};
...
@@ -1141,28 +1140,6 @@ nice_agent_class_init (NiceAgentClass *klass)
...
@@ -1141,28 +1140,6 @@ nice_agent_class_init (NiceAgentClass *klass)
NICE_TYPE_CANDIDATE
,
NICE_TYPE_CANDIDATE
,
G_TYPE_INVALID
);
G_TYPE_INVALID
);
/**
* NiceAgent::closed
* @agent: The #NiceAgent object
*
* This signal is fired when the agent finishes freeing resources it
* previously allocated on remote servers (e.g. relay ports) and is ready
* to be disposed.
*
* Since: 0.1.16
*/
signals
[
SIGNAL_CLOSED
]
=
g_signal_new
(
"closed"
,
G_OBJECT_CLASS_TYPE
(
klass
),
G_SIGNAL_RUN_LAST
,
0
,
NULL
,
NULL
,
NULL
,
G_TYPE_NONE
,
0
);
/* Init debug options depending on env variables */
/* Init debug options depending on env variables */
nice_debug_init
();
nice_debug_init
();
}
}
...
@@ -6688,19 +6665,32 @@ nice_agent_peer_candidate_gathering_done (NiceAgent *agent, guint stream_id)
...
@@ -6688,19 +6665,32 @@ nice_agent_peer_candidate_gathering_done (NiceAgent *agent, guint stream_id)
static
gboolean
static
gboolean
on_agent_refreshes_pruned
(
NiceAgent
*
agent
,
gpointer
user_data
)
on_agent_refreshes_pruned
(
NiceAgent
*
agent
,
gpointer
user_data
)
{
{
// This is called from a timeout cb with agent lock held
GTask
*
task
=
user_data
;
/* This is called from a timeout cb with agent lock held */
agent_queue_signal
(
agent
,
signals
[
SIGNAL_CLOSED
]);
agent_unlock
(
agent
);
g_task_return_boolean
(
task
,
TRUE
);
g_object_unref
(
task
);
agent_lock
(
agent
);
return
G_SOURCE_REMOVE
;
return
G_SOURCE_REMOVE
;
}
}
void
void
nice_agent_close_async
(
NiceAgent
*
agent
)
nice_agent_close_async
(
NiceAgent
*
agent
,
GAsyncReadyCallback
callback
,
gpointer
callback_data
)
{
{
GTask
*
task
;
task
=
g_task_new
(
agent
,
NULL
,
callback
,
callback_data
);
g_task_set_source_tag
(
task
,
nice_agent_close_async
);
agent_lock
(
agent
);
agent_lock
(
agent
);
refresh_prune_agent_async
(
agent
,
on_agent_refreshes_pruned
);
refresh_prune_agent_async
(
agent
,
on_agent_refreshes_pruned
,
task
);
agent_unlock
(
agent
);
agent_unlock
(
agent
);
}
}
agent/agent.h
View file @
6171f250
...
@@ -1662,9 +1662,15 @@ nice_agent_peer_candidate_gathering_done (
...
@@ -1662,9 +1662,15 @@ nice_agent_peer_candidate_gathering_done (
/**
/**
* nice_agent_close_async:
* nice_agent_close_async:
* @agent: The #NiceAgent object
* @agent: The #NiceAgent object
* @callback: (nullable): A callback that will be called when the closing is
* complete
* @callback_data: (nullable): A pointer that will be passed to the callback
*
*
* Asynchronously closes resources the agent has allocated on remote servers.
* Asynchronously closes resources the agent has allocated on remote servers.
* The agent will emit "closed" signal when the operation finishes.
*
* The agent will call the callback in the current #GMainContext in
* which this function is called. The #GAsyncResult in the callback
* can be ignored as this operation never fails.
*
*
* Calling this function before freeing the agent makes sure the allocated relay
* Calling this function before freeing the agent makes sure the allocated relay
* ports aren't left behind on TURN server but properly removed.
* ports aren't left behind on TURN server but properly removed.
...
@@ -1672,7 +1678,8 @@ nice_agent_peer_candidate_gathering_done (
...
@@ -1672,7 +1678,8 @@ nice_agent_peer_candidate_gathering_done (
* Since: 0.1.16
* Since: 0.1.16
*/
*/
void
void
nice_agent_close_async
(
NiceAgent
*
agent
);
nice_agent_close_async
(
NiceAgent
*
agent
,
GAsyncReadyCallback
callback
,
gpointer
callback_data
);
G_END_DECLS
G_END_DECLS
...
...
agent/discovery.c
View file @
6171f250
...
@@ -326,9 +326,9 @@ static void refresh_prune_async (NiceAgent *agent, GSList *refreshes,
...
@@ -326,9 +326,9 @@ static void refresh_prune_async (NiceAgent *agent, GSList *refreshes,
}
}
void
refresh_prune_agent_async
(
NiceAgent
*
agent
,
void
refresh_prune_agent_async
(
NiceAgent
*
agent
,
NiceTimeoutLockedCallback
function
)
NiceTimeoutLockedCallback
function
,
gpointer
user_data
)
{
{
refresh_prune_async
(
agent
,
agent
->
refresh_list
,
function
,
NULL
);
refresh_prune_async
(
agent
,
agent
->
refresh_list
,
function
,
user_data
);
}
}
/*
/*
...
...
agent/discovery.h
View file @
6171f250
...
@@ -86,7 +86,7 @@ typedef struct
...
@@ -86,7 +86,7 @@ typedef struct
void
refresh_free
(
NiceAgent
*
agent
,
CandidateRefresh
*
refresh
);
void
refresh_free
(
NiceAgent
*
agent
,
CandidateRefresh
*
refresh
);
void
refresh_prune_agent_async
(
NiceAgent
*
agent
,
void
refresh_prune_agent_async
(
NiceAgent
*
agent
,
NiceTimeoutLockedCallback
function
);
NiceTimeoutLockedCallback
function
,
gpointer
user_data
);
void
refresh_prune_stream_async
(
NiceAgent
*
agent
,
NiceStream
*
stream
,
void
refresh_prune_stream_async
(
NiceAgent
*
agent
,
NiceStream
*
stream
,
NiceTimeoutLockedCallback
function
);
NiceTimeoutLockedCallback
function
);
void
refresh_prune_candidate
(
NiceAgent
*
agent
,
NiceCandidate
*
candidate
);
void
refresh_prune_candidate
(
NiceAgent
*
agent
,
NiceCandidate
*
candidate
);
...
...
tests/test-fullmode.c
View file @
6171f250
...
@@ -130,8 +130,6 @@ static gboolean global_lagent_gathering_done = FALSE;
...
@@ -130,8 +130,6 @@ static gboolean global_lagent_gathering_done = FALSE;
static
gboolean
global_ragent_gathering_done
=
FALSE
;
static
gboolean
global_ragent_gathering_done
=
FALSE
;
static
gboolean
global_lagent_ibr_received
=
FALSE
;
static
gboolean
global_lagent_ibr_received
=
FALSE
;
static
gboolean
global_ragent_ibr_received
=
FALSE
;
static
gboolean
global_ragent_ibr_received
=
FALSE
;
static
gboolean
global_lagent_closed
=
FALSE
;
static
gboolean
global_ragent_closed
=
FALSE
;
static
int
global_lagent_cands
=
0
;
static
int
global_lagent_cands
=
0
;
static
int
global_ragent_cands
=
0
;
static
int
global_ragent_cands
=
0
;
static
gint
global_ragent_read
=
0
;
static
gint
global_ragent_read
=
0
;
...
@@ -298,8 +296,10 @@ static void cb_initial_binding_request_received(NiceAgent *agent, guint stream_i
...
@@ -298,8 +296,10 @@ static void cb_initial_binding_request_received(NiceAgent *agent, guint stream_i
(
void
)
agent
;
(
void
)
stream_id
;
(
void
)
data
;
(
void
)
agent
;
(
void
)
stream_id
;
(
void
)
data
;
}
}
static
void
cb_closed
(
NiceAgent
*
agen
t
,
gpointer
data
)
static
void
cb_closed
(
GObject
*
src
,
GAsyncResult
*
resul
t
,
gpointer
data
)
{
{
NiceAgent
*
agent
=
NICE_AGENT
(
src
);
g_debug
(
"test-fullmode:%s: %p"
,
G_STRFUNC
,
agent
);
g_debug
(
"test-fullmode:%s: %p"
,
G_STRFUNC
,
agent
);
*
((
gboolean
*
)
data
)
=
TRUE
;
*
((
gboolean
*
)
data
)
=
TRUE
;
...
@@ -862,6 +862,8 @@ int main (void)
...
@@ -862,6 +862,8 @@ int main (void)
int
result
;
int
result
;
guint
timer_id
;
guint
timer_id
;
const
char
*
stun_server
=
NULL
,
*
stun_server_port
=
NULL
;
const
char
*
stun_server
=
NULL
,
*
stun_server_port
=
NULL
;
gboolean
lagent_closed
=
FALSE
;
gboolean
ragent_closed
=
FALSE
;
#ifdef G_OS_WIN32
#ifdef G_OS_WIN32
WSADATA
w
;
WSADATA
w
;
...
@@ -933,10 +935,6 @@ int main (void)
...
@@ -933,10 +935,6 @@ int main (void)
g_signal_connect
(
G_OBJECT
(
ragent
),
"initial-binding-request-received"
,
g_signal_connect
(
G_OBJECT
(
ragent
),
"initial-binding-request-received"
,
G_CALLBACK
(
cb_initial_binding_request_received
),
G_CALLBACK
(
cb_initial_binding_request_received
),
GUINT_TO_POINTER
(
2
));
GUINT_TO_POINTER
(
2
));
g_signal_connect
(
G_OBJECT
(
lagent
),
"closed"
,
G_CALLBACK
(
cb_closed
),
&
global_lagent_closed
);
g_signal_connect
(
G_OBJECT
(
ragent
),
"closed"
,
G_CALLBACK
(
cb_closed
),
&
global_ragent_closed
);
stun_server
=
getenv
(
"NICE_STUN_SERVER"
);
stun_server
=
getenv
(
"NICE_STUN_SERVER"
);
stun_server_port
=
getenv
(
"NICE_STUN_SERVER_PORT"
);
stun_server_port
=
getenv
(
"NICE_STUN_SERVER_PORT"
);
...
@@ -1112,15 +1110,15 @@ int main (void)
...
@@ -1112,15 +1110,15 @@ int main (void)
g_assert
(
global_ragent_state
[
0
]
==
NICE_COMPONENT_STATE_READY
);
g_assert
(
global_ragent_state
[
0
]
==
NICE_COMPONENT_STATE_READY
);
g_assert
(
global_ragent_state
[
1
]
==
NICE_COMPONENT_STATE_READY
);
g_assert
(
global_ragent_state
[
1
]
==
NICE_COMPONENT_STATE_READY
);
nice_agent_close_async
(
lagent
);
nice_agent_close_async
(
lagent
,
cb_closed
,
&
lagent_closed
);
nice_agent_close_async
(
ragent
);
nice_agent_close_async
(
ragent
,
cb_closed
,
&
ragent_closed
);
g_object_unref
(
lagent
);
g_object_unref
(
ragent
);
while
(
!
global_lagent_closed
||
!
global_
ragent_closed
)
{
while
(
!
ragent_closed
||
!
ragent_closed
)
{
g_main_context_iteration
(
NULL
,
TRUE
);
g_main_context_iteration
(
NULL
,
TRUE
);
}
}
g_object_unref
(
lagent
);
g_object_unref
(
ragent
);
g_main_loop_unref
(
global_mainloop
);
g_main_loop_unref
(
global_mainloop
);
global_mainloop
=
NULL
;
global_mainloop
=
NULL
;
...
...
tests/test-turn.c
View file @
6171f250
...
@@ -10,8 +10,6 @@ static NiceComponentState global_ragent_state[2] = { NICE_COMPONENT_STATE_LAST,
...
@@ -10,8 +10,6 @@ static NiceComponentState global_ragent_state[2] = { NICE_COMPONENT_STATE_LAST,
static
guint
global_components_ready
=
0
;
static
guint
global_components_ready
=
0
;
static
gboolean
global_lagent_gathering_done
=
FALSE
;
static
gboolean
global_lagent_gathering_done
=
FALSE
;
static
gboolean
global_ragent_gathering_done
=
FALSE
;
static
gboolean
global_ragent_gathering_done
=
FALSE
;
static
gboolean
global_lagent_closed
=
FALSE
;
static
gboolean
global_ragent_closed
=
FALSE
;
static
int
global_lagent_cands
=
0
;
static
int
global_lagent_cands
=
0
;
static
int
global_ragent_cands
=
0
;
static
int
global_ragent_cands
=
0
;
...
@@ -103,8 +101,9 @@ static void cb_new_selected_pair(NiceAgent *agent, guint stream_id,
...
@@ -103,8 +101,9 @@ static void cb_new_selected_pair(NiceAgent *agent, guint stream_id,
++
global_ragent_cands
;
++
global_ragent_cands
;
}
}
static
void
cb_closed
(
NiceAgent
*
agent
,
gpointer
data
)
static
void
cb_closed
(
GObject
*
src
,
GAsyncResult
*
res
,
gpointer
data
)
{
{
NiceAgent
*
agent
=
NICE_AGENT
(
src
);
g_debug
(
"test-turn:%s: %p"
,
G_STRFUNC
,
agent
);
g_debug
(
"test-turn:%s: %p"
,
G_STRFUNC
,
agent
);
*
((
gboolean
*
)
data
)
=
TRUE
;
*
((
gboolean
*
)
data
)
=
TRUE
;
...
@@ -163,6 +162,8 @@ run_test(guint turn_port, gboolean is_ipv6,
...
@@ -163,6 +162,8 @@ run_test(guint turn_port, gboolean is_ipv6,
NiceAddress
localaddr
;
NiceAddress
localaddr
;
guint
ls_id
,
rs_id
;
guint
ls_id
,
rs_id
;
gulong
timer_id
;
gulong
timer_id
;
gboolean
lagent_closed
=
FALSE
;
gboolean
ragent_closed
=
FALSE
;
if
(
is_ipv6
)
if
(
is_ipv6
)
localhost
=
"::1"
;
localhost
=
"::1"
;
...
@@ -173,8 +174,6 @@ run_test(guint turn_port, gboolean is_ipv6,
...
@@ -173,8 +174,6 @@ run_test(guint turn_port, gboolean is_ipv6,
global_components_ready
=
0
;
global_components_ready
=
0
;
global_lagent_gathering_done
=
FALSE
;
global_lagent_gathering_done
=
FALSE
;
global_ragent_gathering_done
=
FALSE
;
global_ragent_gathering_done
=
FALSE
;
global_lagent_closed
=
FALSE
;
global_ragent_closed
=
FALSE
;
global_lagent_cands
=
global_ragent_cands
=
0
;
global_lagent_cands
=
global_ragent_cands
=
0
;
lagent
=
nice_agent_new
(
NULL
,
NICE_COMPATIBILITY_RFC5245
);
lagent
=
nice_agent_new
(
NULL
,
NICE_COMPATIBILITY_RFC5245
);
...
@@ -210,10 +209,6 @@ run_test(guint turn_port, gboolean is_ipv6,
...
@@ -210,10 +209,6 @@ run_test(guint turn_port, gboolean is_ipv6,
G_CALLBACK
(
cb_new_selected_pair
),
GUINT_TO_POINTER
(
1
));
G_CALLBACK
(
cb_new_selected_pair
),
GUINT_TO_POINTER
(
1
));
g_signal_connect
(
G_OBJECT
(
ragent
),
"new-selected-pair"
,
g_signal_connect
(
G_OBJECT
(
ragent
),
"new-selected-pair"
,
G_CALLBACK
(
cb_new_selected_pair
),
GUINT_TO_POINTER
(
2
));
G_CALLBACK
(
cb_new_selected_pair
),
GUINT_TO_POINTER
(
2
));
g_signal_connect
(
G_OBJECT
(
lagent
),
"closed"
,
G_CALLBACK
(
cb_closed
),
&
global_lagent_closed
);
g_signal_connect
(
G_OBJECT
(
ragent
),
"closed"
,
G_CALLBACK
(
cb_closed
),
&
global_ragent_closed
);
g_object_set
(
G_OBJECT
(
lagent
),
"controlling-mode"
,
TRUE
,
NULL
);
g_object_set
(
G_OBJECT
(
lagent
),
"controlling-mode"
,
TRUE
,
NULL
);
g_object_set
(
G_OBJECT
(
ragent
),
"controlling-mode"
,
FALSE
,
NULL
);
g_object_set
(
G_OBJECT
(
ragent
),
"controlling-mode"
,
FALSE
,
NULL
);
...
@@ -262,17 +257,18 @@ run_test(guint turn_port, gboolean is_ipv6,
...
@@ -262,17 +257,18 @@ run_test(guint turn_port, gboolean is_ipv6,
nice_agent_remove_stream
(
lagent
,
ls_id
);
nice_agent_remove_stream
(
lagent
,
ls_id
);
nice_agent_remove_stream
(
ragent
,
rs_id
);
nice_agent_remove_stream
(
ragent
,
rs_id
);
nice_agent_close_async
(
lagent
);
nice_agent_close_async
(
lagent
,
cb_closed
,
&
lagent_closed
);
nice_agent_close_async
(
ragent
);
nice_agent_close_async
(
ragent
,
cb_closed
,
&
ragent_closed
);
while
(
!
global_lagent_closed
||
!
global_ragent_closed
)
{
g_clear_object
(
&
lagent
);
g_clear_object
(
&
ragent
);
while
(
!
lagent_closed
||
!
ragent_closed
)
{
g_main_context_iteration
(
NULL
,
TRUE
);
g_main_context_iteration
(
NULL
,
TRUE
);
}
}
g_source_remove
(
timer_id
);
g_source_remove
(
timer_id
);
g_clear_object
(
&
lagent
);
g_clear_object
(
&
ragent
);
}
}
guint
global_turn_port
;
guint
global_turn_port
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment