SJ timer API cleanup; added setInterval and clear*

Timers/intervals are now implemented on top of Mongoose.
Got rid of all the platform-specific code (yay!)

Added interval support and ability to clear previously added timeouts.

PUBLISHED_FROM=93866dd80b95b0fa6e137d87f86138330e720154
This commit is contained in:
Deomid Ryabkov 2016-03-17 08:11:54 +02:00 committed by Marko Mikulicic
parent 3327e0e871
commit 8148b6d037
2 changed files with 22 additions and 20 deletions

View File

@ -3020,6 +3020,24 @@ double mg_set_timer(struct mg_connection *c, double timestamp) {
return result;
}
struct mg_connection *mg_add_sock_opt(struct mg_mgr *s, sock_t sock,
mg_event_handler_t callback,
struct mg_add_sock_opts opts) {
struct mg_connection *nc = mg_create_connection(s, callback, opts);
if (nc != NULL) {
mg_sock_set(nc, sock);
mg_add_conn(nc->mgr, nc);
}
return nc;
}
struct mg_connection *mg_add_sock(struct mg_mgr *s, sock_t sock,
mg_event_handler_t callback) {
struct mg_add_sock_opts opts;
memset(&opts, 0, sizeof(opts));
return mg_add_sock_opt(s, sock, callback, opts);
}
double mg_time() {
return cs_time();
}
@ -3040,7 +3058,6 @@ double mg_time() {
#define MG_UDP_RECV_BUFFER_SIZE 1500
static sock_t mg_open_listening_socket(union socket_address *sa, int proto);
static void mg_sock_set(struct mg_connection *nc, sock_t sock);
#ifdef MG_ENABLE_SSL
static void mg_ssl_begin(struct mg_connection *nc);
static int mg_ssl_err(struct mg_connection *conn, int res);
@ -3500,26 +3517,8 @@ static void mg_mgr_handle_ctl_sock(struct mg_mgr *mgr) {
}
#endif
struct mg_connection *mg_add_sock(struct mg_mgr *s, sock_t sock,
mg_event_handler_t callback) {
struct mg_add_sock_opts opts;
memset(&opts, 0, sizeof(opts));
return mg_add_sock_opt(s, sock, callback, opts);
}
struct mg_connection *mg_add_sock_opt(struct mg_mgr *s, sock_t sock,
mg_event_handler_t callback,
struct mg_add_sock_opts opts) {
struct mg_connection *nc = mg_create_connection(s, callback, opts);
if (nc != NULL) {
mg_sock_set(nc, sock);
mg_add_conn(nc->mgr, nc);
}
return nc;
}
/* Associate a socket to a connection. */
static void mg_sock_set(struct mg_connection *nc, sock_t sock) {
void mg_sock_set(struct mg_connection *nc, sock_t sock) {
mg_set_non_blocking_mode(sock);
mg_set_close_on_exec(sock);
nc->sock = sock;

View File

@ -1575,6 +1575,9 @@ void mg_close_conn(struct mg_connection *nc);
void mg_if_get_conn_addr(struct mg_connection *nc, int remote,
union socket_address *sa);
/* Associate a socket to a connection. */
void mg_sock_set(struct mg_connection *nc, sock_t sock);
#endif /* CS_MONGOOSE_SRC_NET_IF_H_ */
/*
* Copyright (c) 2014 Cesanta Software Limited