|
1 |
| -// Copyright (c) 2015 |
| 1 | +// Copyright (c) 2015-2016 |
2 | 2 | // Author: Chrono Law
|
3 | 3 | #ifndef _NGX_GLOBAL_HPP
|
4 | 4 | #define _NGX_GLOBAL_HPP
|
5 | 5 |
|
| 6 | +#include <nginx.h> // for NGINX_VER... |
6 | 7 | #include <boost/noncopyable.hpp>
|
| 8 | + |
7 | 9 | #include "Nginx.hpp"
|
8 | 10 |
|
9 | 11 | #define DECL_VAR(x, y) decltype(y)& x = y
|
10 | 12 |
|
11 |
| -// apis: os(), err(), events(), process(), signal() |
| 13 | +// apis: os(), err(), event(), process(), signal(), cycle(), env() |
12 | 14 | class NgxGlobal final
|
13 | 15 | {
|
14 | 16 | public:
|
@@ -51,7 +53,7 @@ class NgxGlobal final
|
51 | 53 | struct process_info_t final : boost::noncopyable
|
52 | 54 | {
|
53 | 55 | // process/worker id
|
54 |
| - DECL_VAR(id, ngx_pid); |
| 56 | + DECL_VAR(pid, ngx_pid); |
55 | 57 |
|
56 | 58 | // process flag = NGX_PROCESS_MASTER/NGX_PROCESS_SINGLE/...
|
57 | 59 | DECL_VAR(type, ngx_process);
|
@@ -122,6 +124,43 @@ class NgxGlobal final
|
122 | 124 | static signal_info_t s;
|
123 | 125 | return s;
|
124 | 126 | }
|
| 127 | +public: |
| 128 | + // we can't use declyte(xxx)& because keyword 'volatile' |
| 129 | + struct cycle_info_t final : boost::noncopyable |
| 130 | + { |
| 131 | + volatile DECL_VAR(connection_n, ngx_cycle->connection_n); |
| 132 | + |
| 133 | + volatile DECL_VAR(conf_file, ngx_cycle->conf_file); |
| 134 | + volatile DECL_VAR(conf_param, ngx_cycle->conf_param); |
| 135 | + volatile DECL_VAR(conf_prefix, ngx_cycle->conf_prefix); |
| 136 | + volatile DECL_VAR(prefix, ngx_cycle->prefix); |
| 137 | + volatile DECL_VAR(hostname, ngx_cycle->hostname); |
| 138 | + }; |
| 139 | + |
| 140 | + static cycle_info_t& cycle() |
| 141 | + { |
| 142 | + static cycle_info_t c; |
| 143 | + |
| 144 | + return c; |
| 145 | + } |
| 146 | +public: |
| 147 | + // some macro constants |
| 148 | + struct env_info_t final : boost::noncopyable |
| 149 | + { |
| 150 | + // in nginx.h |
| 151 | + ngx_str_t version = ngx_string(NGINX_VER); |
| 152 | + ngx_str_t build = ngx_string(NGINX_VER_BUILD); |
| 153 | + |
| 154 | + // in objs/ngx_auto_config.h |
| 155 | + ngx_str_t configure = ngx_string(NGX_CONFIGURE); |
| 156 | + ngx_str_t compiler = ngx_string(NGX_COMPILER); |
| 157 | + }; |
| 158 | + |
| 159 | + static env_info_t& env() |
| 160 | + { |
| 161 | + static env_info_t e; |
| 162 | + return e; |
| 163 | + } |
125 | 164 | };
|
126 | 165 |
|
127 | 166 | #undef DECL_VAR
|
|
0 commit comments