Skip to content

Commit

Permalink
custom_event: fake_POLLIN_override
Browse files Browse the repository at this point in the history
As discussed in

#3219
  • Loading branch information
lws-team committed Sep 30, 2024
1 parent 78a6d17 commit a6250ec
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 7 deletions.
3 changes: 3 additions & 0 deletions include/libwebsockets/lws-eventlib-exports.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
1 change: 1 addition & 0 deletions lib/event-libs/glib/glib.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,

Expand Down
1 change: 1 addition & 0 deletions lib/event-libs/libev/libev.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,

Expand Down
1 change: 1 addition & 0 deletions lib/event-libs/libevent/libevent.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,

Expand Down
1 change: 1 addition & 0 deletions lib/event-libs/libuv/libuv.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,

Expand Down
1 change: 1 addition & 0 deletions lib/event-libs/uloop/uloop.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,

Expand Down
27 changes: 20 additions & 7 deletions lib/tls/tls-network.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit a6250ec

Please sign in to comment.