1
0
Fork 0
mirror of https://github.com/warmcat/libwebsockets.git synced 2025-03-09 00:00:04 +01:00

custom_event: fake_POLLIN_override

As discussed in

https://github.com/warmcat/libwebsockets/issues/3219
This commit is contained in:
Andy Green 2024-09-30 12:33:39 +01:00
parent 78a6d17aa2
commit 5f3d5e3a3d
7 changed files with 24 additions and 5 deletions

View file

@ -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;

View file

@ -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,

View file

@ -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,

View file

@ -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,

View file

@ -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,

View file

@ -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,

View file

@ -40,12 +40,23 @@ lws_tls_fake_POLLIN_for_buffered(struct lws_context_per_thread *pt)
struct lws *wsi = lws_container_of(p, struct lws,
tls.dll_pending_tls);
if (wsi->position_in_fds_table >= 0) {
/*
* ... allow custom event loop to override our POLLIN-setting
* implementation if it knows how to do it better for its case
*/
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;
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);