nginx 소스 학습 노트 (11) - 기본 용기 - ngxlist
2599 단어 nginx
typedef struct ngx_list_part_s ngx_list_part_t;
struct ngx_list_part_s {
void *elts; //
ngx_uint_t nelts; //
ngx_list_part_t *next; //
};
typedef struct {
ngx_list_part_t *last;
ngx_list_part_t part; //
size_t size; //
ngx_uint_t nalloc; //
ngx_pool_t *pool; //
} ngx_list_t;
list 동작:
// list
ngx_list_t *
ngx_list_create(ngx_pool_t *pool, ngx_uint_t n, size_t size)
{
ngx_list_t *list;
list = ngx_palloc(pool, sizeof(ngx_list_t)); // list
if (list == NULL) {
return NULL;
}
list->part.elts = ngx_palloc(pool, n * size); // list
if (list->part.elts == NULL) {
return NULL;
}
list->part.nelts = 0; // 0
list->part.next = NULL; //
list->last = &list->part; //
list->size = size; //
list->nalloc = n; //
list->pool = pool; //
return list; //
// ,
}
// , ,
void *
ngx_list_push(ngx_list_t *l)
{
void *elt;
ngx_list_part_t *last;
last = l->last;
if (last->nelts == l->nalloc) {
/* the last part is full, allocate a new list part */
last = ngx_palloc(l->pool, sizeof(ngx_list_part_t));
if (last == NULL) {
return NULL;
}
last->elts = ngx_palloc(l->pool, l->nalloc * l->size);
if (last->elts == NULL) {
return NULL;
}
last->nelts = 0;
last->next = NULL;
l->last->next = last;
l->last = last;
}
elt = (char *) last->elts + l->size * last->nelts;
last->nelts++;
return elt;
}
// list
part = &list.part;
data = part->elts;
for (i = 0 ;; i++) {
if (i >= part->nelts) {
if (part->next == NULL) {
break;
}
part = part->next;
data = part->elts;
i = 0;
}
... data[i] ...
}
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
간단! Certbot을 사용하여 웹 사이트를 SSL(HTTPS)화하는 방법초보자가 인프라 주위를 정돈하는 것은 매우 어렵습니다. 이번은 사이트를 간단하게 SSL화(HTTP에서 HTTPS통신)로 변경하는 방법을 소개합니다! 이번에는 소프트웨어 시스템 Nginx CentOS7 의 환경에서 S...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.