Plugins Lighttpd没有响应或响应很晚

Plugins Lighttpd没有响应或响应很晚,plugins,module,webserver,lighttpd,Plugins,Module,Webserver,Lighttpd,我为Lighttpd制作了一个简单的模块来进行实验。如果我只是从另一台计算机登录到我的计算机的Ip地址,并且我的计算机中的Web服务器(lighttpd)应该会发送一个简单的响应。该模块的源代码如下: #include "base.h" #include "log.h" #include "buffer.h" #include <stdio.h> #include "plugin.h" #include<sys/stat.h> #include<sys/types.

我为Lighttpd制作了一个简单的模块来进行实验。如果我只是从另一台计算机登录到我的计算机的Ip地址,并且我的计算机中的Web服务器(lighttpd)应该会发送一个简单的响应。该模块的源代码如下:

#include "base.h"
#include "log.h"
#include "buffer.h"
#include <stdio.h>
#include "plugin.h"
#include<sys/stat.h>
#include<sys/types.h>
#include <ctype.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include "stat_cache.h"
#include "etag.h"
#include "http_chunk.h"
#include "response.h"
/* plugin config for all request/connections */


typedef struct {
    array *match;
} plugin_config;



typedef struct {
    PLUGIN_DATA;

    buffer *match_buf;

    plugin_config **config_storage;

    plugin_config conf;
} plugin_data;



typedef struct {
    size_t foo;
} handler_ctx;



static handler_ctx * handler_ctx_init() {
    handler_ctx * hctx;

    hctx = calloc(1, sizeof(*hctx));

    return hctx;
}



static void handler_ctx_free(handler_ctx *hctx) {

    free(hctx);
}

/* init the plugin data */
INIT_FUNC(mod_helloworld_init) {
    plugin_data *p;

    p = calloc(1, sizeof(*p));

    p->match_buf = buffer_init();

    return p;
}



/* detroy the plugin data */
FREE_FUNC(mod_helloworld_free) {
    plugin_data *p = p_d;

    UNUSED(srv);

    if (!p) return HANDLER_GO_ON;

    if (p->config_storage) {
        size_t i;

        for (i = 0; i < srv->config_context->used; i++) {
            plugin_config *s = p->config_storage[i];

            if (!s) continue;

            array_free(s->match);

            free(s);
        }
        free(p->config_storage);
    }

    buffer_free(p->match_buf);

    free(p);

    return HANDLER_GO_ON;
}



/* handle plugin config and check values */

SETDEFAULTS_FUNC(mod_helloworld_set_defaults) {
    plugin_data *p = p_d;
    size_t i = 0;

    config_values_t cv[] = {
    { "helloworld.array",NULL, T_CONFIG_ARRAY, T_CONFIG_SCOPE_CONNECTION},       /* 0 */
    { NULL, NULL, T_CONFIG_UNSET, T_CONFIG_SCOPE_UNSET }
    };

    if (!p) return HANDLER_ERROR;

    p->config_storage = calloc(1, srv->config_context->used * sizeof(specific_config *));

    for (i = 0; i < srv->config_context->used; i++) {
        plugin_config *s;

        s = calloc(1, sizeof(plugin_config));
        s->match    = array_init();

        cv[0].destination = s->match;

        p->config_storage[i] = s;

        if (0 != config_insert_values_global(srv, ((data_config*)srv->config_context->data[i])->value, cv)) {
            return HANDLER_ERROR;
        }
    }

    return HANDLER_GO_ON;
}

#define PATCH(x) \
    p->conf.x = s->x;
static int mod_helloworld_patch_connection(server *srv, connection *con, plugin_data *p) {
    size_t i, j;
    plugin_config *s = p->config_storage[0];

    PATCH(match);

    /* skip the first, the global context */
    for (i = 1; i < srv->config_context->used; i++) {
        data_config *dc = (data_config *)srv->config_context->data[i];
        s = p->config_storage[i];

        /* condition didn't match */
        if (!config_check_cond(srv, con, dc)) continue;

        /* merge config */
        for (j = 0; j < dc->value->used; j++) {
            data_unset *du = dc->value->data[j];

            if (buffer_is_equal_string(du->key, CONST_STR_LEN("helloworld.array"))) {
                PATCH(match);
            }
        }
    }

    return 0;
}
#undef PATCH

URIHANDLER_FUNC(mod_helloworld_uri_handler) {


UNUSED(p_d);

// Send body data to requestor
char buffer[] = { '<', 'h', 't', 'm', 'l', '>' , '<', 'h', 'e', 'a', 'd', '>', '<', 't', 'i', 't', 'l', 'e', '>', '1', '<', '/', 't', 'i', 't', 'l', 'e', '>', '<', '/', 'h', 'e', 'a', 'd', '>', '<', '/', 'h', 't', 'm', 'l', '>'};

    char textValue[32];
    sprintf(textValue, "%d", sizeof(buffer));

response_header_overwrite(srv, con, CONST_STR_LEN("Content-Length"), textValue, strlen(textValue));
chunkqueue_append_mem(con->write_queue, buffer, sizeof(buffer)); 

//
con->http_status = 200;
return HANDLER_FINISHED;

}


int mod_helloworld_plugin_init(plugin *p) {
    p->version     = LIGHTTPD_VERSION_ID;
    p->name        = buffer_init_string("helloworld");

    p->init        = mod_helloworld_init;
    p->handle_subrequest_start  = mod_helloworld_uri_handler;
    p->set_defaults  = mod_helloworld_set_defaults;
    p->cleanup     = mod_helloworld_free;

    p->data        = NULL;

    return 0;
}
#包括“base.h”
#包括“log.h”
#包括“buffer.h”
#包括
#包括“plugin.h”
#包括
#包括
#包括
#包括
#包括
#包括
#包括“stat_cache.h”
#包括“etag.h”
#包括“http_chunk.h”
#包括“response.h”
/*所有请求/连接的插件配置*/
类型定义结构{
数组*匹配;
}插件配置;
类型定义结构{
插件数据;
缓冲区*match_buf;
插件配置**配置存储;
插件配置配置;
}插件数据;
类型定义结构{
尺寸(t foo);;
}handler_ctx;
静态处理程序\u ctx*处理程序\u ctx\u init(){
handler_ctx*hctx;
hctx=calloc(1,sizeof(*hctx));
返回hctx;
}
静态无效处理程序\u ctx\u free(处理程序\u ctx*hctx){
免费(hctx);
}
/*初始化插件数据*/
INIT_FUNC(mod_helloworld_INIT){
插件数据*p;
p=calloc(1,sizeof(*p));
p->match_buf=buffer_init();
返回p;
}
/*删除插件数据*/
FREE_FUNC(mod_helloworld_FREE){
plugin_data*p=p_d;
未使用(srv);
如果(!p)返回处理程序继续运行;
如果(p->配置存储){
尺寸i;
对于(i=0;iconfig\u context->used;i++){
plugin_config*s=p->config_storage[i];
如果(!s)继续;
无阵列->匹配;
免费的;
}
免费(p->配置存储);
}
缓冲区空闲(p->match\u buf);
自由基(p);
返回处理程序继续;
}
/*处理插件配置并检查值*/
SETDEFAULTS\u FUNC(mod\u helloworld\u set\u默认值){
plugin_data*p=p_d;
尺寸i=0;
配置值\u t cv[]={
{“helloworld.array”,NULL,T_CONFIG_array,T_CONFIG_SCOPE_CONNECTION},/*0*/
{NULL,NULL,T_CONFIG_UNSET,T_CONFIG_SCOPE_UNSET}
};
如果(!p)返回处理程序_错误;
p->config_storage=calloc(1,srv->config_context->used*sizeof(specific_config*);
对于(i=0;iconfig\u context->used;i++){
插件配置*s;
s=calloc(1,sizeof(plugin_config));
s->match=array_init();
cv[0]。目的地=s->匹配;
p->config_storage[i]=s;
如果(0!=配置\插入\值\全局(srv,((数据\配置*)srv->配置\上下文->数据[i])->值,cv)){
返回处理器错误;
}
}
返回处理程序继续;
}
#定义面片(x)\
p->conf.x=s->x;
静态int mod_helloworld_patch_连接(服务器*srv,连接*con,插件数据*p){
尺寸i,j;
plugin_config*s=p->config_storage[0];
补丁(匹配);
/*跳过第一个,全局上下文*/
对于(i=1;iconfig\u context->used;i++){
数据配置*dc=(数据配置*)srv->config\u context->data[i];
s=p->配置存储[i];
/*条件不匹配*/
如果(!配置检查条件(srv、con、dc))继续;
/*合并配置*/
对于(j=0;jvalue->used;j++){
数据_unset*du=dc->value->data[j];
if(buffer_等于字符串(du->key,CONST_STR_LEN(“helloworld.array”)){
补丁(匹配);
}
}
}
返回0;
}
#未定义补丁
URIHANDLER_FUNC(mod_helloworld_uri_handler){
未使用(p_d);
//向请求者发送正文数据
字符缓冲区[]={'','','','1','','',''};
字符文本值[32];
sprintf(textValue,“%d”,sizeof(buffer));
响应头覆盖(srv、con、CONST、STR、LEN(“内容长度”)、textValue、strlen(textValue));
chunkqueue_append_mem(con->write_queue,buffer,sizeof(buffer));
//
con->http_status=200;
返回处理程序(u)完成;;
}
int mod_helloworld_plugin_init(plugin*p){
p->version=LIGHTTPD\u version\u ID;
p->name=buffer_init_string(“helloworld”);
p->init=mod\u helloworld\u init;
p->handle\u subrequest\u start=mod\u helloworld\u uri\u handler;
p->set\u defaults=mod\u helloworld\u set\u defaults;
p->cleanup=mod_helloworld_free;
p->data=NULL;
返回0;
}
通过使用此模块,web服务器应使用标题为“1”的html页面进行响应。但现在我看到lighttpd发送响应的时间很晚,因此请求有时会超时。我不太明白出了什么问题。有人能帮我检查一下吗?我想只有Lighttpd的用户可能知道这个问题的解决方案。即使不使用Lighttpd,如果有人能帮我解决这个问题,我也会非常感激。谢谢。

尝试添加:

con->file_finished = 1;
之后:

con->http_status = 200;
这会告诉引擎请求已完成(为什么
HANDLER\u FINISHED
没有完成这是另一天的问题)