Init modules in apache2

后端 未结 3 1366
失恋的感觉
失恋的感觉 2021-01-13 21:30

I used to write apache modules in apache 1.3, but these days I am willing to pass to apache2. The module that I am writing at the moment has is own binary data, not a databa

3条回答
  •  耶瑟儿~
    2021-01-13 21:42

    You can use a child_init hook to initialize a resource that will last longer then request or connection.

    typedef struct {
        apr_pool_t *pool;
        apr_hash_t *hash;
    } my_server_config;
    
    static void my_child_init(apr_pool_t *p, server_rec *s)
    {
        my_server_config cfg = ap_get_module_config(s->module_config, &my_module);
        /* Create sub-pool: ap_pool_create(&cfg->pool, p); */
        /* Create hash: cfg->hash = ap_hash_make(cfg->pool); */
    }
    
    static void my_register_hooks(apr_pool_t *p)
    {
        ap_hook_child_init(my_child_init, NULL, NULL, APR_HOOK_MIDDLE);
    }
    
    module AP_MODULE_DECLARE_DATA my_module =
    {
        STANDARD20_MODULE_STUFF,
        NULL,  /* per-directory config creator */
        NULL,  /* dir config merger */
        NULL,  /* server config creator */
        NULL,  /* server config merger */
        NULL,  /* command table */
        my_register_hooks, /* set up other request processing hooks */
    };
    

    Child init hook will be called before apache enters operational mode or before threads are created in threaded MPM. The pool passed into the my_child_init function should be process pool.

    For better example you should download apache source code and check the modules/experimental/mod_example.c file.

提交回复
热议问题