mirror of
https://github.com/cesanta/mongoose.git
synced 2026-11-19 19:40:56 +00:00
Refactored code for multiple listeners
This commit is contained in:
1 parent
0ff5b5b044
commit
2cce91de9a
1 file changed
+12
-18
+12
-18
@@ -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 *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);
|
||||||
@@ -4989,8 +4973,18 @@ const char *mg_set_option(struct mg_server *server, const char *name,
|
|||||||
|
|
||||||
if (ind == LISTENING_PORT) {
|
if (ind == LISTENING_PORT) {
|
||||||
struct vec vec;
|
struct vec vec;
|
||||||
while (!error_msg && (value = next_option(value, &vec, NULL)) != NULL) {
|
while ((value = next_option(value, &vec, NULL)) != NULL) {
|
||||||
error_msg = add_listener(server, v, vec.ptr);
|
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
|
#ifndef MONGOOSE_NO_FILESYSTEM
|
||||||
} else if (ind == HEXDUMP_FILE) {
|
} else if (ind == HEXDUMP_FILE) {
|
||||||
|
|||||||
Reference in new issue
Block a user