diff --git a/mongoose.c b/mongoose.c index 74f491403f00f8537c8f1c15e1d98d27ef4585b6..f6bb65c656df23b388c9f38a5dc3a78d8a5773c0 100644 --- a/mongoose.c +++ b/mongoose.c @@ -3118,7 +3118,7 @@ void add_to_set(sock_t sock, fd_set *set, sock_t *max_fd) { } } -void mg_poll_server(struct mg_server *server, int milliseconds) { +unsigned int mg_poll_server(struct mg_server *server, int milliseconds) { struct ll *lp, *tmp; struct connection *conn; struct timeval tv; @@ -3127,7 +3127,7 @@ void mg_poll_server(struct mg_server *server, int milliseconds) { time_t current_time = time(NULL), expire_time = current_time - atoi(server->config_options[IDLE_TIMEOUT_MS]) / 1000; - if (server->listening_sock == INVALID_SOCKET) return; + if (server->listening_sock == INVALID_SOCKET) return 0; FD_ZERO(&read_set); FD_ZERO(&write_set); @@ -3193,6 +3193,8 @@ void mg_poll_server(struct mg_server *server, int milliseconds) { close_conn(conn); } } + + return (unsigned int) current_time; } void mg_destroy_server(struct mg_server **server) { @@ -3420,6 +3422,17 @@ const char *mg_set_option(struct mg_server *server, const char *name, return error_msg; } +void mg_set_listening_socket(struct mg_server *server, int sock) { + if (server->listening_sock != INVALID_SOCKET) { + closesocket(server->listening_sock); + } + server->listening_sock = sock; +} + +int mg_get_listening_socket(struct mg_server *server) { + return server->listening_sock; +} + 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); diff --git a/mongoose.h b/mongoose.h index cd2c38b240e6719ec5118b135eb5162c52a0f782..c20f095f4c730da1621177a380f00bbe9e2add23 100644 --- a/mongoose.h +++ b/mongoose.h @@ -62,11 +62,13 @@ typedef int (*mg_handler_t)(struct mg_connection *); struct mg_server *mg_create_server(void *server_param); void mg_destroy_server(struct mg_server **); const char *mg_set_option(struct mg_server *, const char *opt, const char *val); -void mg_poll_server(struct mg_server *, int milliseconds); +unsigned int mg_poll_server(struct mg_server *, int milliseconds); void mg_add_uri_handler(struct mg_server *, const char *uri, mg_handler_t); void mg_set_http_error_handler(struct mg_server *, mg_handler_t); 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 *); int mg_iterate_over_connections(struct mg_server *, void (*func)(struct mg_connection *, void *), void *param);