From: Andy Green Date: Sun, 28 Feb 2016 17:09:01 +0000 (+0800) Subject: libuv create 1Hz background timeout check X-Git-Tag: upstream/1.7.3~4 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=6671327c8d75ae818961f63c00542798cfbc130c;p=platform%2Fupstream%2Flibwebsockets.git libuv create 1Hz background timeout check Signed-off-by: Andy Green --- diff --git a/lib/context.c b/lib/context.c index 4ed0382..2574f22 100644 --- a/lib/context.c +++ b/lib/context.c @@ -162,6 +162,8 @@ lws_create_context(struct lws_context_creation_info *info) return NULL; } + context->pt[n].context = context; + context->pt[n].tid = n; context->pt[n].http_header_data = lws_malloc(context->max_http_header_data * context->max_http_header_pool); if (!context->pt[n].http_header_data) diff --git a/lib/libuv.c b/lib/libuv.c index a9998df..ac1ab6d 100644 --- a/lib/libuv.c +++ b/lib/libuv.c @@ -74,6 +74,17 @@ lws_uv_sigint_cfg(struct lws_context *context, int use_uv_sigint, return 0; } +static void +lws_uv_timeout_cb(uv_timer_t *timer) +{ + struct lws_context_per_thread *pt = container_of(timer, + struct lws_context_per_thread, uv_timeout_watcher); + + lwsl_info("%s\n", __func__); + /* do timeout check only */ + lws_service_fd_tsi(pt->context, NULL, pt->tid); +} + static const int sigs[] = { SIGINT, SIGTERM, SIGSEGV, SIGFPE }; LWS_VISIBLE int @@ -112,6 +123,9 @@ lws_uv_initloop(struct lws_context *context, uv_loop_t *loop, uv_signal_cb cb, uv_poll_start(&wsi->w_read.uv_watcher, UV_READABLE, lws_accept_cb); } + uv_timer_init(pt->io_loop_uv, &pt->uv_timeout_watcher); + uv_timer_start(&pt->uv_timeout_watcher, lws_uv_timeout_cb, 1000, 1000); + return status; } diff --git a/lib/private-libwebsockets.h b/lib/private-libwebsockets.h index 9c3609a..0368cfd 100644 --- a/lib/private-libwebsockets.h +++ b/lib/private-libwebsockets.h @@ -530,6 +530,7 @@ struct lws_context_per_thread { struct lws *rx_draining_ext_list; struct lws *tx_draining_ext_list; struct lws *timeout_list; + struct lws_context *context; void *http_header_data; struct allocated_headers *ah_pool; struct lws *ah_wait_list; @@ -546,6 +547,7 @@ struct lws_context_per_thread { #if defined(LWS_USE_LIBUV) uv_loop_t *io_loop_uv; uv_signal_t signals[8]; + uv_timer_t uv_timeout_watcher; #endif #if defined(LWS_USE_LIBEV) struct lws_io_watcher w_accept; @@ -571,6 +573,7 @@ struct lws_context_per_thread { unsigned int fds_count; short ah_count_in_use; + unsigned char tid; }; /* diff --git a/test-server/test-server-libuv.c b/test-server/test-server-libuv.c index 4ac7956..5716bdf 100644 --- a/test-server/test-server-libuv.c +++ b/test-server/test-server-libuv.c @@ -122,9 +122,8 @@ void signal_cb(uv_signal_t *watcher, int revents) } static void -uv_timeout_cb(uv_timer_t *w) +uv_timeout_cb_dumb_increment(uv_timer_t *w) { - lwsl_info("%s\n", __func__); lws_callback_on_writable_all_protocol(context, &protocols[PROTOCOL_DUMB_INCREMENT]); } @@ -273,6 +272,7 @@ int main(int argc, char **argv) info.gid = -1; info.uid = -1; info.max_http_header_pool = 1; + info.timeout_secs = 5; info.options = opts | LWS_SERVER_OPTION_LIBUV; context = lws_create_context(&info); @@ -284,7 +284,7 @@ int main(int argc, char **argv) lws_uv_initloop(context, NULL, signal_cb, 0); uv_timer_init(lws_uv_getloop(context, 0), &timeout_watcher); - uv_timer_start(&timeout_watcher, uv_timeout_cb, 50, 50); + uv_timer_start(&timeout_watcher, uv_timeout_cb_dumb_increment, 50, 50); lws_libuv_run(context, 0);