Welcome! Log In Create A New Profile

Advanced

Re: All I want for easter is a working module

Mathew Heard
April 11, 2020 09:00PM
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@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@nginx.org
> http://mailman.nginx.org/mailman/listinfo/nginx
>
_______________________________________________
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx
Subject Author Posted

All I want for easter is a working module

splitice April 11, 2020 10:16AM

Re: All I want for easter is a working module

J.R. April 11, 2020 11:34AM

Re: All I want for easter is a working module

Mathew Heard April 11, 2020 09:00PM

Re: All I want for easter is a working module

daBee April 12, 2020 12:56AM

Re: All I want for easter is a working module

Mathew Heard April 12, 2020 02:34AM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 314
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready