diff --git a/include/libwebsockets/lws-eventlib-exports.h b/include/libwebsockets/lws-eventlib-exports.h index 5d01caa9d7..9c1ca3ad39 100644 --- a/include/libwebsockets/lws-eventlib-exports.h +++ b/include/libwebsockets/lws-eventlib-exports.h @@ -67,6 +67,9 @@ struct lws_event_loop_ops { void (*destroy_wsi)(struct lws *wsi); /* return nonzero if caller thread is not loop service thread */ int (*foreign_thread)(struct lws_context *context, int tsi); + /* optional: custom implementation for faking POLLIN for buffered. + * return nonzero if any wsi faked */ + int (*fake_POLLIN_override)(struct lws_context *context, int tsi); uint8_t flags; diff --git a/lib/event-libs/glib/glib.c b/lib/event-libs/glib/glib.c index 14c779e150..d0f39860d2 100644 --- a/lib/event-libs/glib/glib.c +++ b/lib/event-libs/glib/glib.c @@ -491,6 +491,7 @@ static const struct lws_event_loop_ops event_loop_ops_glib = { /* destroy_pt */ elops_destroy_pt_glib, /* destroy wsi */ elops_destroy_wsi_glib, /* foreign_thread */ NULL, + /* fake_POLLIN */ NULL, /* flags */ LELOF_DESTROY_FINAL, diff --git a/lib/event-libs/libev/libev.c b/lib/event-libs/libev/libev.c index 6b460d6c40..199e17cf26 100644 --- a/lib/event-libs/libev/libev.c +++ b/lib/event-libs/libev/libev.c @@ -443,6 +443,7 @@ static const struct lws_event_loop_ops event_loop_ops_ev = { /* destroy_pt */ elops_destroy_pt_ev, /* destroy wsi */ elops_destroy_wsi_ev, /* foreign_thread */ NULL, + /* fake_POLLIN */ NULL, /* flags */ 0, diff --git a/lib/event-libs/libevent/libevent.c b/lib/event-libs/libevent/libevent.c index aaee588092..21b6630f19 100644 --- a/lib/event-libs/libevent/libevent.c +++ b/lib/event-libs/libevent/libevent.c @@ -495,6 +495,7 @@ static const struct lws_event_loop_ops event_loop_ops_event = { /* destroy_pt */ elops_destroy_pt_event, /* destroy wsi */ elops_destroy_wsi_event, /* foreign_thread */ NULL, + /* fake_POLLIN */ NULL, /* flags */ 0, diff --git a/lib/event-libs/libuv/libuv.c b/lib/event-libs/libuv/libuv.c index 699aaf386a..23894df112 100644 --- a/lib/event-libs/libuv/libuv.c +++ b/lib/event-libs/libuv/libuv.c @@ -926,6 +926,7 @@ static const struct lws_event_loop_ops event_loop_ops_uv = { /* destroy_pt */ elops_destroy_pt_uv, /* destroy wsi */ NULL, /* foreign_thread */ elops_foreign_thread_uv, + /* fake_POLLIN */ NULL, /* flags */ 0, diff --git a/lib/event-libs/uloop/uloop.c b/lib/event-libs/uloop/uloop.c index a6a14bb9e1..c99265d8e6 100644 --- a/lib/event-libs/uloop/uloop.c +++ b/lib/event-libs/uloop/uloop.c @@ -301,6 +301,7 @@ static const struct lws_event_loop_ops event_loop_ops_uloop = { /* destroy_pt */ elops_destroy_pt_uloop, /* destroy wsi */ elops_destroy_wsi_uloop, /* foreign_thread */ NULL, + /* fake_POLLIN */ NULL, /* flags */ 0, diff --git a/lib/tls/tls-network.c b/lib/tls/tls-network.c index 4a1e14391e..62fca1ce8b 100644 --- a/lib/tls/tls-network.c +++ b/lib/tls/tls-network.c @@ -35,17 +35,30 @@ lws_tls_fake_POLLIN_for_buffered(struct lws_context_per_thread *pt) { int ret = 0; + /* + * ... allow custom event loop to override our implementation if it + * chooses to + */ + + + lws_start_foreach_dll_safe(struct lws_dll2 *, p, p1, lws_dll2_get_head(&pt->tls.dll_pending_tls_owner)) { struct lws *wsi = lws_container_of(p, struct lws, tls.dll_pending_tls); - - if (wsi->position_in_fds_table >= 0) { - - pt->fds[wsi->position_in_fds_table].revents = (short) - (pt->fds[wsi->position_in_fds_table].revents | - (pt->fds[wsi->position_in_fds_table].events & LWS_POLLIN)); - ret |= pt->fds[wsi->position_in_fds_table].revents & LWS_POLLIN; + + if (pt->context->event_loop_ops && + pt->context->event_loop_ops->fake_POLLIN_override) + pt->context->event_loop_ops->fake_POLLIN_override( + pt->context, pt->tid); + else { + if (wsi->position_in_fds_table >= 0) { + + pt->fds[wsi->position_in_fds_table].revents = (short) + (pt->fds[wsi->position_in_fds_table].revents | + (pt->fds[wsi->position_in_fds_table].events & LWS_POLLIN)); + ret |= pt->fds[wsi->position_in_fds_table].revents & LWS_POLLIN; + } } } lws_end_foreach_dll_safe(p, p1);