Skip to content

Commit 5f3d5e3

Browse files
committed
custom_event: fake_POLLIN_override
As discussed in #3219
1 parent 78a6d17 commit 5f3d5e3

File tree

7 files changed

+25
-6
lines changed

7 files changed

+25
-6
lines changed

include/libwebsockets/lws-eventlib-exports.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,9 @@ struct lws_event_loop_ops {
6767
void (*destroy_wsi)(struct lws *wsi);
6868
/* return nonzero if caller thread is not loop service thread */
6969
int (*foreign_thread)(struct lws_context *context, int tsi);
70+
/* optional: custom implementation for faking POLLIN for buffered.
71+
* return nonzero if any wsi faked */
72+
int (*fake_POLLIN_override)(struct lws_context *context, int tsi);
7073

7174
uint8_t flags;
7275

lib/event-libs/glib/glib.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -491,6 +491,7 @@ static const struct lws_event_loop_ops event_loop_ops_glib = {
491491
/* destroy_pt */ elops_destroy_pt_glib,
492492
/* destroy wsi */ elops_destroy_wsi_glib,
493493
/* foreign_thread */ NULL,
494+
/* fake_POLLIN */ NULL,
494495

495496
/* flags */ LELOF_DESTROY_FINAL,
496497

lib/event-libs/libev/libev.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -443,6 +443,7 @@ static const struct lws_event_loop_ops event_loop_ops_ev = {
443443
/* destroy_pt */ elops_destroy_pt_ev,
444444
/* destroy wsi */ elops_destroy_wsi_ev,
445445
/* foreign_thread */ NULL,
446+
/* fake_POLLIN */ NULL,
446447

447448
/* flags */ 0,
448449

lib/event-libs/libevent/libevent.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -495,6 +495,7 @@ static const struct lws_event_loop_ops event_loop_ops_event = {
495495
/* destroy_pt */ elops_destroy_pt_event,
496496
/* destroy wsi */ elops_destroy_wsi_event,
497497
/* foreign_thread */ NULL,
498+
/* fake_POLLIN */ NULL,
498499

499500
/* flags */ 0,
500501

lib/event-libs/libuv/libuv.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -926,6 +926,7 @@ static const struct lws_event_loop_ops event_loop_ops_uv = {
926926
/* destroy_pt */ elops_destroy_pt_uv,
927927
/* destroy wsi */ NULL,
928928
/* foreign_thread */ elops_foreign_thread_uv,
929+
/* fake_POLLIN */ NULL,
929930

930931
/* flags */ 0,
931932

lib/event-libs/uloop/uloop.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,7 @@ static const struct lws_event_loop_ops event_loop_ops_uloop = {
301301
/* destroy_pt */ elops_destroy_pt_uloop,
302302
/* destroy wsi */ elops_destroy_wsi_uloop,
303303
/* foreign_thread */ NULL,
304+
/* fake_POLLIN */ NULL,
304305

305306
/* flags */ 0,
306307

lib/tls/tls-network.c

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,23 @@ lws_tls_fake_POLLIN_for_buffered(struct lws_context_per_thread *pt)
4040
struct lws *wsi = lws_container_of(p, struct lws,
4141
tls.dll_pending_tls);
4242

43-
if (wsi->position_in_fds_table >= 0) {
44-
45-
pt->fds[wsi->position_in_fds_table].revents = (short)
46-
(pt->fds[wsi->position_in_fds_table].revents |
47-
(pt->fds[wsi->position_in_fds_table].events & LWS_POLLIN));
48-
ret |= pt->fds[wsi->position_in_fds_table].revents & LWS_POLLIN;
43+
/*
44+
* ... allow custom event loop to override our POLLIN-setting
45+
* implementation if it knows how to do it better for its case
46+
*/
47+
48+
if (pt->context->event_loop_ops &&
49+
pt->context->event_loop_ops->fake_POLLIN_override)
50+
pt->context->event_loop_ops->fake_POLLIN_override(
51+
pt->context, pt->tid);
52+
else {
53+
if (wsi->position_in_fds_table >= 0) {
54+
55+
pt->fds[wsi->position_in_fds_table].revents = (short)
56+
(pt->fds[wsi->position_in_fds_table].revents |
57+
(pt->fds[wsi->position_in_fds_table].events & LWS_POLLIN));
58+
ret |= pt->fds[wsi->position_in_fds_table].revents & LWS_POLLIN;
59+
}
4960
}
5061

5162
} lws_end_foreach_dll_safe(p, p1);

0 commit comments

Comments
 (0)