Commit c16b2d17 authored by Olivier Crête's avatar Olivier Crête

Remove GTimeVal as it is deprecated in GLib

parent 6a6b4f4b
...@@ -80,22 +80,12 @@ static CandidateCheckPair *priv_conn_check_add_for_candidate_pair_matched ( ...@@ -80,22 +80,12 @@ static CandidateCheckPair *priv_conn_check_add_for_candidate_pair_matched (
static gboolean priv_update_selected_pair (NiceAgent *agent, static gboolean priv_update_selected_pair (NiceAgent *agent,
NiceComponent *component, CandidateCheckPair *pair); NiceComponent *component, CandidateCheckPair *pair);
static int priv_timer_expired (GTimeVal *timer, GTimeVal *now) static gint64 priv_timer_remainder (gint64 timer, gint64 now)
{ {
return (now->tv_sec == timer->tv_sec) ? if (now >= timer)
now->tv_usec >= timer->tv_usec :
now->tv_sec >= timer->tv_sec;
}
static unsigned int priv_timer_remainder (GTimeVal *timer, GTimeVal *now)
{
unsigned int delay;
if (now->tv_sec > timer->tv_sec ||
(now->tv_sec == timer->tv_sec && now->tv_usec > timer->tv_usec))
return 0; return 0;
delay = (timer->tv_sec - now->tv_sec) * 1000;
delay += ((signed long)(timer->tv_usec - now->tv_usec)) / 1000; return timer - now;
return delay;
} }
static gchar static gchar
...@@ -270,12 +260,12 @@ priv_print_conn_check_lists (NiceAgent *agent, const gchar *where, const gchar * ...@@ -270,12 +260,12 @@ priv_print_conn_check_lists (NiceAgent *agent, const gchar *where, const gchar *
{ {
GSList *i, *k, *l; GSList *i, *k, *l;
guint j, m; guint j, m;
GTimeVal now; gint64 now;
if (!nice_debug_is_verbose ()) if (!nice_debug_is_verbose ())
return; return;
g_get_current_time (&now); now = g_get_monotonic_time ();
#define PRIORITY_LEN 32 #define PRIORITY_LEN 32
...@@ -314,10 +304,10 @@ priv_print_conn_check_lists (NiceAgent *agent, const gchar *where, const gchar * ...@@ -314,10 +304,10 @@ priv_print_conn_check_lists (NiceAgent *agent, const gchar *where, const gchar *
for (l = pair->stun_transactions, m = 0; l; l = l->next, m++) { for (l = pair->stun_transactions, m = 0; l; l = l->next, m++) {
StunTransaction *stun = l->data; StunTransaction *stun = l->data;
nice_debug ("Agent %p : *** sc=%d/%d : pair %p : " nice_debug ("Agent %p : *** sc=%d/%d : pair %p : "
"stun#=%d timer=%d/%d %d/%dms buf=%p %s", "stun#=%d timer=%d/%d %" G_GINT64_FORMAT "/%dms buf=%p %s",
agent, pair->stream_id, pair->component_id, pair, m, agent, pair->stream_id, pair->component_id, pair, m,
stun->timer.retransmissions, stun->timer.max_retransmissions, stun->timer.retransmissions, stun->timer.max_retransmissions,
stun->timer.delay - priv_timer_remainder (&stun->next_tick, &now), stun->timer.delay - priv_timer_remainder (stun->next_tick, now),
stun->timer.delay, stun->timer.delay,
stun->message.buffer, stun->message.buffer,
(m == 0 && pair->retransmit) ? "(R)" : ""); (m == 0 && pair->retransmit) ? "(R)" : "");
...@@ -772,9 +762,9 @@ static gboolean priv_conn_check_tick_stream (NiceStream *stream, NiceAgent *agen ...@@ -772,9 +762,9 @@ static gboolean priv_conn_check_tick_stream (NiceStream *stream, NiceAgent *agen
GSList *i, *j; GSList *i, *j;
CandidateCheckPair *pair; CandidateCheckPair *pair;
unsigned int timeout; unsigned int timeout;
GTimeVal now; gint64 now;
g_get_current_time (&now); now = g_get_monotonic_time ();
/* step: process ongoing STUN transactions */ /* step: process ongoing STUN transactions */
for (i = stream->conncheck_list; i ; i = i->next) { for (i = stream->conncheck_list; i ; i = i->next) {
...@@ -802,15 +792,14 @@ static gboolean priv_conn_check_tick_stream (NiceStream *stream, NiceAgent *agen ...@@ -802,15 +792,14 @@ static gboolean priv_conn_check_tick_stream (NiceStream *stream, NiceAgent *agen
StunTransaction *s = j->data; StunTransaction *s = j->data;
GSList *next = j->next; GSList *next = j->next;
if (priv_timer_expired (&s->next_tick, &now)) if (now >= s->next_tick)
switch (stun_timer_refresh (&s->timer)) { switch (stun_timer_refresh (&s->timer)) {
case STUN_USAGE_TIMER_RETURN_TIMEOUT: case STUN_USAGE_TIMER_RETURN_TIMEOUT:
priv_remove_stun_transaction (p, s, component); priv_remove_stun_transaction (p, s, component);
break; break;
case STUN_USAGE_TIMER_RETURN_RETRANSMIT: case STUN_USAGE_TIMER_RETURN_RETRANSMIT:
timeout = stun_timer_remainder (&s->timer); timeout = stun_timer_remainder (&s->timer);
s->next_tick = now; s->next_tick = now + timeout * 1000;
g_time_val_add (&s->next_tick, timeout * 1000);
break; break;
default: default:
break; break;
...@@ -823,7 +812,7 @@ static gboolean priv_conn_check_tick_stream (NiceStream *stream, NiceAgent *agen ...@@ -823,7 +812,7 @@ static gboolean priv_conn_check_tick_stream (NiceStream *stream, NiceAgent *agen
/* process the first stun transaction of the list */ /* process the first stun transaction of the list */
stun = p->stun_transactions->data; stun = p->stun_transactions->data;
if (!priv_timer_expired (&stun->next_tick, &now)) if (now < stun->next_tick)
continue; continue;
switch (stun_timer_refresh (&stun->timer)) { switch (stun_timer_refresh (&stun->timer)) {
...@@ -871,16 +860,14 @@ timer_return_timeout: ...@@ -871,16 +860,14 @@ timer_return_timeout:
(gchar *)stun->buffer); (gchar *)stun->buffer);
/* note: convert from milli to microseconds for g_time_val_add() */ /* note: convert from milli to microseconds for g_time_val_add() */
stun->next_tick = now; stun->next_tick = now + timeout * 1000;
g_time_val_add (&stun->next_tick, timeout * 1000);
return TRUE; return TRUE;
case STUN_USAGE_TIMER_RETURN_SUCCESS: case STUN_USAGE_TIMER_RETURN_SUCCESS:
timeout = stun_timer_remainder (&stun->timer); timeout = stun_timer_remainder (&stun->timer);
/* note: convert from milli to microseconds for g_time_val_add() */ /* note: convert from milli to microseconds for g_time_val_add() */
stun->next_tick = now; stun->next_tick = now + timeout * 1000;
g_time_val_add (&stun->next_tick, timeout * 1000);
keep_timer_going = TRUE; keep_timer_going = TRUE;
break; break;
...@@ -2941,8 +2928,7 @@ int conn_check_send (NiceAgent *agent, CandidateCheckPair *pair) ...@@ -2941,8 +2928,7 @@ int conn_check_send (NiceAgent *agent, CandidateCheckPair *pair)
stun_timer_start (&stun->timer, timeout, agent->stun_max_retransmissions); stun_timer_start (&stun->timer, timeout, agent->stun_max_retransmissions);
} }
g_get_current_time (&stun->next_tick); stun->next_tick = g_get_monotonic_time () + timeout * 1000;
g_time_val_add (&stun->next_tick, timeout * 1000);
/* TCP-ACTIVE candidate must create a new socket before sending /* TCP-ACTIVE candidate must create a new socket before sending
* by connecting to the peer. The new socket is stored in the candidate * by connecting to the peer. The new socket is stored in the candidate
......
...@@ -75,7 +75,7 @@ typedef struct _StunTransaction StunTransaction; ...@@ -75,7 +75,7 @@ typedef struct _StunTransaction StunTransaction;
struct _StunTransaction struct _StunTransaction
{ {
GTimeVal next_tick; /* next tick timestamp */ gint64 next_tick; /* next tick timestamp */
StunTimer timer; StunTimer timer;
uint8_t buffer[STUN_MAX_MESSAGE_SIZE_IPV6]; uint8_t buffer[STUN_MAX_MESSAGE_SIZE_IPV6];
StunMessage message; StunMessage message;
......
...@@ -61,13 +61,6 @@ ...@@ -61,13 +61,6 @@
#include "stun/usages/turn.h" #include "stun/usages/turn.h"
#include "socket.h" #include "socket.h"
static inline int priv_timer_expired (GTimeVal *timer, GTimeVal *now)
{
return (now->tv_sec == timer->tv_sec) ?
now->tv_usec >= timer->tv_usec :
now->tv_sec >= timer->tv_sec;
}
/* /*
* Frees the CandidateDiscovery structure pointed to * Frees the CandidateDiscovery structure pointed to
* by 'user data'. Compatible with g_slist_free_full(). * by 'user data'. Compatible with g_slist_free_full().
...@@ -1172,7 +1165,7 @@ static gboolean priv_discovery_tick_unlocked (NiceAgent *agent) ...@@ -1172,7 +1165,7 @@ static gboolean priv_discovery_tick_unlocked (NiceAgent *agent)
agent->stun_max_retransmissions); agent->stun_max_retransmissions);
} }
g_get_current_time (&cand->next_tick); cand->next_tick = g_get_monotonic_time ();
} else { } else {
/* case: error in starting discovery, start the next discovery */ /* case: error in starting discovery, start the next discovery */
nice_debug ("Agent %p : Error starting discovery, skipping the item.", nice_debug ("Agent %p : Error starting discovery, skipping the item.",
...@@ -1191,15 +1184,13 @@ static gboolean priv_discovery_tick_unlocked (NiceAgent *agent) ...@@ -1191,15 +1184,13 @@ static gboolean priv_discovery_tick_unlocked (NiceAgent *agent)
} }
if (cand->done != TRUE) { if (cand->done != TRUE) {
GTimeVal now; gint64 now = g_get_monotonic_time ();
g_get_current_time (&now);
if (cand->stun_message.buffer == NULL) { if (cand->stun_message.buffer == NULL) {
nice_debug ("Agent %p : STUN discovery was cancelled, marking discovery done.", agent); nice_debug ("Agent %p : STUN discovery was cancelled, marking discovery done.", agent);
cand->done = TRUE; cand->done = TRUE;
} }
else if (priv_timer_expired (&cand->next_tick, &now)) { else if (now >= cand->next_tick) {
switch (stun_timer_refresh (&cand->timer)) { switch (stun_timer_refresh (&cand->timer)) {
case STUN_USAGE_TIMER_RETURN_TIMEOUT: case STUN_USAGE_TIMER_RETURN_TIMEOUT:
{ {
...@@ -1230,8 +1221,7 @@ static gboolean priv_discovery_tick_unlocked (NiceAgent *agent) ...@@ -1230,8 +1221,7 @@ static gboolean priv_discovery_tick_unlocked (NiceAgent *agent)
(gchar *)cand->stun_buffer); (gchar *)cand->stun_buffer);
/* note: convert from milli to microseconds for g_time_val_add() */ /* note: convert from milli to microseconds for g_time_val_add() */
cand->next_tick = now; cand->next_tick = now + (timeout * 1000);
g_time_val_add (&cand->next_tick, timeout * 1000);
++not_done; /* note: retry later */ ++not_done; /* note: retry later */
break; break;
...@@ -1240,8 +1230,7 @@ static gboolean priv_discovery_tick_unlocked (NiceAgent *agent) ...@@ -1240,8 +1230,7 @@ static gboolean priv_discovery_tick_unlocked (NiceAgent *agent)
{ {
unsigned int timeout = stun_timer_remainder (&cand->timer); unsigned int timeout = stun_timer_remainder (&cand->timer);
cand->next_tick = now; cand->next_tick = now + (timeout * 1000);
g_time_val_add (&cand->next_tick, timeout * 1000);
++not_done; /* note: retry later */ ++not_done; /* note: retry later */
break; break;
......
...@@ -49,7 +49,7 @@ typedef struct ...@@ -49,7 +49,7 @@ typedef struct
NiceCandidateType type; /* candidate type STUN or TURN */ NiceCandidateType type; /* candidate type STUN or TURN */
NiceSocket *nicesock; /* XXX: should be taken from local cand: existing socket to use */ NiceSocket *nicesock; /* XXX: should be taken from local cand: existing socket to use */
NiceAddress server; /* STUN/TURN server address */ NiceAddress server; /* STUN/TURN server address */
GTimeVal next_tick; /* next tick timestamp */ gint64 next_tick; /* next tick timestamp */
gboolean pending; /* is discovery in progress? */ gboolean pending; /* is discovery in progress? */
gboolean done; /* is discovery complete? */ gboolean done; /* is discovery complete? */
guint stream_id; guint stream_id;
......
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