Skip to content

Commit 9393dd3

Browse files
dlundquistlws-team
authored andcommitted
ev: remove any watchers on close
1 parent c57733c commit 9393dd3

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

lib/event-libs/libev/libev.c

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ lws_accept_cb(struct ev_loop *loop, struct ev_io *watcher, int revents)
9494
struct lws_context_per_thread *pt;
9595
struct lws_pollfd eventfd;
9696
struct lws *wsi;
97+
int tsi = 0;
9798

9899
if (revents & EV_ERROR)
99100
return;
@@ -112,10 +113,12 @@ lws_accept_cb(struct ev_loop *loop, struct ev_io *watcher, int revents)
112113
}
113114

114115
wsi = wsi_from_fd(context, watcher->fd);
115-
pt = &context->pt[(int)wsi->tsi];
116+
if (wsi)
117+
tsi = (int)wsi->tsi;
118+
pt = &context->pt[tsi];
116119
ptpr = pt_to_priv_ev(pt);
117120

118-
lws_service_fd_tsi(context, &eventfd, (int)wsi->tsi);
121+
lws_service_fd_tsi(context, &eventfd, tsi);
119122

120123
ev_idle_start(ptpr->io_loop, &ptpr->idle);
121124
}
@@ -413,14 +416,22 @@ elops_destroy_wsi_ev(struct lws *wsi)
413416
ev_io_stop(ptpr->io_loop, &w->w_write.watcher);
414417
}
415418

419+
static int
420+
elops_wsi_logical_close_ev(struct lws *wsi)
421+
{
422+
elops_destroy_wsi_ev(wsi);
423+
424+
return 0;
425+
}
426+
416427
static const struct lws_event_loop_ops event_loop_ops_ev = {
417428
/* name */ "libev",
418429
/* init_context */ elops_init_context_ev,
419430
/* destroy_context1 */ NULL,
420431
/* destroy_context2 */ elops_destroy_context2_ev,
421432
/* init_vhost_listen_wsi */ elops_init_vhost_listen_wsi_ev,
422433
/* init_pt */ elops_init_pt_ev,
423-
/* wsi_logical_close */ NULL,
434+
/* wsi_logical_close */ elops_wsi_logical_close_ev,
424435
/* check_client_connect_ok */ NULL,
425436
/* close_handle_manually */ NULL,
426437
/* accept */ elops_accept_ev,

0 commit comments

Comments
 (0)