mirror of
https://github.com/nginx/nginx.git
synced 2025-06-07 17:52:38 +08:00
stop rbtree search early if equal hash was found
This commit is contained in:
parent
1279b049b4
commit
e532b0194c
@ -1413,44 +1413,53 @@ ngx_ssl_get_cached_session(ngx_ssl_conn_t *ssl_conn, u_char *id, int len,
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (hash == node->key && (u_char) len == node->data) {
|
/* hash == node->key */
|
||||||
sess_id = (ngx_ssl_sess_id_t *) node;
|
|
||||||
|
|
||||||
if (ngx_strncmp(id, sess_id->id, len) == 0) {
|
do {
|
||||||
|
if ((u_char) len == node->data) {
|
||||||
|
sess_id = (ngx_ssl_sess_id_t *) node;
|
||||||
|
|
||||||
cached_sess = sess_id->session;
|
if (ngx_strncmp(id, sess_id->id, len) == 0) {
|
||||||
|
|
||||||
tp = ngx_timeofday();
|
cached_sess = sess_id->session;
|
||||||
|
|
||||||
if (cached_sess->expire > tp->sec) {
|
tp = ngx_timeofday();
|
||||||
ngx_memcpy(buf, &cached_sess->asn1[0], sess_id->len);
|
|
||||||
|
|
||||||
ngx_shmtx_unlock(&shpool->mutex);
|
if (cached_sess->expire > tp->sec) {
|
||||||
|
ngx_memcpy(buf, &cached_sess->asn1[0], sess_id->len);
|
||||||
|
|
||||||
p = buf;
|
ngx_shmtx_unlock(&shpool->mutex);
|
||||||
sess = d2i_SSL_SESSION(NULL, &p, sess_id->len);
|
|
||||||
|
|
||||||
return sess;
|
p = buf;
|
||||||
|
sess = d2i_SSL_SESSION(NULL, &p, sess_id->len);
|
||||||
|
|
||||||
|
return sess;
|
||||||
|
}
|
||||||
|
|
||||||
|
cached_sess->next->prev = cached_sess->prev;
|
||||||
|
cached_sess->prev->next = cached_sess->next;
|
||||||
|
|
||||||
|
ngx_rbtree_delete(cache->session_rbtree, node);
|
||||||
|
|
||||||
|
ngx_slab_free_locked(shpool, cached_sess);
|
||||||
|
ngx_slab_free_locked(shpool, sess_id->id);
|
||||||
|
ngx_slab_free_locked(shpool, sess_id);
|
||||||
|
|
||||||
|
sess = NULL;
|
||||||
|
|
||||||
|
goto done;
|
||||||
}
|
}
|
||||||
|
|
||||||
cached_sess->next->prev = cached_sess->prev;
|
|
||||||
cached_sess->prev->next = cached_sess->next;
|
|
||||||
|
|
||||||
ngx_rbtree_delete(cache->session_rbtree, node);
|
|
||||||
|
|
||||||
ngx_slab_free_locked(shpool, cached_sess);
|
|
||||||
ngx_slab_free_locked(shpool, sess_id->id);
|
|
||||||
ngx_slab_free_locked(shpool, sess_id);
|
|
||||||
|
|
||||||
sess = NULL;
|
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
node = node->right;
|
node = node->right;
|
||||||
|
|
||||||
|
} while (node != sentinel && hash == node->key);
|
||||||
|
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
done:
|
||||||
|
|
||||||
ngx_shmtx_unlock(&shpool->mutex);
|
ngx_shmtx_unlock(&shpool->mutex);
|
||||||
|
|
||||||
return sess;
|
return sess;
|
||||||
@ -1500,29 +1509,38 @@ ngx_ssl_remove_session(SSL_CTX *ssl, ngx_ssl_session_t *sess)
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (hash == node->key && len == node->data) {
|
/* hash == node->key */
|
||||||
sess_id = (ngx_ssl_sess_id_t *) node;
|
|
||||||
|
|
||||||
if (ngx_strncmp(id, sess_id->id, (size_t) len) == 0) {
|
do {
|
||||||
|
if ((u_char) len == node->data) {
|
||||||
|
sess_id = (ngx_ssl_sess_id_t *) node;
|
||||||
|
|
||||||
cached_sess = sess_id->session;
|
if (ngx_strncmp(id, sess_id->id, (size_t) len) == 0) {
|
||||||
|
|
||||||
cached_sess->next->prev = cached_sess->prev;
|
cached_sess = sess_id->session;
|
||||||
cached_sess->prev->next = cached_sess->next;
|
|
||||||
|
|
||||||
ngx_rbtree_delete(cache->session_rbtree, node);
|
cached_sess->next->prev = cached_sess->prev;
|
||||||
|
cached_sess->prev->next = cached_sess->next;
|
||||||
|
|
||||||
ngx_slab_free_locked(shpool, cached_sess);
|
ngx_rbtree_delete(cache->session_rbtree, node);
|
||||||
ngx_slab_free_locked(shpool, sess_id->id);
|
|
||||||
ngx_slab_free_locked(shpool, sess_id);
|
|
||||||
|
|
||||||
break;
|
ngx_slab_free_locked(shpool, cached_sess);
|
||||||
}
|
ngx_slab_free_locked(shpool, sess_id->id);
|
||||||
}
|
ngx_slab_free_locked(shpool, sess_id);
|
||||||
|
|
||||||
node = node->right;
|
goto done;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
node = node->right;
|
||||||
|
|
||||||
|
} while (node != sentinel && hash == node->key);
|
||||||
|
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
done:
|
||||||
|
|
||||||
ngx_shmtx_unlock(&shpool->mutex);
|
ngx_shmtx_unlock(&shpool->mutex);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user