views:

467

answers:

1

I try to use keep-alive connection mongoose, but it seems mongoose close the connection first.

I changed the embed.c to send back the connection: keep-alive. The connection is still closed after response.

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:~$
+2  A: 

Currently it is impossible to do without changing Mongoose code. You can try to make a trick, in analyze_request() function, set the keep-alive flag:

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

There must be better mechanism of doing this from the callback, though.

valenok