Skip to content

Commit e820283

Browse files
Zac Helws-team
Zac He
authored andcommitted
service: lock pt while using wsi fdtable pos
1 parent ec76f81 commit e820283

File tree

1 file changed

+10
-11
lines changed

1 file changed

+10
-11
lines changed

lib/core-net/pollfd.c

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,6 @@ _lws_change_pollfd(struct lws *wsi, int _and, int _or, struct lws_pollargs *pa)
6969
context = wsi->a.context;
7070
pt = &context->pt[(int)wsi->tsi];
7171

72-
assert(wsi->position_in_fds_table < (int)pt->fds_count);
73-
7472
#if !defined(LWS_WITH_EVENT_LIBS)
7573
/*
7674
* This only applies when we use the default poll() event loop.
@@ -112,10 +110,11 @@ _lws_change_pollfd(struct lws *wsi, int _and, int _or, struct lws_pollargs *pa)
112110

113111
ftp->_and = _and;
114112
ftp->_or = _or;
115-
ftp->fd_index = wsi->position_in_fds_table;
116113
ftp->next = NULL;
117114

118115
lws_pt_lock(pt, __func__);
116+
assert(wsi->position_in_fds_table < (int)pt->fds_count);
117+
ftp->fd_index = wsi->position_in_fds_table;
119118

120119
/* place at END of list to maintain order */
121120
ftp1 = (struct lws_foreign_thread_pollfd **)
@@ -144,13 +143,16 @@ _lws_change_pollfd(struct lws *wsi, int _and, int _or, struct lws_pollargs *pa)
144143
*/
145144
_or |= LWS_POLLHUP;
146145
#endif
147-
146+
lws_pt_lock(pt, __func__);
147+
assert(wsi->position_in_fds_table < (int)pt->fds_count);
148148
pfd = &pt->fds[wsi->position_in_fds_table];
149-
pa->fd = wsi->desc.sockfd;
150-
lwsl_wsi_debug(wsi, "fd %d events %d -> %d", pa->fd, pfd->events,
151-
(pfd->events & ~_and) | _or);
152149
pa->prev_events = pfd->events;
153150
pa->events = pfd->events = (short)((pfd->events & ~_and) | _or);
151+
lws_pt_unlock(pt);
152+
153+
pa->fd = wsi->desc.sockfd;
154+
lwsl_wsi_debug(wsi, "fd %d events %d -> %d", pa->fd, pa->prev_events,
155+
pa->events);
154156

155157
if (wsi->mux_substream)
156158
return 0;
@@ -621,10 +623,7 @@ lws_callback_on_writable_all_protocol_vhost(const struct lws_vhost *vhost,
621623
lws_dll2_get_head(&vhost->same_vh_protocol_owner[n])) {
622624
wsi = lws_container_of(d, struct lws, same_vh_protocol);
623625

624-
assert(wsi->a.protocol &&
625-
wsi->a.protocol->callback == protocol->callback &&
626-
!strcmp(protocol->name, wsi->a.protocol->name));
627-
626+
assert(wsi->a.protocol == protocol);
628627
lws_callback_on_writable(wsi);
629628

630629
} lws_end_foreach_dll_safe(d, d1);

0 commit comments

Comments
 (0)