Commit 0ff5b5b0 authored by Sergey Lyubka's avatar Sergey Lyubka

Added support for multiple listeners

parent 0c5d9a98
...@@ -2614,7 +2614,6 @@ static int should_keep_alive(const struct mg_connection *conn) { ...@@ -2614,7 +2614,6 @@ static int should_keep_alive(const struct mg_connection *conn) {
const char *method = conn->request_method; const char *method = conn->request_method;
const char *http_version = conn->http_version; const char *http_version = conn->http_version;
const char *header = mg_get_header(conn, "Connection"); const char *header = mg_get_header(conn, "Connection");
return 0;
return method != NULL && return method != NULL &&
(!strcmp(method, "GET") || c->endpoint_type == EP_USER) && (!strcmp(method, "GET") || c->endpoint_type == EP_USER) &&
((header != NULL && !mg_strcasecmp(header, "keep-alive")) || ((header != NULL && !mg_strcasecmp(header, "keep-alive")) ||
...@@ -4947,6 +4946,22 @@ static void set_default_option_values(char **opts) { ...@@ -4947,6 +4946,22 @@ static void set_default_option_values(char **opts) {
} }
} }
static const char *add_listener(struct mg_server *server, char **v,
const char *value) {
const char *error_msg = NULL;
struct ns_connection *c;
if ((c = ns_bind(&server->ns_mgr, value, mg_ev_handler, NULL)) == NULL) {
error_msg = "Cannot bind to port";
} else {
char buf[100];
ns_sock_to_str(c->sock, buf, sizeof(buf), 2);
free(*v);
*v = mg_strdup(buf);
}
return error_msg;
}
const char *mg_set_option(struct mg_server *server, const char *name, const char *mg_set_option(struct mg_server *server, const char *name,
const char *value) { const char *value) {
int ind = get_option_index(name); int ind = get_option_index(name);
...@@ -4973,14 +4988,9 @@ const char *mg_set_option(struct mg_server *server, const char *name, ...@@ -4973,14 +4988,9 @@ const char *mg_set_option(struct mg_server *server, const char *name,
DBG(("%s [%s]", name, *v)); DBG(("%s [%s]", name, *v));
if (ind == LISTENING_PORT) { if (ind == LISTENING_PORT) {
struct ns_connection *c = ns_bind(&server->ns_mgr, value, mg_ev_handler, NULL); struct vec vec;
if (c == NULL) { while (!error_msg && (value = next_option(value, &vec, NULL)) != NULL) {
error_msg = "Cannot bind to port"; error_msg = add_listener(server, v, vec.ptr);
} else {
char buf[100];
ns_sock_to_str(c->sock, buf, sizeof(buf), 2);
free(*v);
*v = mg_strdup(buf);
} }
#ifndef MONGOOSE_NO_FILESYSTEM #ifndef MONGOOSE_NO_FILESYSTEM
} else if (ind == HEXDUMP_FILE) { } else if (ind == HEXDUMP_FILE) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment