Added libwebsocket_sigint_cfg for libev builds to provide
authorAndrew Canaday <andrew.canaday@nytimes.com>
Mon, 27 Apr 2015 02:50:59 +0000 (22:50 -0400)
committerAndy Green <andy.green@linaro.org>
Mon, 12 Oct 2015 03:16:46 +0000 (11:16 +0800)
 runtime configuration of sigint behavior.

lib/libev.c
lib/libwebsockets.h
lib/private-libwebsockets.h

index eff7197..8cda448 100644 (file)
@@ -57,6 +57,21 @@ libwebsocket_sigint_cb(struct ev_loop *loop,
        ev_break(loop, EVBREAK_ALL);
 }
 
+LWS_VISIBLE int libwebsocket_sigint_cfg(
+       struct libwebsocket_context *context,
+       int use_ev_sigint,
+       lws_ev_signal_cb* cb)
+{
+       context->use_ev_sigint = use_ev_sigint;
+       if( cb ) {
+               context->lws_ev_sigint_cb = cb;
+       }
+       else {
+               context->lws_ev_sigint_cb = &libwebsocket_sigint_cb;
+       };
+       return 0;
+};
+
 LWS_VISIBLE int
 libwebsocket_initloop(
        struct libwebsocket_context *context,
@@ -80,8 +95,12 @@ libwebsocket_initloop(
        ev_io_init(w_accept, libwebsocket_accept_cb,
                                        context->listen_service_fd, EV_READ);
        ev_io_start(context->io_loop,w_accept);
-       ev_signal_init(w_sigint, libwebsocket_sigint_cb, SIGINT);
-       ev_signal_start(context->io_loop,w_sigint);
+
+       /* Register the signal watcher unless the user has indicated otherwise: */
+       if( context->use_ev_sigint ) {
+               ev_signal_init(w_sigint, context->lws_ev_sigint_cb, SIGINT);
+               ev_signal_start(context->io_loop,w_sigint);
+       };
        backend = ev_backend(loop);
 
        switch (backend) {
index c621029..608cb49 100644 (file)
@@ -1143,6 +1143,14 @@ lws_add_http_header_status(struct libwebsocket_context *context,
 LWS_EXTERN int lws_http_transaction_completed(struct libwebsocket *wsi);
 
 #ifdef LWS_USE_LIBEV
+typedef void (lws_ev_signal_cb)(EV_P_ struct ev_signal *w, int revents);
+
+LWS_VISIBLE LWS_EXTERN int
+libwebsocket_sigint_cfg(
+       struct libwebsocket_context *context,
+       int use_ev_sigint,
+       lws_ev_signal_cb* cb);
+
 LWS_VISIBLE LWS_EXTERN int
 libwebsocket_initloop(
        struct libwebsocket_context *context, struct ev_loop *loop);
index ec08013..c9c6996 100644 (file)
@@ -438,6 +438,8 @@ struct libwebsocket_context {
        struct ev_loop* io_loop;
        struct lws_io_watcher w_accept;
        struct lws_signal_watcher w_sigint;
+       lws_ev_signal_cb* lws_ev_sigint_cb;
+       int use_ev_sigint;
 #endif /* LWS_USE_LIBEV */
        int max_fds;
        int listen_port;