diff --git a/lib/context.c b/lib/context.c index e4cbe783..20650cb5 100644 --- a/lib/context.c +++ b/lib/context.c @@ -378,9 +378,10 @@ lws_context_destroy(struct lws_context *context) } } #ifdef LWS_USE_LIBEV - ev_io_stop(context->io_loop, &context->w_accept.watcher); - if (context->use_ev_sigint) - ev_signal_stop(context->io_loop, &context->w_sigint.watcher); + uv_poll_stop(&context->w_accept.watcher); + //ev_io_stop(context->io_loop, &context->w_accept.watcher); + //if (context->use_ev_sigint) + //ev_signal_stop(context->io_loop, &context->w_sigint.watcher); #endif /* LWS_USE_LIBEV */ for (n = 0; n < context->count_threads; n++) { diff --git a/lib/libev.c b/lib/libev.c index 167c0457..a7fd1cb8 100644 --- a/lib/libev.c +++ b/lib/libev.c @@ -30,24 +30,24 @@ void lws_feature_status_libev(struct lws_context_creation_info *info) } static void -lws_accept_cb(struct ev_loop *loop, struct ev_io *watcher, int revents) +lws_accept_cb(uv_poll_t *watcher, int status, int revents) { struct lws_io_watcher *lws_io = container_of(watcher, struct lws_io_watcher, watcher); struct lws_context *context = lws_io->context; struct lws_pollfd eventfd; - if (revents & EV_ERROR) - return; + if (status < 0/*revents & EV_ERROR*/) + return; - eventfd.fd = watcher->fd; + eventfd.fd = watcher->io_watcher.fd; eventfd.events = 0; - eventfd.revents = EV_NONE; - if (revents & EV_READ) { + eventfd.revents = 0;//EV_NONE; + if (revents & UV_READABLE) { eventfd.events |= LWS_POLLIN; eventfd.revents |= LWS_POLLIN; } - if (revents & EV_WRITE) { + if (revents & UV_WRITABLE) { eventfd.events |= LWS_POLLOUT; eventfd.revents |= LWS_POLLOUT; } @@ -55,9 +55,9 @@ lws_accept_cb(struct ev_loop *loop, struct ev_io *watcher, int revents) } LWS_VISIBLE void -lws_sigint_cb(struct ev_loop *loop, struct ev_signal *watcher, int revents) +lws_sigint_cb(uv_loop_t *loop, uv_signal_t *watcher, int revents) { - ev_break(loop, EVBREAK_ALL); + //ev_break(loop, EVBREAK_ALL); } LWS_VISIBLE int @@ -74,17 +74,17 @@ lws_sigint_cfg(struct lws_context *context, int use_ev_sigint, } LWS_VISIBLE int -lws_initloop(struct lws_context *context, struct ev_loop *loop) +lws_initloop(struct lws_context *context, uv_loop_t *loop) { - struct ev_signal *w_sigint = &context->w_sigint.watcher; - struct ev_io *w_accept = &context->w_accept.watcher; - const char * backend_name; + //uv_signal_t *w_sigint = &context->w_sigint.watcher; + uv_poll_t *w_accept = &context->w_accept.watcher; + //const char * backend_name; int status = 0; - int backend; - int m = 0; /* !!! TODO add pt support */ + //int backend; + int m = 0; /* !!! TODO add pt support */ if (!loop) - loop = ev_default_loop(0); + loop = uv_default_loop(); context->io_loop = loop; @@ -92,15 +92,17 @@ lws_initloop(struct lws_context *context, struct ev_loop *loop) * Initialize the accept w_accept with the listening socket * and register a callback for read operations */ - ev_io_init(w_accept, lws_accept_cb, context->pt[m].lserv_fd, EV_READ); - ev_io_start(context->io_loop,w_accept); + uv_poll_init(context->io_loop, w_accept, context->pt[m].lserv_fd); + uv_poll_start(w_accept, UV_READABLE, lws_accept_cb); + //ev_io_init(w_accept, lws_accept_cb, context->pt[m].lserv_fd, UV_READABLE); + //ev_io_start(context->io_loop,w_accept); /* Register the signal watcher unless the user says not to */ if (context->use_ev_sigint) { - ev_signal_init(w_sigint, context->lws_ev_sigint_cb, SIGINT); - ev_signal_start(context->io_loop,w_sigint); + //ev_signal_init(w_sigint, context->lws_ev_sigint_cb, SIGINT); + //ev_signal_start(context->io_loop,w_sigint); } - backend = ev_backend(loop); + /*backend = ev_backend(loop); switch (backend) { case EVBACKEND_SELECT: @@ -126,7 +128,7 @@ lws_initloop(struct lws_context *context, struct ev_loop *loop) break; } - lwsl_notice(" libev backend: %s\n", backend_name); + lwsl_notice(" libev backend: %s\n", backend_name);*/ return status; } @@ -135,22 +137,24 @@ LWS_VISIBLE void lws_libev_accept(struct lws *new_wsi, int accept_fd) { struct lws_context *context = lws_get_context(new_wsi); - struct ev_io *r = &new_wsi->w_read.watcher; - struct ev_io *w = &new_wsi->w_write.watcher; + uv_poll_t *r = &new_wsi->w_read.watcher; + //uv_poll_t *w = &new_wsi->w_write.watcher; if (!LWS_LIBEV_ENABLED(context)) return; new_wsi->w_read.context = context; new_wsi->w_write.context = context; - ev_io_init(r, lws_accept_cb, accept_fd, EV_READ); - ev_io_init(w, lws_accept_cb, accept_fd, EV_WRITE); + uv_poll_init(context->io_loop, r, accept_fd); + //ev_io_init(r, lws_accept_cb, accept_fd, UV_READABLE); + //ev_io_init(w, lws_accept_cb, accept_fd, UV_WRITABLE); } LWS_VISIBLE void lws_libev_io(struct lws *wsi, int flags) { struct lws_context *context = lws_get_context(wsi); + int current_events = wsi->w_read.watcher.io_watcher.pevents & (UV_READABLE | UV_WRITABLE); if (!LWS_LIBEV_ENABLED(context)) return; @@ -162,15 +166,26 @@ lws_libev_io(struct lws *wsi, int flags) (flags & (LWS_EV_READ | LWS_EV_WRITE))); if (flags & LWS_EV_START) { - if (flags & LWS_EV_WRITE) - ev_io_start(context->io_loop, &wsi->w_write.watcher); - if (flags & LWS_EV_READ) - ev_io_start(context->io_loop, &wsi->w_read.watcher); + if (flags & LWS_EV_WRITE) + current_events |= UV_WRITABLE; + //ev_io_start(context->io_loop, &wsi->w_write.watcher); + if (flags & LWS_EV_READ) + current_events |= UV_READABLE; + //ev_io_start(context->io_loop, &wsi->w_read.watcher); + + uv_poll_start(&wsi->w_read.watcher, current_events, lws_accept_cb); } else { - if (flags & LWS_EV_WRITE) - ev_io_stop(context->io_loop, &wsi->w_write.watcher); - if (flags & LWS_EV_READ) - ev_io_stop(context->io_loop, &wsi->w_read.watcher); + if (flags & LWS_EV_WRITE) + current_events &= ~UV_WRITABLE; + //ev_io_stop(context->io_loop, &wsi->w_write.watcher); + if (flags & LWS_EV_READ) + current_events &= ~UV_READABLE; + //ev_io_stop(context->io_loop, &wsi->w_read.watcher); + + if (!(current_events & (UV_READABLE | UV_WRITABLE))) + uv_poll_stop(&wsi->w_read.watcher); + else + uv_poll_start(&wsi->w_read.watcher, current_events, lws_accept_cb); } } @@ -190,5 +205,5 @@ LWS_VISIBLE void lws_libev_run(const struct lws_context *context) { if (context->io_loop && LWS_LIBEV_ENABLED(context)) - ev_run(context->io_loop, 0); + uv_run(context->io_loop, 0); } diff --git a/lib/libwebsockets.h b/lib/libwebsockets.h index 47a034bf..81293cda 100644 --- a/lib/libwebsockets.h +++ b/lib/libwebsockets.h @@ -169,7 +169,7 @@ struct sockaddr_in; #endif #ifdef LWS_USE_LIBEV -#include +#include #endif /* LWS_USE_LIBEV */ #ifndef LWS_EXTERN @@ -1456,17 +1456,17 @@ LWS_VISIBLE LWS_EXTERN int LWS_WARN_UNUSED_RESULT lws_http_transaction_completed(struct lws *wsi); #ifdef LWS_USE_LIBEV -typedef void (lws_ev_signal_cb)(EV_P_ struct ev_signal *w, int revents); +typedef void (lws_ev_signal_cb)(uv_loop_t *l, uv_signal_t *w, int revents); LWS_VISIBLE LWS_EXTERN int lws_sigint_cfg(struct lws_context *context, int use_ev_sigint, lws_ev_signal_cb *cb); LWS_VISIBLE LWS_EXTERN int -lws_initloop(struct lws_context *context, struct ev_loop *loop); +lws_initloop(struct lws_context *context, uv_loop_t *loop); LWS_VISIBLE void -lws_sigint_cb(struct ev_loop *loop, struct ev_signal *watcher, int revents); +lws_sigint_cb(uv_loop_t *loop, uv_signal_t *watcher, int revents); #endif /* LWS_USE_LIBEV */ LWS_VISIBLE LWS_EXTERN int diff --git a/lib/private-libwebsockets.h b/lib/private-libwebsockets.h index 72f71b44..d20da12e 100644 --- a/lib/private-libwebsockets.h +++ b/lib/private-libwebsockets.h @@ -117,7 +117,7 @@ #include #include #ifdef LWS_USE_LIBEV -#include +#include #endif /* LWS_USE_LIBEV */ #include @@ -439,12 +439,12 @@ struct lws; #ifdef LWS_USE_LIBEV struct lws_io_watcher { - struct ev_io watcher; + uv_poll_t watcher; struct lws_context* context; }; struct lws_signal_watcher { - struct ev_signal watcher; + uv_signal_t watcher; struct lws_context* context; }; #endif /* LWS_USE_LIBEV */ @@ -560,7 +560,7 @@ struct lws_context { struct lws **lws_lookup; /* fd to wsi */ #endif #ifdef LWS_USE_LIBEV - struct ev_loop* io_loop; + uv_loop_t *io_loop; struct lws_io_watcher w_accept; struct lws_signal_watcher w_sigint; lws_ev_signal_cb* lws_ev_sigint_cb;