diff options
Diffstat (limited to 'src/core')
| -rw-r--r-- | src/core/ngx_conf_file.c | 24 | ||||
| -rw-r--r-- | src/core/ngx_hunk.c | 49 | ||||
| -rw-r--r-- | src/core/ngx_hunk.h | 43 | ||||
| -rw-r--r-- | src/core/ngx_string.h | 1 |
4 files changed, 62 insertions, 55 deletions
diff --git a/src/core/ngx_conf_file.c b/src/core/ngx_conf_file.c index e38bbcede..de3bf75a0 100644 --- a/src/core/ngx_conf_file.c +++ b/src/core/ngx_conf_file.c @@ -206,7 +206,7 @@ static int ngx_conf_read_token(ngx_conf_t *cf) cf->args->nelts = 0; h = cf->conf_file->hunk; - start = h->pos.mem; + start = h->pos; #if 0 ngx_log_debug(cf->log, "TOKEN START"); @@ -214,31 +214,31 @@ ngx_log_debug(cf->log, "TOKEN START"); for ( ;; ) { - if (h->pos.mem >= h->last.mem) { + if (h->pos >= h->last) { if (cf->conf_file->file.offset >= ngx_file_size(cf->conf_file->file.info)) { return NGX_CONF_FILE_DONE; } - if (h->pos.mem - start) { - ngx_memcpy(h->start, start, h->pos.mem - start); + if (h->pos - start) { + ngx_memcpy(h->start, start, h->pos - start); } n = ngx_read_file(&cf->conf_file->file, - h->start + (h->pos.mem - start), - h->end - (h->start + (h->pos.mem - start)), + h->start + (h->pos - start), + h->end - (h->start + (h->pos - start)), cf->conf_file->file.offset); if (n == NGX_ERROR) { return NGX_ERROR; } - h->pos.mem = h->start + (h->pos.mem - start); + h->pos = h->start + (h->pos - start); start = h->start; - h->last.mem = h->pos.mem + n; + h->last = h->pos + n; } - ch = *h->pos.mem++; + ch = *h->pos++; #if 0 ngx_log_debug(cf->log, "%d:%d:%d:%d:%d '%c'" _ @@ -282,7 +282,7 @@ ngx_log_debug(cf->log, "%d:%d:%d:%d:%d '%c'" _ continue; } - start = h->pos.mem - 1; + start = h->pos - 1; switch (ch) { @@ -363,11 +363,11 @@ ngx_log_debug(cf->log, "%d:%d:%d:%d:%d '%c'" _ if (found) { ngx_test_null(word, ngx_push_array(cf->args), NGX_ERROR); ngx_test_null(word->data, - ngx_palloc(cf->pool, h->pos.mem - start + 1), + ngx_palloc(cf->pool, h->pos - start + 1), NGX_ERROR); for (dst = word->data, src = start, len = 0; - src < h->pos.mem - 1; + src < h->pos - 1; len++) { if (*src == '\\') { diff --git a/src/core/ngx_hunk.c b/src/core/ngx_hunk.c index e1e960fd3..fe26a3329 100644 --- a/src/core/ngx_hunk.c +++ b/src/core/ngx_hunk.c @@ -10,16 +10,14 @@ ngx_hunk_t *ngx_create_temp_hunk(ngx_pool_t *pool, int size, ngx_test_null(h, ngx_palloc(pool, sizeof(ngx_hunk_t)), NULL); -#if !(HAVE_OFFSET_EQUAL_PTR) - h->pos.file = h->last.file = 0; -#endif - ngx_test_null(h->pre_start, ngx_palloc(pool, size + before + after), NULL); - h->start = h->pos.mem = h->last.mem = h->pre_start + before; - h->end = h->last.mem + size; + + h->start = h->pos = h->last = h->pre_start + before; + h->file_pos = h->file_last = 0; + h->end = h->last + size; h->post_end = h->end + after; - h->type = NGX_HUNK_TEMP; + h->type = NGX_HUNK_TEMP|NGX_HUNK_IN_MEMORY; h->tag = 0; h->file = NULL; @@ -32,26 +30,24 @@ ngx_hunk_t *ngx_create_hunk_before(ngx_pool_t *pool, ngx_hunk_t *hunk, int size) ngx_test_null(h, ngx_palloc(pool, sizeof(ngx_hunk_t)), NULL); -#if !(HAVE_OFFSET_EQUAL_PTR) - h->pos.file = h->last.file = 0; -#endif - - if (hunk->type & NGX_HUNK_TEMP && hunk->pos.mem - hunk->pre_start >= size) { + if (hunk->type & NGX_HUNK_TEMP && hunk->pos - hunk->pre_start >= size) { /* keep hunk->start unchanged - used in restore */ h->pre_start = hunk->pre_start; - h->end = h->post_end = hunk->pre_start = hunk->pos.mem; - h->start = h->pos.mem = h->last.mem = h->end - size; + h->end = h->post_end = hunk->pre_start = hunk->pos; + h->start = h->pos = h->last = h->end - size; + h->file_pos = h->file_last = 0; - h->type = NGX_HUNK_TEMP; + h->type = NGX_HUNK_TEMP|NGX_HUNK_IN_MEMORY; h->tag = 0; h->file = NULL; } else { ngx_test_null(h->pre_start, ngx_palloc(pool, size), NULL); - h->start = h->pos.mem = h->last.mem = h->pre_start; + h->start = h->pos = h->last = h->pre_start; h->end = h->post_end = h->start + size; + h->file_pos = h->file_last = 0; - h->type = NGX_HUNK_TEMP; + h->type = NGX_HUNK_TEMP|NGX_HUNK_IN_MEMORY; h->tag = 0; h->file = NULL; } @@ -65,27 +61,26 @@ ngx_hunk_t *ngx_create_hunk_after(ngx_pool_t *pool, ngx_hunk_t *hunk, int size) ngx_test_null(h, ngx_palloc(pool, sizeof(ngx_hunk_t)), NULL); -#if !(HAVE_OFFSET_EQUAL_PTR) - h->pos.file = h->last.file = 0; -#endif - if (hunk->type & NGX_HUNK_TEMP - && hunk->last.mem == hunk->end + && hunk->last == hunk->end && hunk->post_end - hunk->end >= size) { h->post_end = hunk->post_end; - h->pre_start = h->start = h->pos.mem = h->last.mem = hunk->post_end = - hunk->last.mem; - h->type = NGX_HUNK_TEMP; + h->pre_start = h->start = h->pos = h->last = hunk->post_end = + hunk->last; + h->file_pos = h->file_last = 0; + + h->type = NGX_HUNK_TEMP|NGX_HUNK_IN_MEMORY; h->tag = 0; h->file = NULL; } else { ngx_test_null(h->pre_start, ngx_palloc(pool, size), NULL); - h->start = h->pos.mem = h->last.mem = h->pre_start; + h->start = h->pos = h->last = h->pre_start; h->end = h->post_end = h->start + size; + h->file_pos = h->file_last = 0; - h->type = NGX_HUNK_TEMP; + h->type = NGX_HUNK_TEMP|NGX_HUNK_IN_MEMORY; h->tag = 0; h->file = NULL; } diff --git a/src/core/ngx_hunk.h b/src/core/ngx_hunk.h index 2e16450e8..f5068c0c2 100644 --- a/src/core/ngx_hunk.h +++ b/src/core/ngx_hunk.h @@ -10,34 +10,34 @@ /* hunk type */ -/* temp means that hunk's content can be changed */ -/* other type means that hunk's content can not be changed */ -#define NGX_HUNK_TEMP 0x0001 -#define NGX_HUNK_MEMORY 0x0002 -#define NGX_HUNK_MMAP 0x0004 -#define NGX_HUNK_FILE 0x0008 +/* the hunk is in memory */ +#define NGX_HUNK_IN_MEMORY 0x0001 +/* the hunk's content can be changed */ +#define NGX_HUNK_TEMP 0x0002 +/* the hunk's content is in cache and can not be changed */ +#define NGX_HUNK_MEMORY 0x0004 +/* the hunk's content is mmap()ed and can not be changed */ +#define NGX_HUNK_MMAP 0x0008 + +#define NGX_HUNK_RECYCLED 0x0010 + +/* the hunk is in file */ +#define NGX_HUNK_FILE 0x0100 /* hunk flags */ /* in thread state flush means to write the hunk completely before return */ /* in event state flush means to start to write the hunk */ -#define NGX_HUNK_FLUSH 0x0100 +#define NGX_HUNK_FLUSH 0x1000 /* last hunk */ -#define NGX_HUNK_LAST 0x0200 -#if 0 -/* can be used with NGX_HUNK_LAST only */ -#define NGX_HUNK_SHUTDOWN 0x0400 / -#endif - -#define NGX_HUNK_RECYCLED 0x0800 - +#define NGX_HUNK_LAST 0x2000 -#define NGX_HUNK_IN_MEMORY (NGX_HUNK_TEMP|NGX_HUNK_MEMORY|NGX_HUNK_MMAP) typedef struct ngx_hunk_s ngx_hunk_t; struct ngx_hunk_s { +#if 0 union { char *mem; /* start of current data */ off_t file; @@ -46,6 +46,13 @@ struct ngx_hunk_s { char *mem; /* end of current data */ off_t file; } last; +#endif + + char *pos; + char *last; + off_t file_pos; + off_t file_last; + int type; char *start; /* start of hunk */ char *end; /* end of hunk */ @@ -67,6 +74,10 @@ struct ngx_chain_s { #define NGX_CHAIN_ERROR (ngx_chain_t *) NGX_ERROR +#define ngx_hunk_in_memory_only(h) \ + ((h->type & (NGX_HUNK_IN_MEMORY|NGX_HUNK_FILE)) == NGX_HUNK_IN_MEMORY) + + ngx_hunk_t *ngx_create_temp_hunk(ngx_pool_t *pool, int size, int before, int after); diff --git a/src/core/ngx_string.h b/src/core/ngx_string.h index 83ca4ba15..c9d5d8049 100644 --- a/src/core/ngx_string.h +++ b/src/core/ngx_string.h @@ -12,6 +12,7 @@ typedef struct { #define ngx_string(str) { sizeof(str) - 1, str } +#define ngx_null_string { 0, NULL } #if (WIN32) |
