Changeset 979cfb4 for protocols/jabber


Ignore:
Timestamp:
2008-02-03T13:54:19Z (16 years ago)
Author:
Wilmer van der Gaast <wilmer@…>
Branches:
master
Children:
8c1eb80
Parents:
0fbda193
Message:

Saner garbage collection of cached packets in the Jabber module. Now
cached packets are removed after about ten minues instead of something
between one and two minutes. Closes one issue in #354.

Location:
protocols/jabber
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • protocols/jabber/jabber.h

    r0fbda193 r979cfb4  
    9595struct jabber_cache_entry
    9696{
     97        time_t saved_at;
    9798        struct xt_node *node;
    9899        jabber_cache_event func;
     
    140141#define JABBER_PACKET_ID "BeeP"
    141142#define JABBER_CACHED_ID "BeeC"
     143
     144/* The number of seconds to keep cached packets before garbage collecting
     145   them. This gc is done on every keepalive (every minute). */
     146#define JABBER_CACHE_MAX_AGE 600
    142147
    143148/* RFC 392[01] stuff */
  • protocols/jabber/jabber_util.c

    r0fbda193 r979cfb4  
    142142        entry->node = node;
    143143        entry->func = func;
     144        entry->saved_at = time( NULL );
    144145        g_hash_table_insert( jd->node_cache, xt_find_attr( node, "id" ), entry );
    145146}
     
    163164{
    164165        struct jabber_data *jd = ic->proto_data;
    165        
    166         g_hash_table_foreach_remove( jd->node_cache, jabber_cache_clean_entry, NULL );
    167 }
    168 
    169 gboolean jabber_cache_clean_entry( gpointer key, gpointer entry_, gpointer nullpointer )
     166        time_t threshold = time( NULL ) - JABBER_CACHE_MAX_AGE;
     167       
     168        g_hash_table_foreach_remove( jd->node_cache, jabber_cache_clean_entry, &threshold );
     169}
     170
     171gboolean jabber_cache_clean_entry( gpointer key, gpointer entry_, gpointer threshold_ )
    170172{
    171173        struct jabber_cache_entry *entry = entry_;
    172         struct xt_node *node = entry->node;
    173        
    174         if( node->flags & XT_SEEN )
    175                 return TRUE;
    176         else
    177         {
    178                 node->flags |= XT_SEEN;
    179                 return FALSE;
    180         }
     174        time_t *threshold = threshold_;
     175       
     176        return entry->saved_at < *threshold;
    181177}
    182178
Note: See TracChangeset for help on using the changeset viewer.