Commit 2cce91de authored by Sergey Lyubka's avatar Sergey Lyubka

Refactored code for multiple listeners

parent 0ff5b5b0
......@@ -4946,22 +4946,6 @@ 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 *value) {
int ind = get_option_index(name);
......@@ -4989,8 +4973,18 @@ const char *mg_set_option(struct mg_server *server, const char *name,
if (ind == LISTENING_PORT) {
struct vec vec;
while (!error_msg && (value = next_option(value, &vec, NULL)) != NULL) {
error_msg = add_listener(server, v, vec.ptr);
while ((value = next_option(value, &vec, NULL)) != NULL) {
struct ns_connection *c = ns_bind(&server->ns_mgr, vec.ptr,
mg_ev_handler, NULL);
if (c== NULL) {
error_msg = "Cannot bind to port";
break;
} else {
char buf[100];
ns_sock_to_str(c->sock, buf, sizeof(buf), 2);
free(*v);
*v = mg_strdup(buf);
}
}
#ifndef MONGOOSE_NO_FILESYSTEM
} 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