All I want for easter is a working module

Mathew Heard me at mheard.com
Sun Apr 12 00:58:54 UTC 2020


J.R,

You won't find it publicly as all it is a testing module with the goal of
establishing a working timer. If you want the source code for it you need
only ask. Here you go.

/*
* Copyright (C) Mathew Heard.
*/


#include <ngx_config.h>
#include <ngx_core.h>
#include <ngx_http.h>
#include <ngx_event.h>

#define NGX_HTTP_SLOW_INTERVAL 7000

typedef struct {
ngx_flag_t enable;
} ngx_http_slow_conf_t;


static void *ngx_http_slow_create_conf(ngx_conf_t *cycle);
static char *ngx_http_slow_init_conf(ngx_conf_t *cycle, void *conf);

static char *ngx_http_slow_enable(ngx_conf_t *cf, void *post, void *data);
static ngx_conf_post_t ngx_http_slow_enable_post = { ngx_http_slow_enable };


static ngx_command_t ngx_http_slow_commands[] = {

{ ngx_string("slow"),
NGX_HTTP_MAIN_CONF|NGX_CONF_FLAG,
ngx_conf_set_flag_slot,
NGX_HTTP_MAIN_CONF_OFFSET,
offsetof(ngx_http_slow_conf_t, enable),
&ngx_http_slow_enable_post },

ngx_null_command
};

ngx_http_module_t ngx_http_slow_module_ctx = {
NULL, /* preconfiguration */
NULL, /* postconfiguration */

ngx_http_slow_create_conf, /* create main configuration */
ngx_http_slow_init_conf, /* init main configuration */

NULL, /* create server configuration */
NULL, /* merge server configuration */

NULL, /* create location configuration */
NULL /* merge location configuration */
};

static ngx_int_t ngx_http_slow_init_worker(ngx_cycle_t *cycle);

ngx_module_t ngx_http_slow_module = {
NGX_MODULE_V1,
&ngx_http_slow_module_ctx, /* module context */
ngx_http_slow_commands, /* module directives */
NGX_HTTP_MODULE, /* module type */
NULL, /* init master */
NULL, /* init module */
ngx_http_slow_init_worker, /* init process */
NULL, /* init thread */
NULL, /* exit thread */
NULL, /* exit process */
NULL, /* exit master */
NGX_MODULE_V1_PADDING
};


void ngx_http_slow_handler(ngx_event_t *ev){
ngx_log_error(NGX_LOG_ERR, ev->log, 0, "run timer");
// set up the next tick in n seconds
if (ngx_exiting) {
return;
}
ngx_add_timer(ev, (ngx_msec_t)NGX_HTTP_SLOW_INTERVAL);
}

static ngx_event_t ngx_http_slow_timer;
static ngx_connection_t dumb;

static ngx_int_t ngx_http_slow_init_worker(ngx_cycle_t *cycle){
if (ngx_process != NGX_PROCESS_WORKER){
return NGX_OK;
}

ngx_log_error(NGX_LOG_ERR, ngx_cycle->log, 0, "start timer");
memset(&ngx_http_slow_timer, 0, sizeof(ngx_http_slow_timer));
ngx_http_slow_timer.log = ngx_cycle->log;
ngx_http_slow_timer.handler = ngx_http_slow_handler;
ngx_http_slow_timer.data = &dumb;
dumb.fd = (ngx_socket_t) -1;
ngx_add_timer(&ngx_http_slow_timer, (ngx_msec_t)NGX_HTTP_SLOW_INTERVAL);

return NGX_OK;
}

static void *
ngx_http_slow_create_conf(ngx_conf_t *cycle)
{
ngx_http_slow_conf_t *fcf;

fcf = ngx_pcalloc(cycle->pool, sizeof(ngx_http_slow_conf_t));
if (fcf == NULL) {
return NULL;
}

fcf->enable = NGX_CONF_UNSET;

return fcf;
}


static char *
ngx_http_slow_init_conf(ngx_conf_t *cycle, void *conf)
{
ngx_http_slow_conf_t *fcf = conf;

ngx_conf_init_value(fcf->enable, 0);

return NGX_CONF_OK;
}


static char *
ngx_http_slow_enable(ngx_conf_t *cf, void *post, void *data)
{
ngx_flag_t *fp = data;

if (*fp == 0) {
return NGX_CONF_OK;
}

return NGX_CONF_OK;
}

On Sun, 12 Apr 2020 at 01:33, J.R. <themadbeaker at gmail.com> wrote:

> I've never heard of 'ngx_http_slow_module'... Is there a github page
> or similar with the source code?
>
> It's going to take more than just selective snippets if you really
> want someone to help debug it...
> _______________________________________________
> nginx mailing list
> nginx at nginx.org
> http://mailman.nginx.org/mailman/listinfo/nginx
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.nginx.org/pipermail/nginx/attachments/20200412/3f7d6935/attachment-0001.htm>


More information about the nginx mailing list