Changeset 2013:125c5728a8a3 in roaraudio for libroar/slp.c


Ignore:
Timestamp:
06/16/09 13:08:53 (15 years ago)
Author:
phi
Branch:
default
Phase:
public
Message:

added support for caching, need some more work

File:
1 edited

Legend:

Unmodified
Added
Removed
  • libroar/slp.c

    r2008 r2013  
    5757  self->match[self->matchcount].url[ROAR_SLP_MAX_URL_LEN-1] = 0; 
    5858 
     59  self->match[self->matchcount].tod  = time(NULL); 
     60  self->match[self->matchcount].tod += lifetime; 
     61 
    5962  self->matchcount++; 
    6063 } else { 
     
    143146 
    144147int    roar_slp_find_roard_r (char * addr, size_t len) { 
    145  struct roar_slp_cookie cookie; 
    146  int offset = 0; 
     148 static struct roar_slp_match    cache  = {"", 0}; 
     149        struct roar_slp_cookie   cookie; 
     150 int                             offset = 0; 
     151 char                          * url; 
    147152 
    148153 ROAR_DBG("roar_slp_find_roard_r(addr=%p, len=%i) = ?", addr, len); 
     
    153158 *addr = 0; // just in case... 
    154159 
    155  ROAR_DBG("roar_slp_find_roard_r(*) = ?"); 
    156  
    157  if ( roar_slp_cookie_init(&cookie, NULL) == -1 ) 
    158   return -1; 
    159  
    160  ROAR_DBG("roar_slp_find_roard_r(*) = ?"); 
    161  
    162  if ( roar_slp_search(&cookie, "service:mixer.fellig:roar") == -1 ) 
    163   return -1; 
    164  
    165  ROAR_DBG("roar_slp_find_roard_r(*) = ?"); 
    166  
    167  if ( cookie.matchcount == 0 ) 
    168   return -1; 
    169  
    170  ROAR_DBG("roar_slp_find_roard_r(*) = ?"); 
    171  
    172  if ( !strncmp(cookie.match[0].url, "service:mixer.fellig:roar://", 28) ) 
     160 if ( cache.tod < time(NULL) ) { 
     161  ROAR_WARN("roar_slp_find_roard_r(*): cache too old, searching for a new server..."); 
     162  ROAR_DBG("roar_slp_find_roard_r(*) = ?"); 
     163 
     164  if ( roar_slp_cookie_init(&cookie, NULL) == -1 ) 
     165   return -1; 
     166 
     167  ROAR_DBG("roar_slp_find_roard_r(*) = ?"); 
     168 
     169  if ( roar_slp_search(&cookie, "service:mixer.fellig:roar") == -1 ) 
     170   return -1; 
     171 
     172  ROAR_DBG("roar_slp_find_roard_r(*) = ?"); 
     173 
     174  if ( cookie.matchcount == 0 ) 
     175   return -1; 
     176 
     177  ROAR_DBG("roar_slp_find_roard_r(*) = ?"); 
     178 
     179  url = cookie.match[0].url; 
     180 
     181  ROAR_WARN("roar_slp_find_roard_r(*): found new server, caching it"); 
     182  memcpy(&cache, &(cookie.match[0]), sizeof(cache)); 
     183 } else { 
     184  ROAR_WARN("roar_slp_find_roard_r(*): cache within TTL, no need to search for server, using cache."); 
     185  url = cache.url; 
     186 } 
     187 
     188 if ( !strncmp(url, "service:mixer.fellig:roar://", 28) ) 
    173189  offset = 28; 
    174190 
    175191 ROAR_DBG("roar_slp_find_roard_r(*): url='%s'", cookie.match[0].url); 
    176192 
    177  strncpy(addr, &(cookie.match[0].url[offset]), len); 
     193 strncpy(addr, &(url[offset]), len); 
    178194 addr[len-1] = 0; // also just in case. 
    179195 
Note: See TracChangeset for help on using the changeset viewer.