Skip to content

Commit e7cb0d0

Browse files
author
Chrono Law
committed
more global vars
1 parent fdad7ea commit e7cb0d0

File tree

2 files changed

+43
-5
lines changed

2 files changed

+43
-5
lines changed

ngxpp/Nginx.hpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
1-
// Copyright (c) 2015
1+
// Copyright (c) 2015-2016
22
// Author: Chrono Law
33
#ifndef _NGX_COMMON_HEADERS_HPP
44
#define _NGX_COMMON_HEADERS_HPP
55

66
extern "C" {
77

88
#include <ngx_http.h>
9-
#include <nginx.h>
109

1110
}
1211

ngxpp/NgxGlobal.hpp

+42-3
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
1-
// Copyright (c) 2015
1+
// Copyright (c) 2015-2016
22
// Author: Chrono Law
33
#ifndef _NGX_GLOBAL_HPP
44
#define _NGX_GLOBAL_HPP
55

6+
#include <nginx.h> // for NGINX_VER...
67
#include <boost/noncopyable.hpp>
8+
79
#include "Nginx.hpp"
810

911
#define DECL_VAR(x, y) decltype(y)& x = y
1012

11-
// apis: os(), err(), events(), process(), signal()
13+
// apis: os(), err(), event(), process(), signal(), cycle(), env()
1214
class NgxGlobal final
1315
{
1416
public:
@@ -51,7 +53,7 @@ class NgxGlobal final
5153
struct process_info_t final : boost::noncopyable
5254
{
5355
// process/worker id
54-
DECL_VAR(id, ngx_pid);
56+
DECL_VAR(pid, ngx_pid);
5557

5658
// process flag = NGX_PROCESS_MASTER/NGX_PROCESS_SINGLE/...
5759
DECL_VAR(type, ngx_process);
@@ -122,6 +124,43 @@ class NgxGlobal final
122124
static signal_info_t s;
123125
return s;
124126
}
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+
}
125164
};
126165

127166
#undef DECL_VAR

0 commit comments

Comments
 (0)