summaryrefslogtreecommitdiffhomepage
path: root/src/core
diff options
context:
space:
mode:
authorIgor Sysoev <igor@sysoev.ru>2003-10-23 06:13:16 +0000
committerIgor Sysoev <igor@sysoev.ru>2003-10-23 06:13:16 +0000
commitf107910a9ef3b7de8752fc4e9e34cb69c1924a09 (patch)
tree35335e8d2e15d30819f6818ebc1871ee5a74b568 /src/core
parentdc9dd434aa1cfd24a98265742ff0ed4aeefc1f05 (diff)
downloadnginx-f107910a9ef3b7de8752fc4e9e34cb69c1924a09.tar.gz
nginx-f107910a9ef3b7de8752fc4e9e34cb69c1924a09.tar.bz2
nginx-0.0.1-2003-10-23-10:13:16 import
Diffstat (limited to 'src/core')
-rw-r--r--src/core/ngx_alloc.c86
-rw-r--r--src/core/ngx_alloc.h9
-rw-r--r--src/core/ngx_conf_file.c71
-rw-r--r--src/core/ngx_conf_file.h37
-rw-r--r--src/core/ngx_file.c2
5 files changed, 146 insertions, 59 deletions
diff --git a/src/core/ngx_alloc.c b/src/core/ngx_alloc.c
index 02c9342ac..32aa25c7e 100644
--- a/src/core/ngx_alloc.c
+++ b/src/core/ngx_alloc.c
@@ -20,6 +20,7 @@ void *ngx_alloc(size_t size, ngx_log_t *log)
return p;
}
+
void *ngx_calloc(size_t size, ngx_log_t *log)
{
void *p;
@@ -32,6 +33,7 @@ void *ngx_calloc(size_t size, ngx_log_t *log)
return p;
}
+
ngx_pool_t *ngx_create_pool(size_t size, ngx_log_t *log)
{
ngx_pool_t *p;
@@ -47,6 +49,7 @@ ngx_pool_t *ngx_create_pool(size_t size, ngx_log_t *log)
return p;
}
+
void ngx_destroy_pool(ngx_pool_t *pool)
{
ngx_pool_t *p, *n;
@@ -56,7 +59,9 @@ void ngx_destroy_pool(ngx_pool_t *pool)
#if (NGX_DEBUG_ALLOC)
ngx_log_debug(pool->log, "free: %08x" _ l->alloc);
#endif
- free(l->alloc);
+ if (l->alloc) {
+ free(l->alloc);
+ }
}
/*
@@ -85,6 +90,7 @@ void ngx_destroy_pool(ngx_pool_t *pool)
pool = NULL;
}
+
void *ngx_palloc(ngx_pool_t *pool, size_t size)
{
char *m;
@@ -107,53 +113,71 @@ void *ngx_palloc(ngx_pool_t *pool, size_t size)
}
}
- /* alloc new pool block */
+ /* alloc a new pool block */
+
ngx_test_null(n, ngx_create_pool(p->end - (char *) p, p->log), NULL);
p->next = n;
m = n->last;
n->last += size;
+
return m;
+ }
- /* alloc large block */
- } else {
- large = NULL;
- last = NULL;
-
- if (pool->large) {
- for (last = pool->large; /* void */; last = last->next) {
- if (last->alloc == NULL) {
- large = last;
- last = NULL;
- break;
- }
-
- if (last->next == NULL) {
- break;
- }
+ /* alloc a large block */
+
+ large = NULL;
+ last = NULL;
+
+ if (pool->large) {
+ for (last = pool->large; /* void */; last = last->next) {
+ if (last->alloc == NULL) {
+ large = last;
+ last = NULL;
+ break;
}
- }
- if (large == NULL) {
- ngx_test_null(large, ngx_palloc(pool, sizeof(ngx_pool_large_t)),
- NULL);
- large->next = NULL;
+ if (last->next == NULL) {
+ break;
+ }
}
+ }
- ngx_test_null(p, ngx_alloc(size, pool->log), NULL);
+ if (large == NULL) {
+ ngx_test_null(large, ngx_palloc(pool, sizeof(ngx_pool_large_t)), NULL);
+ large->next = NULL;
+ }
- if (pool->large == NULL) {
- pool->large = large;
+ ngx_test_null(p, ngx_alloc(size, pool->log), NULL);
- } else if (last) {
- last->next = large;
- }
+ if (pool->large == NULL) {
+ pool->large = large;
+
+ } else if (last) {
+ last->next = large;
+ }
+
+ large->alloc = p;
- large->alloc = p;
+ return p;
+}
- return p;
+
+void ngx_pfree(ngx_pool_t *pool, void *p)
+{
+ ngx_pool_large_t *l;
+
+ for (l = pool->large; l; l = l->next) {
+ if (p == l->alloc) {
+#if (NGX_DEBUG_ALLOC)
+ ngx_log_debug(pool->log, "free: %08x" _ l->alloc);
+#endif
+ free(l->alloc);
+ l->alloc = NULL;
+ }
}
}
+
void *ngx_pcalloc(ngx_pool_t *pool, size_t size)
{
void *p;
diff --git a/src/core/ngx_alloc.h b/src/core/ngx_alloc.h
index b63f4bdc1..946361182 100644
--- a/src/core/ngx_alloc.h
+++ b/src/core/ngx_alloc.h
@@ -6,9 +6,10 @@
#include <ngx_core.h>
-/* NGX_MAX_ALLOC_FROM_POOL should be (PAGE_SIZE - 1), i.e. 4095 on x86.
- On FreeBSD 5.x it allows to use zero copy send.
- On Windows NT it decreases number of locked pages in kernel.
+/*
+ * NGX_MAX_ALLOC_FROM_POOL should be (PAGE_SIZE - 1), i.e. 4095 on x86.
+ * On FreeBSD 5.x it allows to use zero copy send.
+ * On Windows NT it decreases number of locked pages in kernel.
*/
#define NGX_MAX_ALLOC_FROM_POOL 4095
@@ -44,6 +45,8 @@ void ngx_destroy_pool(ngx_pool_t *pool);
void *ngx_palloc(ngx_pool_t *pool, size_t size);
void *ngx_pcalloc(ngx_pool_t *pool, size_t size);
+void ngx_pfree(ngx_pool_t *pool, void *p);
+
#define ngx_free free
diff --git a/src/core/ngx_conf_file.c b/src/core/ngx_conf_file.c
index 70da2dcbe..a5a907ae1 100644
--- a/src/core/ngx_conf_file.c
+++ b/src/core/ngx_conf_file.c
@@ -546,6 +546,7 @@ char *ngx_conf_set_flag_slot(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
int flag;
ngx_str_t *value;
+
if (*(int *) (p + cmd->offset) != NGX_CONF_UNSET) {
return "is duplicate";
}
@@ -596,23 +597,25 @@ char *ngx_conf_set_num_slot(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
{
char *p = conf;
- int num, len;
+ int *np;
ngx_str_t *value;
- if (*(int *) (p + cmd->offset) != NGX_CONF_UNSET) {
+
+ np = (int *) (p + cmd->offset);
+
+ if (*np != NGX_CONF_UNSET) {
return "is duplicate";
}
value = (ngx_str_t *) cf->args->elts;
-
- len = value[1].len;
-
- num = ngx_atoi(value[1].data, len);
- if (num == NGX_ERROR) {
+ *np = ngx_atoi(value[1].data, value[1].len);
+ if (*np == NGX_ERROR) {
return "invalid number";
}
- *(int *) (p + cmd->offset) = num;
+ if (cmd->bounds) {
+ return cmd->bounds->check(cf, cmd->bounds, np);
+ }
return NGX_CONF_OK;
}
@@ -622,11 +625,14 @@ char *ngx_conf_set_size_slot(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
{
char *p = conf;
- int size, len, scale;
+ int size, len, scale, *np;
char last;
ngx_str_t *value;
- if (*(int *) (p + cmd->offset) != NGX_CONF_UNSET) {
+
+ np = (int *) (p + cmd->offset);
+
+ if (*np != NGX_CONF_UNSET) {
return "is duplicate";
}
@@ -658,8 +664,11 @@ char *ngx_conf_set_size_slot(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
}
size *= scale;
+ *np = size;
- *(int *) (p + cmd->offset) = size;
+ if (cmd->bounds) {
+ return cmd->bounds->check(cf, cmd->bounds, np);
+ }
return NGX_CONF_OK;
}
@@ -669,12 +678,15 @@ char *ngx_conf_set_msec_slot(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
{
char *p = conf;
- int size, total, len, scale;
+ int size, total, len, scale, *np;
u_int max, i;
char last, *start;
ngx_str_t *value;
- if (*(int *) (p + cmd->offset) != NGX_CONF_UNSET) {
+
+ np = (int *) (p + cmd->offset);
+
+ if (*np != NGX_CONF_UNSET) {
return "is duplicate";
}
@@ -756,7 +768,11 @@ char *ngx_conf_set_msec_slot(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
start = &value[1].data[i + 1];
}
- *(int *) (p + cmd->offset) = total;
+ *np = total;
+
+ if (cmd->bounds) {
+ return cmd->bounds->check(cf, cmd->bounds, np);
+ }
return NGX_CONF_OK;
}
@@ -766,12 +782,15 @@ char *ngx_conf_set_sec_slot(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
{
char *p = conf;
- int size, total, len, scale;
+ int size, total, len, scale, *np;
u_int max, i;
char last, *start;
ngx_str_t *value;
- if (*(int *) (p + cmd->offset) != NGX_CONF_UNSET) {
+
+ np = (int *) (p + cmd->offset);
+
+ if (*np != NGX_CONF_UNSET) {
return "is duplicate";
}
@@ -865,7 +884,11 @@ char *ngx_conf_set_sec_slot(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
start = &value[1].data[i + 1];
}
- *(int *) (p + cmd->offset) = total;
+ *np = total;
+
+ if (cmd->bounds) {
+ return cmd->bounds->check(cf, cmd->bounds, np);
+ }
return NGX_CONF_OK;
}
@@ -929,3 +952,17 @@ char *ngx_conf_unsupported(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
{
return "unsupported on this platform";
}
+
+
+char *ngx_conf_check_num_bounds(ngx_conf_t *cf, ngx_conf_bounds_t *bounds,
+ void *conf)
+{
+ int *num = conf;
+
+ if (*num >= bounds->type.num.low && *num <= bounds->type.num.high) {
+ return NGX_CONF_OK;
+
+ }
+
+ return "invalid value";
+}
diff --git a/src/core/ngx_conf_file.h b/src/core/ngx_conf_file.h
index 66ca2a912..e09cc65e9 100644
--- a/src/core/ngx_conf_file.h
+++ b/src/core/ngx_conf_file.h
@@ -52,17 +52,37 @@
#define NGX_CONF_MODULE 0x464E4F43 /* "CONF" */
+typedef struct ngx_conf_bounds_s ngx_conf_bounds_t;
+
+struct ngx_conf_bounds_s {
+ char *(*check)(ngx_conf_t *cf, ngx_conf_bounds_t *bounds, void *conf);
+
+ union {
+ struct {
+ int low;
+ int high;
+ } num;
+
+ struct num {
+ int low_num;
+ int high_num;
+ int low_size;
+ int high_size;
+ } bufs;
+ } type;
+};
+
struct ngx_command_s {
- ngx_str_t name;
- int type;
- char *(*set)(ngx_conf_t *cf, ngx_command_t *cmd, void *conf);
- int conf;
- int offset;
- void *bounds;
+ ngx_str_t name;
+ int type;
+ char *(*set)(ngx_conf_t *cf, ngx_command_t *cmd, void *conf);
+ int conf;
+ int offset;
+ ngx_conf_bounds_t *bounds;
};
-#define ngx_null_command {ngx_null_string, 0, NULL, 0, 0, NULL}
+#define ngx_null_command { ngx_null_string, 0, NULL, 0, 0, NULL }
struct ngx_open_file_s {
@@ -221,6 +241,9 @@ char *ngx_conf_set_bufs_slot(ngx_conf_t *cf, ngx_command_t *cmd, void *conf);
char *ngx_conf_set_core_flag_slot(ngx_conf_t *cf, ngx_command_t *cmd,
void *conf);
+char *ngx_conf_check_num_bounds(ngx_conf_t *cf, ngx_conf_bounds_t *bounds,
+ void *conf);
+
extern ngx_module_t *ngx_modules[];
extern ngx_cycle_t *ngx_cycle;
diff --git a/src/core/ngx_file.c b/src/core/ngx_file.c
index 538adff1d..2383e5c52 100644
--- a/src/core/ngx_file.c
+++ b/src/core/ngx_file.c
@@ -203,5 +203,5 @@ char *ngx_conf_set_path_slot(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
path->level[i++] = 0;
}
- return NULL;
+ return NGX_CONF_OK;
}