-Thu Feb 12 15:13:11 CST 2009
+Thu Feb 12 15:14:36 CST 2009
/** 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);
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);
}
}
+/** 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 */
}
}
+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
BEGIN();
sres_a_record_t *a, a0[1], **all;
+ sres_record_t **copy;
char host[128];
sres_cache_t *cache;
time_t now, base;
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)
(unsigned)N, (long unsigned)t2.tv_sec, t2.tv_nsec);
}
+ 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);