@@ -47,7 +47,7 @@ static conn_mode_entry_t *get_agent_mode_entry(juice_agent_t *agent) {
4747 return conn_get_mode_entry (mode );
4848}
4949
50- static int acquire_registry (conn_mode_entry_t * entry , udp_socket_config_t * config ) {
50+ static int acquire_registry (conn_mode_entry_t * entry , udp_socket_config_t * config , conn_registry_t * * acquired ) {
5151 // entry must be locked
5252 conn_registry_t * registry ;
5353
@@ -58,8 +58,10 @@ static int acquire_registry(conn_mode_entry_t *entry, udp_socket_config_t *confi
5858 }
5959
6060 if (!registry ) {
61- if (!entry -> registry_init_func )
61+ if (!entry -> registry_init_func ) {
62+ * acquired = NULL ;
6263 return 0 ;
64+ }
6365
6466 JLOG_DEBUG ("Creating connections registry" );
6567
@@ -96,6 +98,8 @@ static int acquire_registry(conn_mode_entry_t *entry, udp_socket_config_t *confi
9698 mutex_lock (& registry -> mutex );
9799 }
98100
101+ * acquired = registry ;
102+
99103 // registry is locked
100104 return 0 ;
101105}
@@ -129,20 +133,13 @@ static void release_registry(conn_mode_entry_t *entry, conn_registry_t *registry
129133
130134int conn_create (juice_agent_t * agent , udp_socket_config_t * config ) {
131135 conn_mode_entry_t * entry = get_agent_mode_entry (agent );
136+ conn_registry_t * registry ;
132137 mutex_lock (& entry -> mutex );
133- if (acquire_registry (entry , config )) { // locks the registry if created
138+ if (acquire_registry (entry , config , & registry )) { // locks the registry if created
134139 mutex_unlock (& entry -> mutex );
135140 return -1 ;
136141 }
137142
138- conn_registry_t * registry ;
139-
140- if (entry -> get_registry_func ) {
141- registry = entry -> get_registry_func (config );
142- } else {
143- registry = entry -> registry ;
144- }
145-
146143 agent -> registry = registry ;
147144
148145 JLOG_DEBUG ("Creating connection" );
@@ -283,14 +280,15 @@ int juice_mux_listen(const char *bind_address, int local_port, juice_cb_mux_inco
283280 config .bind_address = bind_address ;
284281 config .port_begin = config .port_end = local_port ;
285282
283+ conn_registry_t * registry ;
284+
286285 // locks the registry, creating it first if required
287- if (acquire_registry (entry , & config )) {
286+ if (acquire_registry (entry , & config , & registry )) {
288287 JLOG_DEBUG ("juice_mux_listen acquiring registry failed" );
289288 mutex_unlock (& entry -> mutex );
290289 return -1 ;
291290 }
292291
293- conn_registry_t * registry = entry -> get_registry_func (& config );
294292 if (!registry ) {
295293 JLOG_DEBUG ("juice_mux_listen registry not found after creating it" );
296294 mutex_unlock (& entry -> mutex );
0 commit comments