Commit f059e41c authored by Sergey Lyubka's avatar Sergey Lyubka

Removed mg_set_listening_socket() and mg_get_listening_socket(), added mg_copy_listeners()

parent 2cce91de
......@@ -26,9 +26,9 @@ int main(void) {
server1 = mg_create_server((void *) "1", ev_handler);
server2 = mg_create_server((void *) "2", ev_handler);
// Make both server1 and server2 listen on the same socket
// Make both server1 and server2 listen on the same sockets
mg_set_option(server1, "listening_port", "8080");
//mg_set_listening_socket(server2, mg_get_listening_socket(server1));
mg_copy_listeners(server1, server2);
// server1 goes to separate thread, server 2 runs in main thread.
// IMPORTANT: NEVER LET DIFFERENT THREADS HANDLE THE SAME SERVER.
......
......@@ -4807,9 +4807,8 @@ void mg_destroy_server(struct mg_server **server) {
}
struct mg_connection *mg_next(struct mg_server *s, struct mg_connection *c) {
struct connection *conn = MG_CONN_2_CONN(c);
struct ns_connection *nc = ns_next(&s->ns_mgr,
c == NULL ? NULL : conn->ns_conn);
struct ns_connection *nc = ns_next(&s->ns_mgr, c == NULL ? NULL :
MG_CONN_2_CONN(c)->ns_conn);
if (nc != NULL && nc->user_data != NULL) {
return & ((struct connection *) nc->user_data)->mg_conn;
} else {
......@@ -4923,6 +4922,18 @@ const char **mg_get_valid_option_names(void) {
return static_config_options;
}
void mg_copy_listeners(struct mg_server *s, struct mg_server *to) {
struct ns_connection *c;
for (c = ns_next(&s->ns_mgr, NULL); c != NULL; c = ns_next(&s->ns_mgr, c)) {
struct ns_connection *tmp;
if ((c->flags & NSF_LISTENING) && (tmp = malloc(sizeof(*tmp))) != NULL) {
memcpy(tmp, c, sizeof(*tmp));
tmp->mgr = &to->ns_mgr;
ns_add_conn(tmp->mgr, tmp);
}
}
}
static int get_option_index(const char *name) {
int i;
......@@ -5209,19 +5220,6 @@ void mg_wakeup_server(struct mg_server *server) {
ns_broadcast(&server->ns_mgr, NULL, (void *) "", 0);
}
#if 0
void mg_set_listening_socket(struct mg_server *server, int sock) {
if (server->ns_mgr.listening_sock != INVALID_SOCKET) {
closesocket(server->ns_mgr.listening_sock);
}
server->ns_mgr.listening_sock = (sock_t) sock;
}
int mg_get_listening_socket(struct mg_server *server) {
return server->ns_mgr.listening_sock;
}
#endif
const char *mg_get_option(const struct mg_server *server, const char *name) {
const char **opts = (const char **) server->config_options;
int i = get_option_index(name);
......
......@@ -93,8 +93,7 @@ const char *mg_set_option(struct mg_server *, const char *opt, const char *val);
int mg_poll_server(struct mg_server *, int milliseconds);
const char **mg_get_valid_option_names(void);
const char *mg_get_option(const struct mg_server *server, const char *name);
void mg_set_listening_socket(struct mg_server *, int sock);
int mg_get_listening_socket(struct mg_server *);
void mg_copy_listeners(struct mg_server *from, struct mg_server *to);
struct mg_connection *mg_next(struct mg_server *, struct mg_connection *);
void mg_wakeup_server(struct mg_server *);
void mg_wakeup_server_ex(struct mg_server *, mg_handler_t, const char *, ...);
......
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