]> git.sur5r.net Git - openldap/commitdiff
Use difftime() to determine cache age.
authorKurt Zeilenga <kurt@openldap.org>
Thu, 27 May 1999 22:48:14 +0000 (22:48 +0000)
committerKurt Zeilenga <kurt@openldap.org>
Thu, 27 May 1999 22:48:14 +0000 (22:48 +0000)
libraries/libldap/cache.c
libraries/libldap/ldap-int.h

index 46b2078d51817e57b32679e3ce2153ad3f470a48..13d88bf29b42ac6eb55e375f35945fcdabb56782 100644 (file)
@@ -376,7 +376,7 @@ ldap_check_cache( LDAP *ld, unsigned long msgtype, BerElement *request )
        LDAPMessage     *m, *new, *prev, *next;
        BerElement      reqber;
        int             first, hash;
-       unsigned long   validtime;
+       time_t  c_time;
 
        Debug( LDAP_DEBUG_TRACE, "ldap_check_cache\n", 0, 0, 0 );
 
@@ -388,14 +388,14 @@ ldap_check_cache( LDAP *ld, unsigned long msgtype, BerElement *request )
        reqber.ber_buf = reqber.ber_ptr = request->ber_buf;
        reqber.ber_end = request->ber_ptr;
 
-       validtime = (long)time( NULL ) - ld->ld_cache->lc_timeout;
+       c_time = time( NULL );
 
        prev = NULLMSG;
        hash = cache_hash( &reqber );
        for ( m = ld->ld_cache->lc_buckets[ hash ]; m != NULLMSG; m = next ) {
                Debug( LDAP_DEBUG_TRACE,"cc: examining id %d,type %d\n",
                    m->lm_msgid, m->lm_msgtype, 0 );
-               if ( m->lm_time < validtime ) {
+               if ( difftime(c_time, m->lm_time) > ld->ld_cache->lc_timeout ) {
                        /* delete expired message */
                        next = m->lm_next;
                        if ( prev == NULL ) {
@@ -617,7 +617,8 @@ check_cache_memused( LDAPCache *lc )
  *    } while ( cache size is > SIZE_FACTOR * lc_maxmem )
  */
        int             i;
-       unsigned long   remove_threshold, validtime;
+       unsigned long   remove_threshold;
+       time_t c_time;
        LDAPMessage     *m, *prev, *next;
 
        Debug( LDAP_DEBUG_TRACE, "check_cache_memused: %ld bytes in use (%ld max)\n",
@@ -630,13 +631,13 @@ check_cache_memused( LDAPCache *lc )
 
        remove_threshold = lc->lc_timeout;
        while ( lc->lc_memused > lc->lc_maxmem * SIZE_FACTOR ) {
-               validtime = (long)time( NULL ) - remove_threshold;
+               c_time = time( NULL );
                for ( i = 0; i < LDAP_CACHE_BUCKETS; ++i ) {
                        prev = NULLMSG;
                        for ( m = lc->lc_buckets[ i ]; m != NULLMSG;
                            m = next ) {
                                next = m->lm_next;
-                               if ( m->lm_time < validtime ) {
+                               if ( difftime(c_time, m->lm_time) > remove_threshold) {
                                        if ( prev == NULLMSG ) {
                                                lc->lc_buckets[ i ] = next;
                                        } else {
index d818787487faefa353f591aa45cae718b4f9dc26..fee3266cc9cbcd6be1f345572e7d97b6226ef6f3 100644 (file)
@@ -73,7 +73,7 @@ struct ldapmsg {
        BerElement      *lm_ber;        /* the ber encoded message contents */
        struct ldapmsg  *lm_chain;      /* for search - next msg in the resp */
        struct ldapmsg  *lm_next;       /* next response */
-       unsigned int    lm_time;        /* used to maintain cache */
+       time_t  lm_time;        /* used to maintain cache */
 };
 #define NULLMSG ((LDAPMessage *)NULL)
 /*