From c1501fd3a77d1dc4669e4d9a895a9879381fe096 Mon Sep 17 00:00:00 2001 From: Kurt Zeilenga Date: Thu, 27 May 1999 22:48:14 +0000 Subject: [PATCH] Use difftime() to determine cache age. --- libraries/libldap/cache.c | 13 +++++++------ libraries/libldap/ldap-int.h | 2 +- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/libraries/libldap/cache.c b/libraries/libldap/cache.c index 46b2078d51..13d88bf29b 100644 --- a/libraries/libldap/cache.c +++ b/libraries/libldap/cache.c @@ -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 { diff --git a/libraries/libldap/ldap-int.h b/libraries/libldap/ldap-int.h index d818787487..fee3266cc9 100644 --- a/libraries/libldap/ldap-int.h +++ b/libraries/libldap/ldap-int.h @@ -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) /* -- 2.39.5