Changeset 4219
- Timestamp:
- Aug 7, 2012 2:53:03 AM (12 years ago)
- Location:
- pjproject/trunk/pjsip
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/trunk/pjsip/include/pjsua-lib/pjsua_internal.h
r4218 r4219 337 337 338 338 pj_pool_t *pool; /**< Pool */ 339 int ref_cnt; /**< Reference count */ 340 pj_bool_t destroy_flag; /**< To be destroyed */ 341 pj_bool_t has_result; 339 342 unsigned count; /**< # of entries */ 340 343 pj_str_t *srv; /**< Array of entries */ -
pjproject/trunk/pjsip/src/pjsua-lib/pjsua_core.c
r4218 r4219 1089 1089 } 1090 1090 1091 /* Internal function to destroy STUN resolution session 1092 * (pj_stun_resolve). 1093 */ 1091 static void stun_resolve_add_ref(pjsua_stun_resolve *sess) 1092 { 1093 ++sess->ref_cnt; 1094 } 1095 1094 1096 static void destroy_stun_resolve(pjsua_stun_resolve *sess) 1095 1097 { 1098 sess->destroy_flag = PJ_TRUE; 1099 if (sess->ref_cnt > 0) 1100 return; 1101 1096 1102 PJSUA_LOCK(); 1097 1103 pj_list_erase(sess); … … 1102 1108 } 1103 1109 1110 static void stun_resolve_dec_ref(pjsua_stun_resolve *sess) 1111 { 1112 --sess->ref_cnt; 1113 if (sess->ref_cnt <= 0 && sess->destroy_flag) 1114 destroy_stun_resolve(sess); 1115 } 1116 1117 1104 1118 /* This is the internal function to be called when STUN resolution 1105 1119 * session (pj_stun_resolve) has completed. … … 1108 1122 { 1109 1123 pj_stun_resolve_result result; 1124 1125 if (sess->has_result) 1126 goto on_return; 1110 1127 1111 1128 pj_bzero(&result, sizeof(result)); … … 1114 1131 result.name = sess->srv[sess->idx]; 1115 1132 pj_memcpy(&result.addr, &sess->addr, sizeof(result.addr)); 1133 sess->has_result = PJ_TRUE; 1116 1134 1117 1135 if (result.status == PJ_SUCCESS) { … … 1129 1147 } 1130 1148 1149 stun_resolve_add_ref(sess); 1131 1150 sess->cb(&result); 1132 1151 stun_resolve_dec_ref(sess); 1152 1153 on_return: 1133 1154 if (!sess->blocking) { 1134 1155 destroy_stun_resolve(sess); … … 1192 1213 static void resolve_stun_entry(pjsua_stun_resolve *sess) 1193 1214 { 1215 stun_resolve_add_ref(sess); 1216 1194 1217 /* Loop while we have entry to try */ 1195 1218 for (; sess->idx < sess->count; ++sess->idx) { 1196 1219 const int af = pj_AF_INET(); 1220 char target[64]; 1197 1221 pj_str_t hostpart; 1198 1222 pj_uint16_t port; … … 1201 1225 pj_assert(sess->idx < sess->count); 1202 1226 1227 pj_ansi_snprintf(target, sizeof(target), "%.*s", 1228 (int)sess->srv[sess->idx].slen, 1229 sess->srv[sess->idx].ptr); 1230 1203 1231 /* Parse the server entry into host:port */ 1204 1232 sess->status = pj_sockaddr_parse2(af, 0, &sess->srv[sess->idx], 1205 1233 &hostpart, &port, NULL); 1206 1234 if (sess->status != PJ_SUCCESS) { 1207 PJ_LOG(2,(THIS_FILE, "Invalid STUN server entry %.*s", 1208 (int)sess->srv[sess->idx].slen, 1209 sess->srv[sess->idx].ptr)); 1235 PJ_LOG(2,(THIS_FILE, "Invalid STUN server entry %s", target)); 1210 1236 continue; 1211 1237 } … … 1217 1243 pj_assert(sess->stun_sock == NULL); 1218 1244 1219 PJ_LOG(4,(THIS_FILE, "Trying STUN server %.*s (%d of %d)..", 1220 (int)sess->srv[sess->idx].slen, 1221 sess->srv[sess->idx].ptr, 1222 sess->idx+1, sess->count)); 1245 PJ_LOG(4,(THIS_FILE, "Trying STUN server %s (%d of %d)..", 1246 target, sess->idx+1, sess->count)); 1223 1247 1224 1248 /* Use STUN_sock to test this entry */ … … 1232 1256 pj_strerror(sess->status, errmsg, sizeof(errmsg)); 1233 1257 PJ_LOG(4,(THIS_FILE, 1234 "Error creating STUN socket for %.*s: %s", 1235 (int)sess->srv[sess->idx].slen, 1236 sess->srv[sess->idx].ptr, errmsg)); 1258 "Error creating STUN socket for %s: %s", 1259 target, errmsg)); 1237 1260 1238 1261 continue; … … 1245 1268 pj_strerror(sess->status, errmsg, sizeof(errmsg)); 1246 1269 PJ_LOG(4,(THIS_FILE, 1247 "Error starting STUN socket for %.*s: %s", 1248 (int)sess->srv[sess->idx].slen, 1249 sess->srv[sess->idx].ptr, errmsg)); 1250 1251 pj_stun_sock_destroy(sess->stun_sock); 1252 sess->stun_sock = NULL; 1270 "Error starting STUN socket for %s: %s", 1271 target, errmsg)); 1272 1273 if (sess->stun_sock) { 1274 pj_stun_sock_destroy(sess->stun_sock); 1275 sess->stun_sock = NULL; 1276 } 1253 1277 continue; 1254 1278 } … … 1257 1281 * stun_sock_cb() 1258 1282 */ 1259 return;1283 goto on_return; 1260 1284 } 1261 1285 … … 1266 1290 stun_resolve_complete(sess); 1267 1291 } 1292 1293 on_return: 1294 stun_resolve_dec_ref(sess); 1268 1295 } 1269 1296
Note: See TracChangeset
for help on using the changeset viewer.