我尝试使用keep-alive连接mongoose,但似乎mongoose首先关闭连接.
我更改了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:~$
小智.. 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 }
但是,必须有更好的机制来从回调中执行此操作.
目前,如果不改变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 }
但是,必须有更好的机制来从回调中执行此操作.