2014-04-03 07:42:50 +08:00
|
|
|
/*
|
|
|
|
* libwebsockets - small server side websockets and web server implementation
|
|
|
|
*
|
2015-12-17 17:03:59 +08:00
|
|
|
* Copyright (C) 2010-2015 Andy Green <andy@warmcat.com>
|
2014-04-03 07:42:50 +08:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation:
|
|
|
|
* version 2.1 of the License.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
|
|
|
* MA 02110-1301 USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "private-libwebsockets.h"
|
|
|
|
|
2016-01-26 20:56:56 +08:00
|
|
|
int
|
|
|
|
_lws_change_pollfd(struct lws *wsi, int _and, int _or, struct lws_pollargs *pa)
|
|
|
|
{
|
|
|
|
struct lws_context_per_thread *pt;
|
2016-01-29 21:18:54 +08:00
|
|
|
struct lws_context *context;
|
2016-01-26 20:56:56 +08:00
|
|
|
int ret = 0, pa_events = 1;
|
|
|
|
struct lws_pollfd *pfd;
|
|
|
|
int sampled_tid, tid;
|
|
|
|
|
|
|
|
if (!wsi || wsi->position_in_fds_table < 0)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
context = wsi->context;
|
|
|
|
pt = &context->pt[(int)wsi->tsi];
|
|
|
|
assert(wsi->position_in_fds_table >= 0 &&
|
|
|
|
wsi->position_in_fds_table < pt->fds_count);
|
|
|
|
|
|
|
|
pfd = &pt->fds[wsi->position_in_fds_table];
|
|
|
|
pa->fd = wsi->sock;
|
|
|
|
pa->prev_events = pfd->events;
|
|
|
|
pa->events = pfd->events = (pfd->events & ~_and) | _or;
|
|
|
|
|
|
|
|
if (context->protocols[0].callback(wsi, LWS_CALLBACK_CHANGE_MODE_POLL_FD,
|
|
|
|
wsi->user_space, (void *)pa, 0)) {
|
|
|
|
ret = -1;
|
|
|
|
goto bail;
|
|
|
|
}
|
|
|
|
|
2016-02-14 09:27:41 +08:00
|
|
|
if (_and & LWS_POLLIN) {
|
|
|
|
lws_libev_io(wsi, LWS_EV_STOP | LWS_EV_READ);
|
|
|
|
lws_libuv_io(wsi, LWS_EV_STOP | LWS_EV_READ);
|
|
|
|
}
|
|
|
|
if (_or & LWS_POLLIN) {
|
|
|
|
lws_libev_io(wsi, LWS_EV_START | LWS_EV_READ);
|
|
|
|
lws_libuv_io(wsi, LWS_EV_START | LWS_EV_READ);
|
|
|
|
}
|
|
|
|
if (_and & LWS_POLLOUT) {
|
|
|
|
lws_libev_io(wsi, LWS_EV_STOP | LWS_EV_WRITE);
|
|
|
|
lws_libuv_io(wsi, LWS_EV_STOP | LWS_EV_WRITE);
|
|
|
|
}
|
|
|
|
if (_or & LWS_POLLOUT) {
|
|
|
|
lws_libev_io(wsi, LWS_EV_START | LWS_EV_WRITE);
|
|
|
|
lws_libuv_io(wsi, LWS_EV_START | LWS_EV_WRITE);
|
|
|
|
}
|
|
|
|
|
2016-01-26 20:56:56 +08:00
|
|
|
/*
|
|
|
|
* if we changed something in this pollfd...
|
|
|
|
* ... and we're running in a different thread context
|
|
|
|
* than the service thread...
|
|
|
|
* ... and the service thread is waiting ...
|
|
|
|
* then cancel it to force a restart with our changed events
|
|
|
|
*/
|
|
|
|
#if LWS_POSIX
|
|
|
|
pa_events = pa->prev_events != pa->events;
|
|
|
|
#endif
|
|
|
|
if (pa_events) {
|
|
|
|
|
|
|
|
if (lws_plat_change_pollfd(context, wsi, pfd)) {
|
|
|
|
lwsl_info("%s failed\n", __func__);
|
|
|
|
ret = -1;
|
|
|
|
goto bail;
|
|
|
|
}
|
|
|
|
|
|
|
|
sampled_tid = context->service_tid;
|
|
|
|
if (sampled_tid) {
|
|
|
|
tid = context->protocols[0].callback(wsi,
|
|
|
|
LWS_CALLBACK_GET_THREAD_ID, NULL, NULL, 0);
|
|
|
|
if (tid == -1) {
|
|
|
|
ret = -1;
|
|
|
|
goto bail;
|
|
|
|
}
|
|
|
|
if (tid != sampled_tid)
|
|
|
|
lws_cancel_service_pt(wsi);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
bail:
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2014-04-03 07:42:50 +08:00
|
|
|
int
|
2015-12-17 17:03:59 +08:00
|
|
|
insert_wsi_socket_into_fds(struct lws_context *context, struct lws *wsi)
|
2014-04-03 07:42:50 +08:00
|
|
|
{
|
2015-12-04 11:08:32 +08:00
|
|
|
struct lws_pollargs pa = { wsi->sock, LWS_POLLIN, 0 };
|
2016-01-19 03:34:24 +08:00
|
|
|
struct lws_context_per_thread *pt = &context->pt[(int)wsi->tsi];
|
2016-01-26 20:56:56 +08:00
|
|
|
int ret = 0;
|
|
|
|
#ifndef LWS_NO_SERVER
|
|
|
|
struct lws_pollargs pa1;
|
|
|
|
#endif
|
|
|
|
|
2016-01-29 21:18:54 +08:00
|
|
|
lwsl_debug("%s: %p: tsi=%d, sock=%d, pos-in-fds=%d\n",
|
2016-01-26 20:56:56 +08:00
|
|
|
__func__, wsi, wsi->tsi, wsi->sock, pt->fds_count);
|
2014-04-03 07:42:50 +08:00
|
|
|
|
2016-01-19 03:34:24 +08:00
|
|
|
if ((unsigned int)pt->fds_count >= context->fd_limit_per_thread) {
|
2014-04-03 07:42:50 +08:00
|
|
|
lwsl_err("Too many fds (%d)\n", context->max_fds);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2015-11-02 13:10:33 +08:00
|
|
|
#if !defined(_WIN32) && !defined(MBED_OPERATORS)
|
2014-04-03 07:42:50 +08:00
|
|
|
if (wsi->sock >= context->max_fds) {
|
|
|
|
lwsl_err("Socket fd %d is too high (%d)\n",
|
2015-12-17 17:03:59 +08:00
|
|
|
wsi->sock, context->max_fds);
|
2014-04-03 07:42:50 +08:00
|
|
|
return 1;
|
|
|
|
}
|
2015-01-30 10:13:01 +08:00
|
|
|
#endif
|
2014-04-03 07:42:50 +08:00
|
|
|
|
|
|
|
assert(wsi);
|
2015-11-14 13:48:58 +08:00
|
|
|
assert(lws_socket_is_valid(wsi->sock));
|
2014-04-03 07:42:50 +08:00
|
|
|
|
2015-12-17 07:54:44 +08:00
|
|
|
if (context->protocols[0].callback(wsi, LWS_CALLBACK_LOCK_POLL,
|
|
|
|
wsi->user_space, (void *) &pa, 1))
|
2015-10-15 07:39:33 +08:00
|
|
|
return -1;
|
2014-04-03 07:42:50 +08:00
|
|
|
|
2016-01-26 20:56:56 +08:00
|
|
|
lws_pt_lock(pt);
|
|
|
|
pt->count_conns++;
|
2015-01-30 10:13:01 +08:00
|
|
|
insert_wsi(context, wsi);
|
2016-01-19 03:34:24 +08:00
|
|
|
wsi->position_in_fds_table = pt->fds_count;
|
|
|
|
pt->fds[pt->fds_count].fd = wsi->sock;
|
|
|
|
pt->fds[pt->fds_count].events = LWS_POLLIN;
|
2016-01-26 20:56:56 +08:00
|
|
|
pa.events = pt->fds[pt->fds_count].events;
|
|
|
|
|
2014-04-03 07:42:50 +08:00
|
|
|
lws_plat_insert_socket_into_fds(context, wsi);
|
|
|
|
|
|
|
|
/* external POLL support via protocol 0 */
|
2015-12-17 07:54:44 +08:00
|
|
|
if (context->protocols[0].callback(wsi, LWS_CALLBACK_ADD_POLL_FD,
|
|
|
|
wsi->user_space, (void *) &pa, 0))
|
2016-01-26 20:56:56 +08:00
|
|
|
ret = -1;
|
|
|
|
#ifndef LWS_NO_SERVER
|
|
|
|
/* if no more room, defeat accepts on this thread */
|
|
|
|
if ((unsigned int)pt->fds_count == context->fd_limit_per_thread - 1)
|
|
|
|
_lws_change_pollfd(pt->wsi_listening, LWS_POLLIN, 0, &pa1);
|
|
|
|
#endif
|
|
|
|
lws_pt_unlock(pt);
|
2014-04-03 07:42:50 +08:00
|
|
|
|
2015-12-17 07:54:44 +08:00
|
|
|
if (context->protocols[0].callback(wsi, LWS_CALLBACK_UNLOCK_POLL,
|
|
|
|
wsi->user_space, (void *)&pa, 1))
|
2016-01-26 20:56:56 +08:00
|
|
|
ret = -1;
|
2014-04-03 07:42:50 +08:00
|
|
|
|
2016-01-26 20:56:56 +08:00
|
|
|
return ret;
|
2014-04-03 07:42:50 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2015-12-15 21:15:58 +08:00
|
|
|
remove_wsi_socket_from_fds(struct lws *wsi)
|
2014-04-03 07:42:50 +08:00
|
|
|
{
|
2015-12-04 11:08:32 +08:00
|
|
|
struct lws_pollargs pa = { wsi->sock, 0, 0 };
|
2016-01-26 20:56:56 +08:00
|
|
|
#ifndef LWS_NO_SERVER
|
|
|
|
struct lws_pollargs pa1;
|
|
|
|
#endif
|
2015-12-15 21:15:58 +08:00
|
|
|
struct lws_context *context = wsi->context;
|
2016-01-19 03:34:24 +08:00
|
|
|
struct lws_context_per_thread *pt = &context->pt[(int)wsi->tsi];
|
2016-01-29 21:18:54 +08:00
|
|
|
struct lws *end_wsi;
|
|
|
|
int m, ret = 0;
|
2014-04-03 07:42:50 +08:00
|
|
|
|
2015-11-02 20:34:12 +08:00
|
|
|
#if !defined(_WIN32) && !defined(MBED_OPERATORS)
|
2014-04-03 07:42:50 +08:00
|
|
|
if (wsi->sock > context->max_fds) {
|
2016-01-26 20:56:56 +08:00
|
|
|
lwsl_err("fd %d too high (%d)\n", wsi->sock, context->max_fds);
|
2014-04-03 07:42:50 +08:00
|
|
|
return 1;
|
|
|
|
}
|
2015-10-13 19:54:57 -05:00
|
|
|
#endif
|
2014-04-03 07:42:50 +08:00
|
|
|
|
2015-12-17 07:54:44 +08:00
|
|
|
if (context->protocols[0].callback(wsi, LWS_CALLBACK_LOCK_POLL,
|
|
|
|
wsi->user_space, (void *)&pa, 1))
|
2015-10-15 07:39:33 +08:00
|
|
|
return -1;
|
2014-04-03 07:42:50 +08:00
|
|
|
|
2016-02-14 09:27:41 +08:00
|
|
|
lws_libev_io(wsi, LWS_EV_STOP | LWS_EV_READ | LWS_EV_WRITE | LWS_EV_PREPARE_DELETION);
|
|
|
|
lws_libuv_io(wsi, LWS_EV_STOP | LWS_EV_READ | LWS_EV_WRITE | LWS_EV_PREPARE_DELETION);
|
2016-01-26 20:56:56 +08:00
|
|
|
|
|
|
|
lws_pt_lock(pt);
|
|
|
|
|
|
|
|
lwsl_info("%s: wsi=%p, sock=%d, fds pos=%d, end guy pos=%d, endfd=%d\n",
|
|
|
|
__func__, wsi, wsi->sock, wsi->position_in_fds_table,
|
|
|
|
pt->fds_count, pt->fds[pt->fds_count].fd);
|
|
|
|
|
|
|
|
/* the guy who is to be deleted's slot index in pt->fds */
|
|
|
|
m = wsi->position_in_fds_table;
|
2014-04-03 07:42:50 +08:00
|
|
|
|
2016-01-26 20:56:56 +08:00
|
|
|
/* have the last guy take up the now vacant slot */
|
|
|
|
pt->fds[m] = pt->fds[pt->fds_count - 1];
|
2014-04-03 07:42:50 +08:00
|
|
|
|
|
|
|
lws_plat_delete_socket_from_fds(context, wsi, m);
|
|
|
|
|
2016-01-26 20:56:56 +08:00
|
|
|
/* end guy's "position in fds table" is now the deletion guy's old one */
|
2016-01-19 03:34:24 +08:00
|
|
|
end_wsi = wsi_from_fd(context, pt->fds[pt->fds_count].fd);
|
2016-01-26 20:56:56 +08:00
|
|
|
assert(end_wsi);
|
2015-12-17 17:03:59 +08:00
|
|
|
end_wsi->position_in_fds_table = m;
|
2016-01-26 20:56:56 +08:00
|
|
|
|
2014-04-03 07:42:50 +08:00
|
|
|
/* deletion guy's lws_lookup entry needs nuking */
|
2015-12-17 17:03:59 +08:00
|
|
|
delete_from_fd(context, wsi->sock);
|
2014-04-03 07:42:50 +08:00
|
|
|
/* removed wsi has no position any more */
|
|
|
|
wsi->position_in_fds_table = -1;
|
|
|
|
|
|
|
|
/* remove also from external POLL support via protocol 0 */
|
2016-01-26 20:56:56 +08:00
|
|
|
if (lws_socket_is_valid(wsi->sock))
|
2015-12-17 17:03:59 +08:00
|
|
|
if (context->protocols[0].callback(wsi, LWS_CALLBACK_DEL_POLL_FD,
|
2016-01-26 20:56:56 +08:00
|
|
|
wsi->user_space, (void *) &pa, 0))
|
|
|
|
ret = -1;
|
|
|
|
#ifndef LWS_NO_SERVER
|
2016-02-14 09:27:41 +08:00
|
|
|
if (!context->being_destroyed)
|
|
|
|
/* if this made some room, accept connects on this thread */
|
|
|
|
if ((unsigned int)pt->fds_count < context->fd_limit_per_thread - 1)
|
|
|
|
_lws_change_pollfd(pt->wsi_listening, 0, LWS_POLLIN, &pa1);
|
2016-01-26 20:56:56 +08:00
|
|
|
#endif
|
|
|
|
lws_pt_unlock(pt);
|
|
|
|
|
2015-12-17 07:54:44 +08:00
|
|
|
if (context->protocols[0].callback(wsi, LWS_CALLBACK_UNLOCK_POLL,
|
|
|
|
wsi->user_space, (void *) &pa, 1))
|
2016-01-26 20:56:56 +08:00
|
|
|
ret = -1;
|
2015-10-15 07:39:33 +08:00
|
|
|
|
2016-01-26 20:56:56 +08:00
|
|
|
return ret;
|
2014-04-03 07:42:50 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2015-12-04 11:08:32 +08:00
|
|
|
lws_change_pollfd(struct lws *wsi, int _and, int _or)
|
2014-04-03 07:42:50 +08:00
|
|
|
{
|
2016-01-19 03:34:24 +08:00
|
|
|
struct lws_context_per_thread *pt;
|
2016-01-29 21:18:54 +08:00
|
|
|
struct lws_context *context;
|
2015-12-04 11:08:32 +08:00
|
|
|
struct lws_pollargs pa;
|
2016-01-29 21:18:54 +08:00
|
|
|
int ret = 0;
|
2014-04-03 07:42:50 +08:00
|
|
|
|
2014-12-15 15:08:13 +08:00
|
|
|
if (!wsi || !wsi->protocol || wsi->position_in_fds_table < 0)
|
|
|
|
return 1;
|
2015-12-14 08:52:03 +08:00
|
|
|
|
2015-12-17 18:25:25 +08:00
|
|
|
context = lws_get_context(wsi);
|
2014-12-15 15:08:13 +08:00
|
|
|
if (!context)
|
|
|
|
return 1;
|
|
|
|
|
2015-12-17 07:54:44 +08:00
|
|
|
if (context->protocols[0].callback(wsi, LWS_CALLBACK_LOCK_POLL,
|
|
|
|
wsi->user_space, (void *) &pa, 0))
|
2015-10-15 07:39:33 +08:00
|
|
|
return -1;
|
2014-04-03 07:42:50 +08:00
|
|
|
|
2016-01-26 20:56:56 +08:00
|
|
|
pt = &context->pt[(int)wsi->tsi];
|
2014-04-03 07:42:50 +08:00
|
|
|
|
2016-01-26 20:56:56 +08:00
|
|
|
lws_pt_lock(pt);
|
|
|
|
ret = _lws_change_pollfd(wsi, _and, _or, &pa);
|
|
|
|
lws_pt_unlock(pt);
|
2015-12-17 07:54:44 +08:00
|
|
|
if (context->protocols[0].callback(wsi, LWS_CALLBACK_UNLOCK_POLL,
|
|
|
|
wsi->user_space, (void *) &pa, 0))
|
2016-01-26 20:56:56 +08:00
|
|
|
ret = -1;
|
2015-12-14 08:52:03 +08:00
|
|
|
|
2016-01-26 20:56:56 +08:00
|
|
|
return ret;
|
2014-04-03 07:42:50 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2015-12-04 08:43:54 +08:00
|
|
|
* lws_callback_on_writable() - Request a callback when this socket
|
2014-04-03 07:42:50 +08:00
|
|
|
* becomes able to be written to without
|
|
|
|
* blocking
|
|
|
|
*
|
|
|
|
* @wsi: Websocket connection instance to get callback for
|
|
|
|
*/
|
|
|
|
|
|
|
|
LWS_VISIBLE int
|
2015-12-16 18:19:08 +08:00
|
|
|
lws_callback_on_writable(struct lws *wsi)
|
2014-04-03 07:42:50 +08:00
|
|
|
{
|
2014-10-22 15:37:28 +08:00
|
|
|
#ifdef LWS_USE_HTTP2
|
2015-12-04 11:08:32 +08:00
|
|
|
struct lws *network_wsi, *wsi2;
|
2014-10-22 15:37:28 +08:00
|
|
|
int already;
|
2016-02-24 21:32:31 +08:00
|
|
|
#endif
|
|
|
|
|
|
|
|
if (wsi->state == LWSS_SHUTDOWN)
|
|
|
|
return 0;
|
2014-10-22 15:37:28 +08:00
|
|
|
|
2016-02-24 21:32:31 +08:00
|
|
|
#ifdef LWS_USE_HTTP2
|
2014-10-22 15:37:28 +08:00
|
|
|
lwsl_info("%s: %p\n", __func__, wsi);
|
2015-12-14 08:52:03 +08:00
|
|
|
|
2015-12-17 17:03:59 +08:00
|
|
|
if (wsi->mode != LWSCM_HTTP2_SERVING)
|
2014-10-22 15:37:28 +08:00
|
|
|
goto network_sock;
|
2015-12-14 08:52:03 +08:00
|
|
|
|
2014-10-22 15:37:28 +08:00
|
|
|
if (wsi->u.http2.requested_POLLOUT) {
|
|
|
|
lwsl_info("already pending writable\n");
|
|
|
|
return 1;
|
|
|
|
}
|
2015-12-14 08:52:03 +08:00
|
|
|
|
2014-10-29 09:39:08 +08:00
|
|
|
if (wsi->u.http2.tx_credit <= 0) {
|
|
|
|
/*
|
|
|
|
* other side is not able to cope with us sending
|
|
|
|
* anything so no matter if we have POLLOUT on our side.
|
2015-12-14 08:52:03 +08:00
|
|
|
*
|
2014-10-29 09:39:08 +08:00
|
|
|
* Delay waiting for our POLLOUT until peer indicates he has
|
|
|
|
* space for more using tx window command in http2 layer
|
|
|
|
*/
|
2015-12-17 07:54:44 +08:00
|
|
|
lwsl_info("%s: %p: waiting_tx_credit (%d)\n", __func__, wsi,
|
|
|
|
wsi->u.http2.tx_credit);
|
2014-10-29 09:39:08 +08:00
|
|
|
wsi->u.http2.waiting_tx_credit = 1;
|
|
|
|
return 0;
|
|
|
|
}
|
2015-12-14 08:52:03 +08:00
|
|
|
|
2014-10-22 15:37:28 +08:00
|
|
|
network_wsi = lws_http2_get_network_wsi(wsi);
|
|
|
|
already = network_wsi->u.http2.requested_POLLOUT;
|
2015-12-14 08:52:03 +08:00
|
|
|
|
2014-10-22 15:37:28 +08:00
|
|
|
/* mark everybody above him as requesting pollout */
|
2015-12-14 08:52:03 +08:00
|
|
|
|
2014-10-22 15:37:28 +08:00
|
|
|
wsi2 = wsi;
|
|
|
|
while (wsi2) {
|
|
|
|
wsi2->u.http2.requested_POLLOUT = 1;
|
|
|
|
lwsl_info("mark %p pending writable\n", wsi2);
|
|
|
|
wsi2 = wsi2->u.http2.parent_wsi;
|
|
|
|
}
|
2015-12-14 08:52:03 +08:00
|
|
|
|
2014-10-22 15:37:28 +08:00
|
|
|
/* for network action, act only on the network wsi */
|
2015-12-14 08:52:03 +08:00
|
|
|
|
2014-10-22 15:37:28 +08:00
|
|
|
wsi = network_wsi;
|
|
|
|
if (already)
|
|
|
|
return 1;
|
|
|
|
network_sock:
|
|
|
|
#endif
|
|
|
|
|
2016-01-19 03:34:24 +08:00
|
|
|
if (lws_ext_cb_active(wsi, LWS_EXT_CB_REQUEST_ON_WRITEABLE, NULL, 0))
|
2014-04-03 07:42:50 +08:00
|
|
|
return 1;
|
|
|
|
|
|
|
|
if (wsi->position_in_fds_table < 0) {
|
|
|
|
lwsl_err("%s: failed to find socket %d\n", __func__, wsi->sock);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (lws_change_pollfd(wsi, 0, LWS_POLLOUT))
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2015-12-04 08:43:54 +08:00
|
|
|
* lws_callback_on_writable_all_protocol() - Request a callback for
|
2014-04-03 07:42:50 +08:00
|
|
|
* all connections using the given protocol when it
|
|
|
|
* becomes possible to write to each socket without
|
|
|
|
* blocking in turn.
|
|
|
|
*
|
2015-12-17 17:03:59 +08:00
|
|
|
* @context: lws_context
|
2014-04-03 07:42:50 +08:00
|
|
|
* @protocol: Protocol whose connections will get callbacks
|
|
|
|
*/
|
|
|
|
|
|
|
|
LWS_VISIBLE int
|
2015-12-11 10:45:35 +08:00
|
|
|
lws_callback_on_writable_all_protocol(const struct lws_context *context,
|
2015-12-17 17:03:59 +08:00
|
|
|
const struct lws_protocols *protocol)
|
2014-04-03 07:42:50 +08:00
|
|
|
{
|
2016-01-19 03:34:24 +08:00
|
|
|
const struct lws_context_per_thread *pt = &context->pt[0];
|
2016-01-26 20:56:56 +08:00
|
|
|
unsigned int n, m = context->count_threads;
|
2016-01-29 21:18:54 +08:00
|
|
|
struct lws *wsi;
|
2016-01-19 03:34:24 +08:00
|
|
|
|
|
|
|
while (m--) {
|
|
|
|
for (n = 0; n < pt->fds_count; n++) {
|
|
|
|
wsi = wsi_from_fd(context, pt->fds[n].fd);
|
|
|
|
if (!wsi)
|
|
|
|
continue;
|
|
|
|
if (wsi->protocol == protocol)
|
|
|
|
lws_callback_on_writable(wsi);
|
|
|
|
}
|
|
|
|
pt++;
|
2014-04-03 07:42:50 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|