All I want for easter is a working module

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

All I want for easter is a working module

Mathew Heard
Could anyone help me out with the problem here? 

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");
}

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;
}


"Start timer" is output in the logs, but not "run timer". And I can't see why.

Regards,
Mathew

_______________________________________________
nginx mailing list
[hidden email]
http://mailman.nginx.org/mailman/listinfo/nginx
Reply | Threaded
Open this post in threaded view
|

Re: All I want for easter is a working module

J.R.
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
[hidden email]
http://mailman.nginx.org/mailman/listinfo/nginx
Reply | Threaded
Open this post in threaded view
|

Re: All I want for easter is a working module

Mathew Heard-2
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. <[hidden email]> 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
[hidden email]
http://mailman.nginx.org/mailman/listinfo/nginx

_______________________________________________
nginx mailing list
[hidden email]
http://mailman.nginx.org/mailman/listinfo/nginx
Reply | Threaded
Open this post in threaded view
|

Re: All I want for easter is a working module

Bee.Lists
I think he’s saying that there’s more to this than posting code and saying “no worky”.  

State what you want, what you have, what you’ve tried, and what you think might be going wrong.  Simply posting your code and expecting other troubleshooters to solve your issue, is the wrong approach.  

HE…nor anybody...doesn’t need to ask for your private code to answer your questions.  

At the best of times, the world is challenging.  Currently, it’s not so good.  You’ll attract more bees with honey.  


> On Apr 11, 2020, at 8:58 PM, Mathew Heard <[hidden email]> wrote:
>
> 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.



Cheers, Bee




_______________________________________________
nginx mailing list
[hidden email]
http://mailman.nginx.org/mailman/listinfo/nginx
Reply | Threaded
Open this post in threaded view
|

Re: All I want for easter is a working module

Mathew Heard-2
Gee, glad I don't need to ask for help often. Usually providing a minimal working example to replicate a problem and a concise description of the problem is a good thing. I'm a member of quite a few communities that I provide support for and this would have been an easy case of "your usage of that method looks correct to me".

Anyway it turns out that this is undocumented quirk. The default config (http://nginx.org/en/docs/dev/development_guide.html) provided for building a module builds a CORE type module which is initialized before the event system (add has no return value, and debug logs the correct output regardless). The documentation should probably mention that the ngx_add_timer is not available by default, also it would probably also be a good idea for the ngx_add_timer example to actually include a call to ngx_add_timer.

Anyway enjoy Easter everyone, it sounds like you all need to destress.

On Sun, 12 Apr 2020 at 14:55, Bee.Lists <[hidden email]> wrote:
I think he’s saying that there’s more to this than posting code and saying “no worky”. 

State what you want, what you have, what you’ve tried, and what you think might be going wrong.  Simply posting your code and expecting other troubleshooters to solve your issue, is the wrong approach. 

HE…nor anybody...doesn’t need to ask for your private code to answer your questions. 

At the best of times, the world is challenging.  Currently, it’s not so good.  You’ll attract more bees with honey.   


> On Apr 11, 2020, at 8:58 PM, Mathew Heard <[hidden email]> wrote:
>
> 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.



Cheers, Bee




_______________________________________________
nginx mailing list
[hidden email]
http://mailman.nginx.org/mailman/listinfo/nginx

_______________________________________________
nginx mailing list
[hidden email]
http://mailman.nginx.org/mailman/listinfo/nginx