From 45dead99e057c3db51b92303643d5352d1a4c26a Mon Sep 17 00:00:00 2001 From: Andy Green Date: Fri, 1 Apr 2016 16:57:00 +0800 Subject: [PATCH] libuv report init failure Signed-off-by: Andy Green --- lib/libuv.c | 8 +++++++- test-server/test-server-libuv.c | 7 ++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/lib/libuv.c b/lib/libuv.c index e8da5a5..64090aa 100644 --- a/lib/libuv.c +++ b/lib/libuv.c @@ -138,9 +138,15 @@ lws_uv_initloop(struct lws_context *context, uv_loop_t *loop, int tsi) while (vh) { if (vh->lserv_wsi) { vh->lserv_wsi->w_read.context = context; - uv_poll_init_socket(pt->io_loop_uv, + n = uv_poll_init_socket(pt->io_loop_uv, &vh->lserv_wsi->w_read.uv_watcher, vh->lserv_wsi->sock); + if (n) { + lwsl_err("uv_poll_init failed %d, sockfd=%p\n", + n, (void *)(long)vh->lserv_wsi->sock); + + return -1; + } uv_poll_start(&vh->lserv_wsi->w_read.uv_watcher, UV_READABLE, lws_io_cb); } diff --git a/test-server/test-server-libuv.c b/test-server/test-server-libuv.c index 092c6fd..fb95f7f 100644 --- a/test-server/test-server-libuv.c +++ b/test-server/test-server-libuv.c @@ -292,13 +292,18 @@ int main(int argc, char **argv) lws_uv_sigint_cfg(context, 1, signal_cb); - lws_uv_initloop(context, NULL, 0); + if (lws_uv_initloop(context, NULL, 0)) { + lwsl_err("lws_uv_initloop failed\n"); + + goto bail; + } uv_timer_init(lws_uv_getloop(context, 0), &timeout_watcher); uv_timer_start(&timeout_watcher, uv_timeout_cb_dumb_increment, 50, 50); lws_libuv_run(context, 0); +bail: lws_context_destroy(context); lwsl_notice("libwebsockets-test-server exited cleanly\n"); -- 2.7.4