]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
FS-5527 --resolve
authorAnthony Minessale <anthm@freeswitch.org>
Fri, 28 Jun 2013 15:42:01 +0000 (10:42 -0500)
committerAnthony Minessale <anthm@freeswitch.org>
Fri, 28 Jun 2013 15:42:06 +0000 (10:42 -0500)
libs/sofia-sip/.update
libs/sofia-sip/libsofia-sip-ua/nta/nta.c
libs/sofia-sip/libsofia-sip-ua/su/sofia-sip/su_time.h
libs/sofia-sip/libsofia-sip-ua/su/su_time0.c
src/mod/endpoints/mod_sofia/sofia.c

index 932e4da08782c9257ec6112405dab902bc81fcd0..8024eeba386a3a0324117c0e01933cf75aed35d8 100644 (file)
@@ -1 +1 @@
-Thu Jun 27 14:04:11 CDT 2013
+Fri Jun 28 10:39:50 CDT 2013
index f5d61e453030dfc0fd214d7ba27d6135c7b66d7c..68563978cd9f13f3ca33dccc9d740ad49365349b 100644 (file)
@@ -152,9 +152,7 @@ struct nta_agent_s
   nta_error_magic_t   *sa_error_magic;
   nta_error_tport_f   *sa_error_tport;
 
-  su_time_t             sa_now;         /**< Timestamp in microsecond resolution. */
   uint32_t              sa_next; /**< Timestamp for next agent_timer. */
-  uint32_t              sa_millisec; /**< Timestamp in milliseconds. */
 
   msg_mclass_t const   *sa_mclass;
   uint32_t sa_flags;           /**< SIP message flags */
@@ -1242,15 +1240,12 @@ void agent_timer(su_root_magic_t *rm, su_timer_t *timer, nta_agent_t *agent)
 
   agent->sa_next = 0;
 
-  agent->sa_now = stamp;
-  agent->sa_millisec = now;
   agent->sa_in_timer = 1;
 
+
   _nta_outgoing_timer(agent);
   _nta_incoming_timer(agent);
 
-  /* agent->sa_now is used only if sa_millisec != 0 */
-  agent->sa_millisec = 0;
   agent->sa_in_timer = 0;
 
   /* Calculate next timeout */
@@ -1335,12 +1330,12 @@ uint32_t set_timeout(nta_agent_t *agent, uint32_t offset)
   if (offset == 0)
     return 0;
 
-  if (agent->sa_millisec) /* Avoid expensive call to su_now() */
-    now = agent->sa_now, ms = agent->sa_millisec;
-  else
-    now = su_now(), ms = su_time_ms(now);
+  now = su_now();
+  ms = su_time_ms(now);
 
-  next = ms + offset; if (next == 0) next = 1;
+  next = ms + offset;
+
+  if (next == 0) next = 1;
 
   if (agent->sa_in_timer)      /* Currently executing timer */
     return next;
@@ -1365,9 +1360,6 @@ uint32_t set_timeout(nta_agent_t *agent, uint32_t offset)
 static
 su_time_t agent_now(nta_agent_t const *agent)
 {
-  if (agent && agent->sa_millisec != 0)
-    return agent->sa_now;
-  else
     return su_now();
 }
 
@@ -2784,8 +2776,6 @@ void agent_recv_message(nta_agent_t *agent,
 {
   sip_t *sip = sip_object(msg);
 
-  agent->sa_millisec = su_time_ms(agent->sa_now = now);
-
   if (sip && sip->sip_request) {
     agent_recv_request(agent, msg, sip, tport);
   }
@@ -2795,8 +2785,6 @@ void agent_recv_message(nta_agent_t *agent,
   else {
     agent_recv_garbage(agent, msg, tport);
   }
-
-  agent->sa_millisec = 0;
 }
 
 /** @internal Handle incoming requests. */
@@ -6869,7 +6857,7 @@ enum {
 static void
 _nta_incoming_timer(nta_agent_t *sa)
 {
-  uint32_t now = sa->sa_millisec;
+  uint32_t now = su_time_ms(su_now());
   nta_incoming_t *irq, *irq_next;
   size_t retransmitted = 0, timeout = 0, terminated = 0, destroyed = 0;
   size_t unconfirmed =
@@ -6886,6 +6874,9 @@ _nta_incoming_timer(nta_agent_t *sa)
 
   /* Handle retry queue */
   while ((irq = sa->sa_in.re_list)) {
+
+         now = su_time_ms(su_now());
+
     if ((int32_t)(irq->irq_retry - now) > 0)
       break;
     if (retransmitted >= timer_max_retransmit)
@@ -6943,6 +6934,8 @@ _nta_incoming_timer(nta_agent_t *sa)
   }
 
   while ((irq = sa->sa_in.final_failed->q_head)) {
+         
+
     incoming_remove(irq);
     irq->irq_final_failed = 0;
 
@@ -6974,6 +6967,8 @@ _nta_incoming_timer(nta_agent_t *sa)
     assert(irq->irq_status < 200);
     assert(irq->irq_timeout);
 
+       now = su_time_ms(su_now());
+
     if ((int32_t)(irq->irq_timeout - now) > 0)
       break;
     if (timeout >= timer_max_timeout)
@@ -6994,6 +6989,8 @@ _nta_incoming_timer(nta_agent_t *sa)
     assert(irq->irq_timeout);
     assert(irq->irq_method == sip_method_invite);
 
+       now = su_time_ms(su_now());
+
     if ((int32_t)(irq->irq_timeout - now) > 0 ||
        timeout >= timer_max_timeout ||
        terminated >= timer_max_terminate)
@@ -7022,6 +7019,8 @@ _nta_incoming_timer(nta_agent_t *sa)
     assert(irq->irq_status >= 200);
     assert(irq->irq_method == sip_method_invite);
 
+       now = su_time_ms(su_now());
+
     if ((int32_t)(irq->irq_timeout - now) > 0 ||
        terminated >= timer_max_terminate)
       break;
@@ -7044,6 +7043,8 @@ _nta_incoming_timer(nta_agent_t *sa)
     assert(irq->irq_timeout);
     assert(irq->irq_method != sip_method_invite);
 
+       now = su_time_ms(su_now());     
+
     if ((int32_t)(irq->irq_timeout - now) > 0 ||
        terminated >= timer_max_terminate)
       break;
@@ -7063,6 +7064,7 @@ _nta_incoming_timer(nta_agent_t *sa)
   }
 
   for (irq = sa->sa_in.terminated->q_head; irq; irq = irq_next) {
+         
     irq_next = irq->irq_next;
     if (irq->irq_destroyed)
       incoming_free_queue(rq, irq);
@@ -8727,7 +8729,7 @@ void outgoing_destroy(nta_outgoing_t *orq)
 static void
 _nta_outgoing_timer(nta_agent_t *sa)
 {
-  uint32_t now = sa->sa_millisec;
+  uint32_t now = su_time_ms(su_now());
   nta_outgoing_t *orq;
   outgoing_queue_t rq[1];
   size_t retransmitted = 0, terminated = 0, timeout = 0, destroyed;
@@ -8741,6 +8743,9 @@ _nta_outgoing_timer(nta_agent_t *sa)
   outgoing_queue_init(sa->sa_out.free = rq, 0);
 
   while ((orq = sa->sa_out.re_list)) {
+
+         now = su_time_ms(su_now());
+
     if ((int32_t)(orq->orq_retry - now) > 0)
       break;
     if (retransmitted >= timer_max_retransmit)
index b4acba6a7d87c1ec403a16bbf7a4ea69303fa2e2..ea347e80a0da95dc719b146684ec09830d4e2d7e 100644 (file)
@@ -85,6 +85,11 @@ typedef uint64_t su_nanotime_t;
 
 #define SU_E9 (1000000000U)
 
+typedef void (*su_time_func_t)(su_time_t *tv);
+
+
+SOFIAPUBFUN void su_set_time_func(su_time_func_t func);
+
 SOFIAPUBFUN su_nanotime_t su_nanotime(su_nanotime_t *return_time);
 SOFIAPUBFUN su_nanotime_t su_monotime(su_nanotime_t *return_time);
 
@@ -138,7 +143,7 @@ su_inline uint32_t su_ntp_fraq(su_time_t t)
 /** Time as milliseconds. */
 su_inline uint32_t su_time_ms(su_time_t t)
 {
-  return t.tv_sec * 1000 + (t.tv_usec + 500) / 1000;
+       return (t.tv_sec * 1000) + ((t.tv_usec + 500) / 1000);
 }
 #endif
 
index 0543e45aa0cf0a1fb19c01d269d0dabf2dab59f3..7267213156698ac5545d38fb5b3d5e2c383d01d5 100644 (file)
 void (*_su_time)(su_time_t *tv);
 uint64_t (*_su_nanotime)(uint64_t *);
 
+static su_time_func_t custom_time_func = NULL;
+
+void su_set_time_func(su_time_func_t func) {
+       custom_time_func = func;
+}
+
+
 /** Get current time.
  *
  * The function @c su_time() fills its argument with the current NTP
@@ -79,6 +86,13 @@ uint64_t (*_su_nanotime)(uint64_t *);
 void su_time(su_time_t *tv)
 {
        su_time_t ltv = {0,0};
+
+       if (custom_time_func) {
+               custom_time_func(&ltv);
+               if (tv) *tv = ltv;
+               return;
+       }
+
 #if HAVE_CLOCK_GETTIME
        struct timespec ctv = {0};
        if (clock_gettime(CLOCK_REALTIME, &ctv) == 0) {
index e9f5b9fea44598c43d089915d1a865218ef7b7f9..54b683441c04fb53272802ca508cc8ef0bbf6fc2 100644 (file)
@@ -3488,6 +3488,21 @@ static void config_sofia_profile_urls(sofia_profile_t * profile)
        }
 }
 
+#ifdef SOFIA_CUSTOM_TIME
+/* appears to not be granular enough */
+static void sofia_time(su_time_t *tv)
+{
+       switch_time_t now;
+
+       if (tv) {
+               now = switch_micro_time_now();
+               tv->tv_sec = ((uint32_t) (now / 1000000)) + 2208988800UL;
+               tv->tv_usec = (uint32_t) (now % 1000000);
+       }
+       
+}
+#endif
+
 switch_status_t sofia_init(void)
 {
        su_init();
@@ -3496,6 +3511,10 @@ switch_status_t sofia_init(void)
                return SWITCH_STATUS_GENERR;
        }
 
+#ifdef SOFIA_TIME
+       su_set_time_func(sofia_time);
+#endif
+
        /* Redirect loggers in sofia */
        su_log_redirect(su_log_default, logger, NULL);
        su_log_redirect(tport_log, logger, NULL);