diff src/core/ngx_module.c @ 6378:0f203a2af17c

Dynamic modules: moved module-related stuff to separate files.
author Maxim Dounin <mdounin@mdounin.ru>
date Thu, 04 Feb 2016 18:30:21 +0300
parents
children cf5e822cf470
line wrap: on
line diff
new file mode 100644
--- /dev/null
+++ b/src/core/ngx_module.c
@@ -0,0 +1,65 @@
+
+/*
+ * Copyright (C) Igor Sysoev
+ * Copyright (C) Maxim Dounin
+ * Copyright (C) Nginx, Inc.
+ */
+
+
+#include <ngx_config.h>
+#include <ngx_core.h>
+
+
+ngx_uint_t  ngx_max_module;
+
+
+ngx_int_t
+ngx_preinit_modules()
+{
+    ngx_uint_t  i;
+
+    ngx_max_module = 0;
+    for (i = 0; ngx_modules[i]; i++) {
+        ngx_modules[i]->index = ngx_max_module++;
+    }
+
+    return NGX_OK;
+}
+
+
+ngx_int_t
+ngx_init_modules(ngx_cycle_t *cycle)
+{
+    ngx_uint_t  i;
+
+    for (i = 0; ngx_modules[i]; i++) {
+        if (ngx_modules[i]->init_module) {
+            if (ngx_modules[i]->init_module(cycle) != NGX_OK) {
+                return NGX_ERROR;
+            }
+        }
+    }
+
+    return NGX_OK;
+}
+
+
+ngx_int_t
+ngx_count_modules(ngx_cycle_t *cycle, ngx_uint_t type)
+{
+    ngx_uint_t  i, max;
+
+    max = 0;
+
+    /* count appropriate modules, set up their indices */
+
+    for (i = 0; ngx_modules[i]; i++) {
+        if (ngx_modules[i]->type != type) {
+            continue;
+        }
+
+        ngx_modules[i]->ctx_index = max++;
+    }
+
+    return max;
+}