Commit 721fd589 authored by Pekka Pessi's avatar Pekka Pessi

sres: trying to avoid scheduling extra callbacks. Added sres_resolver_set_timer_cb().

darcs-hash:20061109143247-65a35-b2ba40d678235d2b3f24fb41168cc686fd5975ac.gz
parent 3d46e05f
......@@ -66,6 +66,8 @@ typedef SRES_ASYNC_T sres_async_t;
*
* If the new_socket is not -1, it indicates that resolver has created new
* socket that should be added to the poll() or select() set.
*
* @sa sres_resolver_set_async(), sres_resolver_get_async()
*/
typedef int sres_update_f(sres_async_t *async,
sres_socket_t new_socket,
......@@ -91,6 +93,23 @@ SRESPUBFUN int sres_resolver_sockets(sres_resolver_t *,
/** Resolver timer function. */
SRESPUBFUN void sres_resolver_timer(sres_resolver_t *, int dummy);
/** Prototype for scheduler function.
*
* This function is called when a timer callback is to be scheduled.
*
* @param async asynchronous object (registered with sres_resolver_set_async())
* @param interval interval in milliseconds
*
* @retval 0 when successful
* @retval -1 upon an error
*/
typedef int sres_schedule_f(sres_async_t *async, unsigned long interval);
/** Register resolver timer callback. */
SRESPUBFUN int sres_resolver_set_timer_cb(sres_resolver_t *res,
sres_schedule_f *callback,
sres_async_t *async);
/** Receive DNS response from socket. */
SRESPUBFUN int sres_resolver_receive(sres_resolver_t *, int socket);
......
......@@ -228,6 +228,7 @@ struct sres_resolver_s {
unsigned long res_updated;
sres_update_f *res_updcb;
sres_async_t *res_async;
sres_schedule_f *res_schedulecb;
short res_update_all;
uint16_t res_id;
......@@ -831,6 +832,7 @@ sres_resolver_set_async(sres_resolver_t *res,
return async;
}
/** Get async object */
sres_async_t *
sres_resolver_get_async(sres_resolver_t const *res,
sres_update_f *callback)
......@@ -845,6 +847,20 @@ sres_resolver_get_async(sres_resolver_t const *res,
return res->res_async;
}
/** Register resolver timer callback. */
int sres_resolver_set_timer_cb(sres_resolver_t *res,
sres_schedule_f *callback,
sres_async_t *async)
{
if (res == NULL)
return su_seterrno(EFAULT);
if (res->res_async != async)
return su_seterrno(EALREADY);
res->res_schedulecb = callback;
return 0;
}
/**Send a DNS query.
*
* Sends a DNS query with specified @a type and @a domain to the DNS server.
......@@ -1605,7 +1621,11 @@ sres_query_alloc(sres_resolver_t *res,
query->q_i_server = res->res_i_server;
query->q_n_servers = res->res_n_servers;
query->q_hash = query->q_id * Q_PRIME /* + query->q_i_server */;
sres_qtable_append(res->res_queries, query);
if (res->res_schedulecb && res->res_queries->qt_used == 1)
res->res_schedulecb(res->res_async, 2 * SRES_RETRANSMIT_INTERVAL);
}
return query;
......@@ -2751,6 +2771,9 @@ void sres_resolver_timer(sres_resolver_t *res, int dummy)
if (q != res->res_queries->qt_table[i])
i--;
}
if (res->res_schedulecb && res->res_queries->qt_used)
res->res_schedulecb(res->res_async, SRES_RETRANSMIT_INTERVAL);
}
sres_cache_clean(res->res_cache, res->res_now);
......
......@@ -86,6 +86,8 @@ static void sres_sofia_timer(su_root_magic_t *magic,
su_timer_t *t,
sres_sofia_t *arg);
static int sres_sofia_set_timer(sres_sofia_t *srs, unsigned long interval);
static int sres_sofia_poll(su_root_magic_t *, su_wait_t *,
sres_sofia_register_t *);
......@@ -131,8 +133,13 @@ sres_resolver_create(su_root_t *root,
if (!srs->srs_timer)
SU_DEBUG_3(("sres: cannot create timer\n"));
#if nomore
else if (su_timer_set_for_ever(t, sres_sofia_timer, srs) < 0)
SU_DEBUG_3(("sres: cannot set timer\n"));
#else
else if (sres_resolver_set_timer_cb(res, sres_sofia_set_timer, srs) < 0)
SU_DEBUG_3(("sres: cannot set timer cb\n"));
#endif
else
return res; /* Success! */
......@@ -322,6 +329,17 @@ sres_sofia_timer(su_root_magic_t *magic, su_timer_t *t, sres_sofia_t *srs)
sres_resolver_timer(srs->srs_resolver, -1);
}
/** Sofia timer set wrapper. */
static
int
sres_sofia_set_timer(sres_sofia_t *srs, unsigned long interval)
{
if (interval > SU_DURATION_MAX)
interval = SU_DURATION_MAX;
return su_timer_set_interval(srs->srs_timer, sres_sofia_timer, srs,
(su_duration_t)interval);
}
/** Sofia poll/select wrapper, called by su_root_t object */
static
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment