use ngx_queue.h

This commit is contained in:
Igor Sysoev 2007-12-20 21:01:00 +00:00
parent 181abe549f
commit 01a129d823
2 changed files with 16 additions and 24 deletions

View File

@ -1234,11 +1234,7 @@ ngx_ssl_session_cache_init(ngx_shm_zone_t *shm_zone, void *data)
ngx_rbtree_init(&cache->session_rbtree, &cache->sentinel, ngx_rbtree_init(&cache->session_rbtree, &cache->sentinel,
ngx_ssl_session_rbtree_insert_value); ngx_ssl_session_rbtree_insert_value);
cache->session_cache_head.prev = NULL; ngx_queue_init(&cache->expire_queue);
cache->session_cache_head.next = &cache->session_cache_tail;
cache->session_cache_tail.prev = &cache->session_cache_head;
cache->session_cache_tail.next = NULL;
shm_zone->data = cache; shm_zone->data = cache;
@ -1353,10 +1349,7 @@ ngx_ssl_new_session(ngx_ssl_conn_t *ssl_conn, ngx_ssl_session_t *sess)
sess_id->expire = ngx_time() + SSL_CTX_get_timeout(ssl_ctx); sess_id->expire = ngx_time() + SSL_CTX_get_timeout(ssl_ctx);
sess_id->next = cache->session_cache_head.next; ngx_queue_insert_head(&cache->expire_queue, &sess_id->queue);
sess_id->next->prev = sess_id;
sess_id->prev = &cache->session_cache_head;
cache->session_cache_head.next = sess_id;
ngx_rbtree_insert(&cache->session_rbtree, &sess_id->node); ngx_rbtree_insert(&cache->session_rbtree, &sess_id->node);
@ -1456,8 +1449,7 @@ ngx_ssl_get_cached_session(ngx_ssl_conn_t *ssl_conn, u_char *id, int len,
return sess; return sess;
} }
sess_id->next->prev = sess_id->prev; ngx_queue_remove(&sess_id->queue);
sess_id->prev->next = sess_id->next;
ngx_rbtree_delete(&cache->session_rbtree, node); ngx_rbtree_delete(&cache->session_rbtree, node);
@ -1539,8 +1531,8 @@ ngx_ssl_remove_session(SSL_CTX *ssl, ngx_ssl_session_t *sess)
rc = ngx_memn2cmp(id, sess_id->id, len, (size_t) node->data); rc = ngx_memn2cmp(id, sess_id->id, len, (size_t) node->data);
if (rc == 0) { if (rc == 0) {
sess_id->next->prev = sess_id->prev;
sess_id->prev->next = sess_id->next; ngx_queue_remove(&sess_id->queue);
ngx_rbtree_delete(&cache->session_rbtree, node); ngx_rbtree_delete(&cache->session_rbtree, node);
@ -1571,30 +1563,32 @@ ngx_ssl_expire_sessions(ngx_ssl_session_cache_t *cache,
ngx_slab_pool_t *shpool, ngx_uint_t n) ngx_slab_pool_t *shpool, ngx_uint_t n)
{ {
time_t now; time_t now;
ngx_queue_t *q;
ngx_ssl_sess_id_t *sess_id; ngx_ssl_sess_id_t *sess_id;
now = ngx_time(); now = ngx_time();
while (n < 3) { while (n < 3) {
sess_id = cache->session_cache_tail.prev; if (ngx_queue_empty(&cache->expire_queue)) {
if (sess_id == &cache->session_cache_head) {
return; return;
} }
q = ngx_queue_last(&cache->expire_queue);
sess_id = ngx_queue_data(q, ngx_ssl_sess_id_t, queue);
if (n++ != 0 && sess_id->expire > now) { if (n++ != 0 && sess_id->expire > now) {
return; return;
} }
sess_id->next->prev = sess_id->prev; ngx_queue_remove(q);
sess_id->prev->next = sess_id->next;
ngx_rbtree_delete(&cache->session_rbtree, &sess_id->node);
ngx_log_debug1(NGX_LOG_DEBUG_EVENT, ngx_cycle->log, 0, ngx_log_debug1(NGX_LOG_DEBUG_EVENT, ngx_cycle->log, 0,
"expire session: %08Xi", sess_id->node.key); "expire session: %08Xi", sess_id->node.key);
ngx_rbtree_delete(&cache->session_rbtree, &sess_id->node);
ngx_slab_free_locked(shpool, sess_id->session); ngx_slab_free_locked(shpool, sess_id->session);
#if (NGX_PTR_SIZE == 4) #if (NGX_PTR_SIZE == 4)
ngx_slab_free_locked(shpool, sess_id->id); ngx_slab_free_locked(shpool, sess_id->id);

View File

@ -64,8 +64,7 @@ struct ngx_ssl_sess_id_s {
u_char *id; u_char *id;
size_t len; size_t len;
u_char *session; u_char *session;
ngx_ssl_sess_id_t *prev; ngx_queue_t queue;
ngx_ssl_sess_id_t *next;
time_t expire; time_t expire;
#if (NGX_PTR_SIZE == 8) #if (NGX_PTR_SIZE == 8)
void *stub; void *stub;
@ -77,8 +76,7 @@ struct ngx_ssl_sess_id_s {
typedef struct { typedef struct {
ngx_rbtree_t session_rbtree; ngx_rbtree_t session_rbtree;
ngx_rbtree_node_t sentinel; ngx_rbtree_node_t sentinel;
ngx_ssl_sess_id_t session_cache_head; ngx_queue_t expire_queue;
ngx_ssl_sess_id_t session_cache_tail;
} ngx_ssl_session_cache_t; } ngx_ssl_session_cache_t;