Changeset 2124
- Timestamp:
- Jul 12, 2008 9:50:48 AM (16 years ago)
- Location:
- pjproject/trunk/pjlib-util
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/trunk/pjlib-util/include/pjlib-util/config.h
r2039 r2124 179 179 * (#pj_dns_packet_dup()) is also capable of performing name compressions. 180 180 * 181 * Default: 1000 (as a broad guidance, 400 is good for 4 SRV entries).181 * Default: 512 182 182 */ 183 183 #ifndef PJ_DNS_RESOLVER_RES_BUF_SIZE 184 # define PJ_DNS_RESOLVER_RES_BUF_SIZE 1000184 # define PJ_DNS_RESOLVER_RES_BUF_SIZE 512 185 185 #endif 186 186 -
pjproject/trunk/pjlib-util/src/pjlib-util/resolver.c
r2039 r2124 151 151 PJ_DECL_LIST_MEMBER(struct cached_res); 152 152 153 pj_pool_t *pool; /**< Cache's pool. */ 153 154 struct res_key key; /**< Resource key. */ 154 char buf[RES_BUF_SZ];/**< Resource buffer. */155 155 pj_hash_entry_buf hbuf; /**< Hash buffer */ 156 156 pj_time_val expiry_time; /**< Expiration time. */ … … 195 195 /* Hash table for cached response */ 196 196 pj_hash_table_t *hrescache; /**< Cached response in hash table */ 197 198 /* Cached response free list */199 struct cached_res res_free_nodes;200 197 201 198 /* Pending asynchronous query, hashed by transaction ID. */ … … 296 293 } 297 294 298 /* Response cache hash table and item list*/295 /* Response cache hash table */ 299 296 resv->hrescache = pj_hash_create(pool, RES_HASH_TABLE_SIZE); 300 pj_list_init(&resv->res_free_nodes);301 297 302 298 /* Query hash table and free list. */ … … 352 348 pj_bool_t notify) 353 349 { 350 pj_hash_iterator_t it_buf, *it; 354 351 PJ_ASSERT_RETURN(resolver, PJ_EINVAL); 355 352 … … 358 355 * Notify pending queries if requested. 359 356 */ 360 pj_hash_iterator_t it_buf, *it;361 362 357 it = pj_hash_first(resolver->hquerybyid, &it_buf); 363 358 while (it) { … … 378 373 } 379 374 375 /* Destroy cached entries */ 376 it = pj_hash_first(resolver->hrescache, &it_buf); 377 while (it) { 378 struct cached_res *cache; 379 380 cache = (struct cached_res*) pj_hash_this(resolver->hrescache, it); 381 pj_hash_set(NULL, resolver->hrescache, &cache->key, 382 sizeof(cache->key), 0, NULL); 383 pj_pool_release(cache->pool); 384 385 it = pj_hash_first(resolver->hrescache, &it_buf); 386 } 387 380 388 if (resolver->own_timer && resolver->timer) { 381 389 pj_timer_heap_destroy(resolver->timer); … … 640 648 641 649 650 /* Allocate new cache entry */ 651 static struct cached_res *alloc_entry(pj_dns_resolver *resolver) 652 { 653 pj_pool_t *pool; 654 struct cached_res *cache; 655 656 pool = pj_pool_create(resolver->pool->factory, "dnscache", 657 RES_BUF_SZ, 256, NULL); 658 cache = PJ_POOL_ZALLOC_T(pool, struct cached_res); 659 cache->pool = pool; 660 661 return cache; 662 } 663 664 /* Put unused/expired cached entry to the free list */ 665 static void free_entry(pj_dns_resolver *resolver, struct cached_res *cache) 666 { 667 PJ_UNUSED_ARG(resolver); 668 pj_pool_release(cache->pool); 669 } 670 671 642 672 /* 643 673 * Create and start asynchronous DNS query for a single resource. … … 724 754 725 755 /* Store the entry into free nodes */ 726 pj_list_push_back(&resolver->res_free_nodes, cache);756 free_entry(resolver, cache); 727 757 728 758 /* Must continue with creating a query now */ … … 1066 1096 { 1067 1097 struct cached_res *cache; 1068 pj_pool_t *res_pool;1069 1098 pj_uint32_t hval=0, ttl; 1070 PJ_USE_EXCEPTION;1071 1099 1072 1100 /* If status is unsuccessful, clear the same entry from the cache */ … … 1075 1103 sizeof(*key), &hval); 1076 1104 if (cache) 1077 pj_list_push_back(&resolver->res_free_nodes, cache);1105 free_entry(resolver, cache); 1078 1106 pj_hash_set(NULL, resolver->hrescache, key, sizeof(*key), hval, NULL); 1079 1107 } … … 1111 1139 sizeof(*key), &hval); 1112 1140 if (cache) 1113 pj_list_push_back(&resolver->res_free_nodes, cache);1141 free_entry(resolver, cache); 1114 1142 pj_hash_set(NULL, resolver->hrescache, key, sizeof(*key), hval, NULL); 1115 1143 return; … … 1120 1148 sizeof(*key), &hval); 1121 1149 if (cache == NULL) { 1122 if (!pj_list_empty(&resolver->res_free_nodes)) { 1123 cache = resolver->res_free_nodes.next; 1124 pj_list_erase(cache); 1125 } else { 1126 cache = PJ_POOL_ZALLOC_T(resolver->pool, struct cached_res); 1127 } 1150 cache = alloc_entry(resolver); 1128 1151 } 1129 1152 … … 1134 1157 * the name being requested. 1135 1158 */ 1136 res_pool = pj_pool_create_on_buf("respool", cache->buf, sizeof(cache->buf)); 1137 PJ_TRY { 1138 cache->pkt = NULL; 1139 pj_dns_packet_dup(res_pool, pkt, 1140 PJ_DNS_NO_NS | PJ_DNS_NO_AR, 1141 &cache->pkt); 1142 } 1143 PJ_CATCH_ANY { 1144 PJ_LOG(1,(THIS_FILE, 1145 "Not enough memory to duplicate DNS response. Response was " 1146 "truncated.")); 1147 } 1148 PJ_END; 1159 cache->pkt = NULL; 1160 pj_dns_packet_dup(cache->pool, pkt, 1161 PJ_DNS_NO_NS | PJ_DNS_NO_AR, 1162 &cache->pkt); 1149 1163 1150 1164 /* Calculate expiration time */ … … 1163 1177 pj_hash_set_np(resolver->hrescache, &cache->key, sizeof(*key), hval, 1164 1178 cache->hbuf, cache); 1179 1165 1180 } 1166 1181 … … 1253 1268 { 1254 1269 pj_dns_resolver *resolver; 1255 pj_pool_t *pool ;1270 pj_pool_t *pool = NULL; 1256 1271 pj_dns_parsed_packet *dns_pkt; 1257 1272 pj_dns_async_query *q; … … 1383 1398 1384 1399 read_next_packet: 1400 if (pool) { 1401 /* needed just in case PJ_HAS_POOL_ALT_API is set */ 1402 pj_pool_release(pool); 1403 } 1385 1404 bytes_read = sizeof(resolver->udp_rx_pkt); 1386 1405 resolver->udp_addr_len = sizeof(resolver->udp_src_addr); … … 1516 1535 } 1517 1536 } 1518 PJ_LOG(3,(resolver->name.ptr, " Nb. of cached response free nodes: %u",1519 pj_list_size(&resolver->res_free_nodes)));1520 1537 PJ_LOG(3,(resolver->name.ptr, " Nb. of pending queries: %u (%u)", 1521 1538 pj_hash_count(resolver->hquerybyid),
Note: See TracChangeset
for help on using the changeset viewer.