Skip to content

Commit

Permalink
more global vars
Browse files Browse the repository at this point in the history
  • Loading branch information
Chrono Law committed Jan 4, 2016
1 parent fdad7ea commit e7cb0d0
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 5 deletions.
3 changes: 1 addition & 2 deletions ngxpp/Nginx.hpp
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
// Copyright (c) 2015
// Copyright (c) 2015-2016
// Author: Chrono Law
#ifndef _NGX_COMMON_HEADERS_HPP
#define _NGX_COMMON_HEADERS_HPP

extern "C" {

#include <ngx_http.h>
#include <nginx.h>

}

Expand Down
45 changes: 42 additions & 3 deletions ngxpp/NgxGlobal.hpp
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
// Copyright (c) 2015
// Copyright (c) 2015-2016
// Author: Chrono Law
#ifndef _NGX_GLOBAL_HPP
#define _NGX_GLOBAL_HPP

#include <nginx.h> // for NGINX_VER...
#include <boost/noncopyable.hpp>

#include "Nginx.hpp"

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

// apis: os(), err(), events(), process(), signal()
// apis: os(), err(), event(), process(), signal(), cycle(), env()
class NgxGlobal final
{
public:
Expand Down Expand Up @@ -51,7 +53,7 @@ class NgxGlobal final
struct process_info_t final : boost::noncopyable
{
// process/worker id
DECL_VAR(id, ngx_pid);
DECL_VAR(pid, ngx_pid);

// process flag = NGX_PROCESS_MASTER/NGX_PROCESS_SINGLE/...
DECL_VAR(type, ngx_process);
Expand Down Expand Up @@ -122,6 +124,43 @@ class NgxGlobal final
static signal_info_t s;
return s;
}
public:
// we can't use declyte(xxx)& because keyword 'volatile'
struct cycle_info_t final : boost::noncopyable
{
volatile DECL_VAR(connection_n, ngx_cycle->connection_n);

volatile DECL_VAR(conf_file, ngx_cycle->conf_file);
volatile DECL_VAR(conf_param, ngx_cycle->conf_param);
volatile DECL_VAR(conf_prefix, ngx_cycle->conf_prefix);
volatile DECL_VAR(prefix, ngx_cycle->prefix);
volatile DECL_VAR(hostname, ngx_cycle->hostname);
};

static cycle_info_t& cycle()
{
static cycle_info_t c;

return c;
}
public:
// some macro constants
struct env_info_t final : boost::noncopyable
{
// in nginx.h
ngx_str_t version = ngx_string(NGINX_VER);
ngx_str_t build = ngx_string(NGINX_VER_BUILD);

// in objs/ngx_auto_config.h
ngx_str_t configure = ngx_string(NGX_CONFIGURE);
ngx_str_t compiler = ngx_string(NGX_COMPILER);
};

static env_info_t& env()
{
static env_info_t e;
return e;
}
};

#undef DECL_VAR
Expand Down

0 comments on commit e7cb0d0

Please sign in to comment.