Commit 4708cce8 authored by Sergey Lyubka's avatar Sergey Lyubka

mg_poll_server() returns currect time. add mg_set_listening_socket() and mg_get_listening_socket()

parent 3eb9156e
......@@ -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);
......
......@@ -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);
......
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