mirror of
https://github.com/cesanta/mongoose.git
synced 2024-12-27 15:01:03 +08:00
Fix keep-alive handling in process_new_connection()
This commit is contained in:
parent
05fa677382
commit
113c9d5a02
11
mongoose.c
11
mongoose.c
@ -4759,10 +4759,11 @@ static int is_valid_uri(const char *uri) {
|
||||
|
||||
static void process_new_connection(struct mg_connection *conn) {
|
||||
struct mg_request_info *ri = &conn->request_info;
|
||||
int keep_alive_enabled, discard_len;
|
||||
int keep_alive_enabled, keep_alive, discard_len;
|
||||
const char *cl;
|
||||
|
||||
keep_alive_enabled = !strcmp(conn->ctx->config[ENABLE_KEEP_ALIVE], "yes");
|
||||
keep_alive = 0;
|
||||
|
||||
// Important: on new connection, reset the receiving buffer. Credit goes
|
||||
// to crule42.
|
||||
@ -4808,6 +4809,12 @@ static void process_new_connection(struct mg_connection *conn) {
|
||||
free((void *) ri->remote_user);
|
||||
}
|
||||
|
||||
// NOTE(lsm): order is important here. should_keep_alive() call
|
||||
// is using parsed request, which will be invalid after memmove's below.
|
||||
// Therefore, memorize should_keep_alive() result now for later use
|
||||
// in loop exit condition.
|
||||
keep_alive = should_keep_alive(conn);
|
||||
|
||||
// Discard all buffered data for this request
|
||||
discard_len = conn->content_len >= 0 &&
|
||||
conn->request_len + conn->content_len < (int64_t) conn->data_len ?
|
||||
@ -4820,7 +4827,7 @@ static void process_new_connection(struct mg_connection *conn) {
|
||||
} while (conn->ctx->stop_flag == 0 &&
|
||||
keep_alive_enabled &&
|
||||
conn->content_len >= 0 &&
|
||||
should_keep_alive(conn));
|
||||
keep_alive);
|
||||
}
|
||||
|
||||
// Worker threads take accepted socket from the queue
|
||||
|
Loading…
x
Reference in New Issue
Block a user