[Freeswitch-svn] [commit] r11949 - in freeswitch/trunk/libs/sofia-sip: . libsofia-sip-ua/sresolv libsofia-sip-ua/sresolv/sofia-resolv
FreeSWITCH SVN
mikej at freeswitch.org
Thu Feb 12 13:14:46 PST 2009
Author: mikej
Date: Thu Feb 12 15:14:45 2009
New Revision: 11949
Log:
Tue Feb 10 19:39:02 CST 2009 Pekka Pessi <first.last at nokia.com>
* sres_cache: added sres_cache_copy_answers()
Modified:
freeswitch/trunk/libs/sofia-sip/.update
freeswitch/trunk/libs/sofia-sip/libsofia-sip-ua/sresolv/sofia-resolv/sres_cache.h
freeswitch/trunk/libs/sofia-sip/libsofia-sip-ua/sresolv/sres_cache.c
freeswitch/trunk/libs/sofia-sip/libsofia-sip-ua/sresolv/torture_sresolv.c
Modified: freeswitch/trunk/libs/sofia-sip/.update
==============================================================================
--- freeswitch/trunk/libs/sofia-sip/.update (original)
+++ freeswitch/trunk/libs/sofia-sip/.update Thu Feb 12 15:14:45 2009
@@ -1 +1 @@
-Thu Feb 12 15:13:11 CST 2009
+Thu Feb 12 15:14:36 CST 2009
Modified: freeswitch/trunk/libs/sofia-sip/libsofia-sip-ua/sresolv/sofia-resolv/sres_cache.h
==============================================================================
--- freeswitch/trunk/libs/sofia-sip/libsofia-sip-ua/sresolv/sofia-resolv/sres_cache.h (original)
+++ freeswitch/trunk/libs/sofia-sip/libsofia-sip-ua/sresolv/sofia-resolv/sres_cache.h Thu Feb 12 15:14:45 2009
@@ -90,6 +90,10 @@
/** Free and zero one record. */
SRESPUBFUN void sres_cache_free_one(sres_cache_t *, sres_record_t *answer);
+/** Copy list of records */
+SRESPUBFUN
+sres_record_t **sres_cache_copy_answers(sres_cache_t *, sres_record_t **);
+
/** Remove old records from cache. */
SRESPUBFUN void sres_cache_clean(sres_cache_t *cache, time_t now);
Modified: freeswitch/trunk/libs/sofia-sip/libsofia-sip-ua/sresolv/sres_cache.c
==============================================================================
--- freeswitch/trunk/libs/sofia-sip/libsofia-sip-ua/sresolv/sres_cache.c (original)
+++ freeswitch/trunk/libs/sofia-sip/libsofia-sip-ua/sresolv/sres_cache.c Thu Feb 12 15:14:45 2009
@@ -131,6 +131,8 @@
void _sres_cache_free_one(sres_cache_t *cache, sres_record_t *answer);
su_inline
void _sres_cache_free_answers(sres_cache_t *cache, sres_record_t **answers);
+su_inline sres_record_t **_sres_cache_copy_answers(
+ sres_cache_t *, sres_record_t **);
static unsigned sres_hash_key(const char *string);
@@ -458,6 +460,20 @@
}
}
+/** Copy the list of records. */
+sres_record_t **
+sres_cache_copy_answers(sres_cache_t *cache, sres_record_t **answers)
+{
+ sres_record_t **copy = NULL;
+
+ if (answers && LOCK(cache)) {
+ copy = _sres_cache_copy_answers(cache, answers);
+ UNLOCK(cache);
+ }
+
+ return copy;
+}
+
/* ---------------------------------------------------------------------- */
/* Private functions */
@@ -488,6 +504,29 @@
}
}
+su_inline sres_record_t **
+_sres_cache_copy_answers(sres_cache_t *cache, sres_record_t **answers)
+{
+ int i, n;
+ sres_record_t **copy;
+
+ for (n = 0; answers[n] != NULL; n++)
+ ;
+
+ copy = su_alloc(cache->cache_home, (n + 1) * (sizeof *copy));
+ if (copy == NULL)
+ return NULL;
+
+ for (i = 0; i < n; i++) {
+ copy[i] = answers[i];
+ copy[i]->sr_refcount++;
+ }
+
+ copy[i] = NULL;
+
+ return copy;
+}
+
/** Calculate a hash key for a string */
static
unsigned
Modified: freeswitch/trunk/libs/sofia-sip/libsofia-sip-ua/sresolv/torture_sresolv.c
==============================================================================
--- freeswitch/trunk/libs/sofia-sip/libsofia-sip-ua/sresolv/torture_sresolv.c (original)
+++ freeswitch/trunk/libs/sofia-sip/libsofia-sip-ua/sresolv/torture_sresolv.c Thu Feb 12 15:14:45 2009
@@ -234,6 +234,7 @@
BEGIN();
sres_a_record_t *a, a0[1], **all;
+ sres_record_t **copy;
char host[128];
sres_cache_t *cache;
time_t now, base;
@@ -292,6 +293,11 @@
for (i = 0, N; i < N; i++)
TEST(all[i]->a_record->r_refcount, 2);
+ TEST_1(copy = sres_cache_copy_answers(cache, (sres_record_t **)all));
+
+ for (i = 0, N; i < N; i++)
+ TEST(all[i]->a_record->r_refcount, 3);
+
clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &t0);
for (now = base; now <= base + 3660; now += 30)
@@ -307,6 +313,11 @@
}
for (i = 0, N; i < N; i++)
+ TEST(all[i]->a_record->r_refcount, 2);
+
+ sres_cache_free_answers(cache, copy), copy = NULL;
+
+ for (i = 0, N; i < N; i++)
TEST(all[i]->a_record->r_refcount, 1);
base += 24 * 3600;
More information about the Freeswitch-svn
mailing list