1

我尝试使用keep-alive连接猫鼬,但似乎猫鼬首先关闭了连接。

我更改了 embed.c 以发回连接:keep-alive。响应后连接仍然关闭。

border@ubuntu:~$ nc 127.0.0.1 9999
GET /test_get_request_info HTTP/1.1
Connection: keep-alive

HTTP/1.1 200 OK
Content-Type: text/plain
Connection: keep-alive

Method: [GET]
URI: [/test_get_request_info]
HTTP version: [1/1]
HTTP header [Connection]: [keep-alive]
Query string: []
POST data: []
Remote IP: [2130706433]
Remote port: [56719]
Remote user: []          <-----------------connection closed, nc returns
border@ubuntu:~$
4

1 回答 1

6

目前,不更改 Mongoose 代码是不可能的。您可以尝试制作一个技巧,在 analyze_request() 函数中设置 keep-alive 标志:

} else if ((cb = find_callback(conn->ctx, FALSE, uri, -1)) != NULL) {
        if ((strcmp(ri->request_method, "POST") != 0 &&
            strcmp(ri->request_method, "PUT") != 0) ||
            handle_request_body(conn, -1)) {
                cb->func(conn, &conn->request_info, cb->user_data);
                conn->keep_alive = TRUE;  // ADD THIS LINE
            }

但是,必须有更好的机制从回调中执行此操作。

于 2009-06-11T14:05:47.417 回答