Klaus Demo nginx / 01a129d
use ngx_queue.h Igor Sysoev 14 years ago
2 changed file(s) with 16 addition(s) and 24 deletion(s). Raw diff Collapse all Expand all
12331233 ngx_rbtree_init(&cache->session_rbtree, &cache->sentinel,
12341234 ngx_ssl_session_rbtree_insert_value);
12351235
1236 cache->session_cache_head.prev = NULL;
1237 cache->session_cache_head.next = &cache->session_cache_tail;
1238
1239 cache->session_cache_tail.prev = &cache->session_cache_head;
1240 cache->session_cache_tail.next = NULL;
1236 ngx_queue_init(&cache->expire_queue);
12411237
12421238 shm_zone->data = cache;
12431239
13521348
13531349 sess_id->expire = ngx_time() + SSL_CTX_get_timeout(ssl_ctx);
13541350
1355 sess_id->next = cache->session_cache_head.next;
1356 sess_id->next->prev = sess_id;
1357 sess_id->prev = &cache->session_cache_head;
1358 cache->session_cache_head.next = sess_id;
1351 ngx_queue_insert_head(&cache->expire_queue, &sess_id->queue);
13591352
13601353 ngx_rbtree_insert(&cache->session_rbtree, &sess_id->node);
13611354
14551448 return sess;
14561449 }
14571450
1458 sess_id->next->prev = sess_id->prev;
1459 sess_id->prev->next = sess_id->next;
1451 ngx_queue_remove(&sess_id->queue);
14601452
14611453 ngx_rbtree_delete(&cache->session_rbtree, node);
14621454
15381530 rc = ngx_memn2cmp(id, sess_id->id, len, (size_t) node->data);
15391531
15401532 if (rc == 0) {
1541 sess_id->next->prev = sess_id->prev;
1542 sess_id->prev->next = sess_id->next;
1533
1534 ngx_queue_remove(&sess_id->queue);
15431535
15441536 ngx_rbtree_delete(&cache->session_rbtree, node);
15451537
15701562 ngx_slab_pool_t *shpool, ngx_uint_t n)
15711563 {
15721564 time_t now;
1565 ngx_queue_t *q;
15731566 ngx_ssl_sess_id_t *sess_id;
15741567
15751568 now = ngx_time();
15761569
15771570 while (n < 3) {
15781571
1579 sess_id = cache->session_cache_tail.prev;
1580
1581 if (sess_id == &cache->session_cache_head) {
1572 if (ngx_queue_empty(&cache->expire_queue)) {
15821573 return;
15831574 }
1575
1576 q = ngx_queue_last(&cache->expire_queue);
1577
1578 sess_id = ngx_queue_data(q, ngx_ssl_sess_id_t, queue);
15841579
15851580 if (n++ != 0 && sess_id->expire > now) {
15861581 return;
15871582 }
15881583
1589 sess_id->next->prev = sess_id->prev;
1590 sess_id->prev->next = sess_id->next;
1591
1592 ngx_rbtree_delete(&cache->session_rbtree, &sess_id->node);
1584 ngx_queue_remove(q);
15931585
15941586 ngx_log_debug1(NGX_LOG_DEBUG_EVENT, ngx_cycle->log, 0,
15951587 "expire session: %08Xi", sess_id->node.key);
1588
1589 ngx_rbtree_delete(&cache->session_rbtree, &sess_id->node);
15961590
15971591 ngx_slab_free_locked(shpool, sess_id->session);
15981592 #if (NGX_PTR_SIZE == 4)
6363 u_char *id;
6464 size_t len;
6565 u_char *session;
66 ngx_ssl_sess_id_t *prev;
67 ngx_ssl_sess_id_t *next;
66 ngx_queue_t queue;
6867 time_t expire;
6968 #if (NGX_PTR_SIZE == 8)
7069 void *stub;
7675 typedef struct {
7776 ngx_rbtree_t session_rbtree;
7877 ngx_rbtree_node_t sentinel;
79 ngx_ssl_sess_id_t session_cache_head;
80 ngx_ssl_sess_id_t session_cache_tail;
78 ngx_queue_t expire_queue;
8179 } ngx_ssl_session_cache_t;
8280
8381