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

refactor: isolate event_loop struct content same way as roles

This commit is contained in:
Andy Green 2018-04-29 08:34:19 +08:00
parent 91a47f4fab
commit 8d213f8295
14 changed files with 412 additions and 318 deletions

View file

@ -949,17 +949,17 @@ endif()
if (LWS_WITH_LIBEV)
list(APPEND SOURCES
lib/event-libs/libev.c)
lib/event-libs/libev/libev.c)
endif()
if (LWS_WITH_LIBUV)
list(APPEND SOURCES
lib/event-libs/libuv.c)
lib/event-libs/libuv/libuv.c)
endif()
if (LWS_WITH_LIBEVENT)
list(APPEND SOURCES
lib/event-libs/libevent.c)
lib/event-libs/libevent/libevent.c)
endif()
if (LWS_WITH_LEJP)

View file

@ -1173,34 +1173,22 @@ lws_create_context(const struct lws_context_creation_info *info)
}
#ifdef LWS_WITH_LIBEV
/* (Issue #264) In order to *avoid breaking backwards compatibility*, we
* enable libev mediated SIGINT handling with a default handler of
* lws_sigint_cb. The handler can be overridden or disabled
* by invoking lws_sigint_cfg after creating the context, but
* before invoking lws_initloop:
*/
context->use_ev_sigint = 1;
context->lws_ev_sigint_cb = &lws_ev_sigint_cb;
if (LWS_LIBEV_ENABLED(context)) {
context->use_event_loop_sigint = 1;
context->ev.sigint_cb = &lws_ev_sigint_cb;
}
#endif /* LWS_WITH_LIBEV */
#ifdef LWS_WITH_LIBUV
/* (Issue #264) In order to *avoid breaking backwards compatibility*, we
* enable libev mediated SIGINT handling with a default handler of
* lws_sigint_cb. The handler can be overridden or disabled
* by invoking lws_sigint_cfg after creating the context, but
* before invoking lws_initloop:
*/
context->use_ev_sigint = 1;
context->lws_uv_sigint_cb = &lws_uv_sigint_cb;
if (LWS_LIBUV_ENABLED(context)) {
context->use_event_loop_sigint = 1;
context->uv.sigint_cb = &lws_uv_sigint_cb;
}
#endif
#ifdef LWS_WITH_LIBEVENT
/* (Issue #264) In order to *avoid breaking backwards compatibility*, we
* enable libev mediated SIGINT handling with a default handler of
* lws_sigint_cb. The handler can be overridden or disabled
* by invoking lws_sigint_cfg after creating the context, but
* before invoking lws_initloop:
*/
context->use_ev_sigint = 1;
context->lws_event_sigint_cb = &lws_event_sigint_cb;
if (LWS_LIBEVENT_ENABLED(context)) {
context->use_event_loop_sigint = 1;
context->event.sigint_cb = &lws_event_sigint_cb;
}
#endif /* LWS_WITH_LIBEVENT */
#if defined(LWS_WITH_PEER_LIMITS)
@ -1737,11 +1725,11 @@ lws_context_destroy(struct lws_context *context)
if (LWS_LIBUV_ENABLED(context))
for (n = 0; n < context->count_threads; n++) {
pt = &context->pt[n];
if (!pt->ev_loop_foreign) {
if (!pt->event_loop_foreign) {
#if UV_VERSION_MAJOR > 0
uv_loop_close(pt->io_loop_uv);
uv_loop_close(pt->uv.io_loop);
#endif
lws_free_set_NULL(pt->io_loop_uv);
lws_free_set_NULL(pt->uv.io_loop);
}
}
#endif

View file

@ -35,7 +35,7 @@ static void
lws_accept_cb(struct ev_loop *loop, struct ev_io *watcher, int revents)
{
struct lws_io_watcher *lws_io = lws_container_of(watcher,
struct lws_io_watcher, ev_watcher);
struct lws_io_watcher, ev.watcher);
struct lws_context *context = lws_io->context;
struct lws_pollfd eventfd;
@ -65,14 +65,14 @@ lws_ev_sigint_cb(struct ev_loop *loop, struct ev_signal *watcher, int revents)
}
LWS_VISIBLE int
lws_ev_sigint_cfg(struct lws_context *context, int use_ev_sigint,
lws_ev_sigint_cfg(struct lws_context *context, int use_event_loop_sigint,
lws_ev_signal_cb_t *cb)
{
context->use_ev_sigint = use_ev_sigint;
context->use_event_loop_sigint = use_event_loop_sigint;
if (cb)
context->lws_ev_sigint_cb = cb;
context->ev.sigint_cb = cb;
else
context->lws_ev_sigint_cb = &lws_ev_sigint_cb;
context->ev.sigint_cb = &lws_ev_sigint_cb;
return 0;
}
@ -80,7 +80,7 @@ lws_ev_sigint_cfg(struct lws_context *context, int use_ev_sigint,
LWS_VISIBLE int
lws_ev_initloop(struct lws_context *context, struct ev_loop *loop, int tsi)
{
struct ev_signal *w_sigint = &context->pt[tsi].w_sigint.ev_watcher;
struct ev_signal *w_sigint = &context->pt[tsi].w_sigint.ev.watcher;
struct lws_vhost *vh = context->vhost_list;
const char *backend_name;
int status = 0;
@ -89,9 +89,9 @@ lws_ev_initloop(struct lws_context *context, struct ev_loop *loop, int tsi)
if (!loop)
loop = ev_loop_new(0);
else
context->pt[tsi].ev_loop_foreign = 1;
context->pt[tsi].event_loop_foreign = 1;
context->pt[tsi].io_loop_ev = loop;
context->pt[tsi].ev.io_loop = loop;
if (lws_create_event_pipes(context))
return -1;
@ -105,17 +105,17 @@ lws_ev_initloop(struct lws_context *context, struct ev_loop *loop, int tsi)
vh->lserv_wsi->w_read.context = context;
vh->w_accept.context = context;
ev_io_init(&vh->w_accept.ev_watcher, lws_accept_cb,
ev_io_init(&vh->w_accept.ev.watcher, lws_accept_cb,
vh->lserv_wsi->desc.sockfd, EV_READ);
ev_io_start(loop, &vh->w_accept.ev_watcher);
ev_io_start(loop, &vh->w_accept.ev.watcher);
}
vh = vh->vhost_next;
}
/* Register the signal watcher unless the user says not to */
if (context->use_ev_sigint) {
ev_signal_init(w_sigint, context->lws_ev_sigint_cb, SIGINT);
if (context->use_event_loop_sigint) {
ev_signal_init(w_sigint, context->ev.sigint_cb, SIGINT);
ev_signal_start(loop, w_sigint);
}
@ -159,27 +159,27 @@ lws_libev_destroyloop(struct lws_context *context, int tsi)
if (!lws_check_opt(context->options, LWS_SERVER_OPTION_LIBEV))
return;
if (!pt->io_loop_ev)
if (!pt->ev.io_loop)
return;
while (vh) {
if (vh->lserv_wsi)
ev_io_stop(pt->io_loop_ev, &vh->w_accept.ev_watcher);
ev_io_stop(pt->ev.io_loop, &vh->w_accept.ev.watcher);
vh = vh->vhost_next;
}
if (context->use_ev_sigint)
ev_signal_stop(pt->io_loop_ev,
&pt->w_sigint.ev_watcher);
if (!pt->ev_loop_foreign)
ev_loop_destroy(pt->io_loop_ev);
if (context->use_event_loop_sigint)
ev_signal_stop(pt->ev.io_loop,
&pt->w_sigint.ev.watcher);
if (!pt->event_loop_foreign)
ev_loop_destroy(pt->ev.io_loop);
}
LWS_VISIBLE void
lws_libev_accept(struct lws *new_wsi, lws_sock_file_fd_type desc)
{
struct lws_context *context = lws_get_context(new_wsi);
struct ev_io *r = &new_wsi->w_read.ev_watcher;
struct ev_io *w = &new_wsi->w_write.ev_watcher;
struct ev_io *r = &new_wsi->w_read.ev.watcher;
struct ev_io *w = &new_wsi->w_write.ev.watcher;
int fd;
if (!LWS_LIBEV_ENABLED(context))
@ -205,7 +205,7 @@ lws_libev_io(struct lws *wsi, int flags)
if (!LWS_LIBEV_ENABLED(context))
return;
if (!pt->io_loop_ev)
if (!pt->ev.io_loop)
return;
assert((flags & (LWS_EV_START | LWS_EV_STOP)) &&
@ -213,14 +213,14 @@ lws_libev_io(struct lws *wsi, int flags)
if (flags & LWS_EV_START) {
if (flags & LWS_EV_WRITE)
ev_io_start(pt->io_loop_ev, &wsi->w_write.ev_watcher);
ev_io_start(pt->ev.io_loop, &wsi->w_write.ev.watcher);
if (flags & LWS_EV_READ)
ev_io_start(pt->io_loop_ev, &wsi->w_read.ev_watcher);
ev_io_start(pt->ev.io_loop, &wsi->w_read.ev.watcher);
} else {
if (flags & LWS_EV_WRITE)
ev_io_stop(pt->io_loop_ev, &wsi->w_write.ev_watcher);
ev_io_stop(pt->ev.io_loop, &wsi->w_write.ev.watcher);
if (flags & LWS_EV_READ)
ev_io_stop(pt->io_loop_ev, &wsi->w_read.ev_watcher);
ev_io_stop(pt->ev.io_loop, &wsi->w_read.ev.watcher);
}
}
@ -241,6 +241,6 @@ lws_libev_init_fd_table(struct lws_context *context)
LWS_VISIBLE void
lws_libev_run(const struct lws_context *context, int tsi)
{
if (context->pt[tsi].io_loop_ev && LWS_LIBEV_ENABLED(context))
ev_run(context->pt[tsi].io_loop_ev, 0);
if (context->pt[tsi].ev.io_loop && LWS_LIBEV_ENABLED(context))
ev_run(context->pt[tsi].ev.io_loop, 0);
}

View file

@ -0,0 +1,53 @@
/*
* libwebsockets - small server side websockets and web server implementation
*
* Copyright (C) 2010 - 2018 Andy Green <andy@warmcat.com>
*
* 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
*
* This is included from private-libwebsockets.h if LWS_ROLE_WS
*/
#include <ev.h>
struct lws_pt_eventlibs_libev {
struct ev_loop *io_loop;
};
struct lws_io_watcher_libev {
ev_io watcher;
};
struct lws_signal_watcher_libev {
ev_signal watcher;
};
struct lws_context_eventlibs_libev {
lws_ev_signal_cb_t *sigint_cb;
};
LWS_EXTERN void
lws_libev_accept(struct lws *new_wsi, lws_sock_file_fd_type desc);
LWS_EXTERN void
lws_libev_io(struct lws *wsi, int flags);
LWS_EXTERN int
lws_libev_init_fd_table(struct lws_context *context);
LWS_EXTERN void
lws_libev_destroyloop(struct lws_context *context, int tsi);
LWS_EXTERN void
lws_libev_run(const struct lws_context *context, int tsi);
#define LWS_LIBEV_ENABLED(context) lws_check_opt(context->options, LWS_SERVER_OPTION_LIBEV)
LWS_EXTERN void lws_feature_status_libev(const struct lws_context_creation_info *info);

View file

@ -42,8 +42,8 @@ lws_event_cb(evutil_socket_t sock_fd, short revents, void *ctx)
/* !!! EV_CLOSED doesn't exist in libevent2 */
#if LIBEVENT_VERSION_NUMBER < 0x02000000
if (revents & EV_CLOSED) {
event_del(lws_io->event_watcher);
event_free(lws_io->event_watcher);
event_del(lws_io->event.watcher);
event_free(lws_io->event.watcher);
return;
}
#endif
@ -68,19 +68,19 @@ lws_event_sigint_cb(evutil_socket_t sock_fd, short revents, void *ctx)
{
struct lws_context_per_thread *pt = ctx;
if (!pt->ev_loop_foreign)
event_base_loopbreak(pt->io_loop_event_base);
if (!pt->event_loop_foreign)
event_base_loopbreak(pt->event.io_loop);
}
LWS_VISIBLE int
lws_event_sigint_cfg(struct lws_context *context, int use_event_sigint,
lws_event_signal_cb_t *cb)
{
context->use_ev_sigint = use_event_sigint;
context->use_event_loop_sigint = use_event_sigint;
if (cb)
context->lws_event_sigint_cb = cb;
context->event.sigint_cb = cb;
else
context->lws_event_sigint_cb = &lws_event_sigint_cb;
context->event.sigint_cb = &lws_event_sigint_cb;
return 0;
}
@ -92,10 +92,10 @@ int tsi)
struct lws_vhost *vh = context->vhost_list;
if (!loop)
context->pt[tsi].io_loop_event_base = event_base_new();
context->pt[tsi].event.io_loop = event_base_new();
else {
context->pt[tsi].ev_loop_foreign = 1;
context->pt[tsi].io_loop_event_base = loop;
context->pt[tsi].event_loop_foreign = 1;
context->pt[tsi].event.io_loop = loop;
}
if (lws_create_event_pipes(context))
@ -109,22 +109,22 @@ int tsi)
while (vh) {
if (vh->lserv_wsi) {
vh->lserv_wsi->w_read.context = context;
vh->lserv_wsi->w_read.event_watcher = event_new(
vh->lserv_wsi->w_read.event.watcher = event_new(
loop, vh->lserv_wsi->desc.sockfd,
(EV_READ | EV_PERSIST), lws_event_cb,
&vh->lserv_wsi->w_read);
event_add(vh->lserv_wsi->w_read.event_watcher, NULL);
event_add(vh->lserv_wsi->w_read.event.watcher, NULL);
}
vh = vh->vhost_next;
}
/* Register the signal watcher unless the user says not to */
if (!context->use_ev_sigint)
if (!context->use_event_loop_sigint)
return 0;
context->pt[tsi].w_sigint.event_watcher = evsignal_new(loop, SIGINT,
context->lws_event_sigint_cb, &context->pt[tsi]);
event_add(context->pt[tsi].w_sigint.event_watcher, NULL);
context->pt[tsi].w_sigint.event.watcher = evsignal_new(loop, SIGINT,
context->event.sigint_cb, &context->pt[tsi]);
event_add(context->pt[tsi].w_sigint.event.watcher, NULL);
return 0;
}
@ -138,7 +138,7 @@ lws_libevent_destroyloop(struct lws_context *context, int tsi)
if (!lws_check_opt(context->options, LWS_SERVER_OPTION_LIBEVENT))
return;
if (!pt->io_loop_event_base)
if (!pt->event.io_loop)
return;
/*
@ -146,16 +146,16 @@ lws_libevent_destroyloop(struct lws_context *context, int tsi)
*/
while (vh) {
if (vh->lserv_wsi) {
event_free(vh->lserv_wsi->w_read.event_watcher);
vh->lserv_wsi->w_read.event_watcher = NULL;
event_free(vh->lserv_wsi->w_read.event.watcher);
vh->lserv_wsi->w_read.event.watcher = NULL;
}
vh = vh->vhost_next;
}
if (context->use_ev_sigint)
event_free(pt->w_sigint.event_watcher);
if (!pt->ev_loop_foreign)
event_base_free(pt->io_loop_event_base);
if (context->use_event_loop_sigint)
event_free(pt->w_sigint.event.watcher);
if (!pt->event_loop_foreign)
event_base_free(pt->event.io_loop);
}
LWS_VISIBLE void
@ -174,14 +174,14 @@ lws_libevent_accept(struct lws *new_wsi, lws_sock_file_fd_type desc)
// Initialize the event
pt = &context->pt[(int)new_wsi->tsi];
if (new_wsi->role_ops == role_ops_raw_file)
if (new_wsi->role_ops == &role_ops_raw_file)
fd = desc.filefd;
else
fd = desc.sockfd;
new_wsi->w_read.event_watcher = event_new(pt->io_loop_event_base, fd,
new_wsi->w_read.event.watcher = event_new(pt->event.io_loop, fd,
(EV_READ | EV_PERSIST), lws_event_cb, &new_wsi->w_read);
new_wsi->w_write.event_watcher = event_new(pt->io_loop_event_base, fd,
new_wsi->w_write.event.watcher = event_new(pt->event.io_loop, fd,
(EV_WRITE | EV_PERSIST), lws_event_cb, &new_wsi->w_write);
}
@ -191,11 +191,11 @@ lws_libevent_destroy(struct lws *wsi)
if (!wsi)
return;
if(wsi->w_read.event_watcher)
event_free(wsi->w_read.event_watcher);
if(wsi->w_read.event.watcher)
event_free(wsi->w_read.event.watcher);
if(wsi->w_write.event_watcher)
event_free(wsi->w_write.event_watcher);
if(wsi->w_write.event.watcher)
event_free(wsi->w_write.event.watcher);
}
LWS_VISIBLE void
@ -207,7 +207,7 @@ lws_libevent_io(struct lws *wsi, int flags)
if (!LWS_LIBEVENT_ENABLED(context))
return;
if (!pt->io_loop_event_base || context->being_destroyed)
if (!pt->event.io_loop || context->being_destroyed)
return;
assert((flags & (LWS_EV_START | LWS_EV_STOP)) &&
@ -215,15 +215,15 @@ lws_libevent_io(struct lws *wsi, int flags)
if (flags & LWS_EV_START) {
if (flags & LWS_EV_WRITE)
event_add(wsi->w_write.event_watcher, NULL);
event_add(wsi->w_write.event.watcher, NULL);
if (flags & LWS_EV_READ)
event_add(wsi->w_read.event_watcher, NULL);
event_add(wsi->w_read.event.watcher, NULL);
} else {
if (flags & LWS_EV_WRITE)
event_del(wsi->w_write.event_watcher);
event_del(wsi->w_write.event.watcher);
if (flags & LWS_EV_READ)
event_del(wsi->w_read.event_watcher);
event_del(wsi->w_read.event.watcher);
}
}
@ -245,7 +245,7 @@ LWS_VISIBLE void
lws_libevent_run(const struct lws_context *context, int tsi)
{
/* Run / Dispatch the event_base loop */
if (context->pt[tsi].io_loop_event_base &&
if (context->pt[tsi].event.io_loop &&
LWS_LIBEVENT_ENABLED(context))
event_base_dispatch(context->pt[tsi].io_loop_event_base);
event_base_dispatch(context->pt[tsi].event.io_loop);
}

View file

@ -0,0 +1,60 @@
/*
* libwebsockets - small server side websockets and web server implementation
*
* Copyright (C) 2010 - 2018 Andy Green <andy@warmcat.com>
*
* 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
*
* This is included from private-libwebsockets.h if LWS_ROLE_WS
*/
#include <event2/event.h>
struct lws_pt_eventlibs_libevent {
struct event_base *io_loop;
};
struct lws_io_watcher_libevent {
struct event *watcher;
};
struct lws_signal_watcher_libevent {
struct event *watcher;
};
struct lws_context_eventlibs_libevent {
#if defined(LWS_HIDE_LIBEVENT)
void * sigint_cb;
#else
lws_event_signal_cb_t *sigint_cb;
#endif
};
LWS_EXTERN void
lws_libevent_accept(struct lws *new_wsi, lws_sock_file_fd_type desc);
LWS_VISIBLE void
lws_libevent_destroy(struct lws *wsi);
LWS_EXTERN void
lws_libevent_io(struct lws *wsi, int flags);
LWS_EXTERN int
lws_libevent_init_fd_table(struct lws_context *context);
LWS_EXTERN void
lws_libevent_destroyloop(struct lws_context *context, int tsi);
LWS_EXTERN void
lws_libevent_run(const struct lws_context *context, int tsi);
#define LWS_LIBEVENT_ENABLED(context) lws_check_opt(context->options, LWS_SERVER_OPTION_LIBEVENT)
LWS_EXTERN void lws_feature_status_libevent(const struct lws_context_creation_info *info);

View file

@ -38,13 +38,13 @@ lws_uv_hrtimer_cb(uv_timer_t *timer
)
{
struct lws_context_per_thread *pt = lws_container_of(timer,
struct lws_context_per_thread, uv_hrtimer);
struct lws_context_per_thread, uv.hrtimer);
lws_usec_t us;
lws_pt_lock(pt, __func__);
us = __lws_hrtimer_service(pt);
if (us != LWS_HRTIMER_NOWAIT)
uv_timer_start(&pt->uv_hrtimer, lws_uv_hrtimer_cb, us / 1000, 0);
uv_timer_start(&pt->uv.hrtimer, lws_uv_hrtimer_cb, us / 1000, 0);
lws_pt_unlock(pt);
}
@ -56,7 +56,7 @@ lws_uv_idle(uv_idle_t *handle
)
{
struct lws_context_per_thread *pt = lws_container_of(handle,
struct lws_context_per_thread, uv_idle);
struct lws_context_per_thread, uv.idle);
lws_usec_t us;
lws_service_do_ripe_rxflow(pt);
@ -78,7 +78,7 @@ lws_uv_idle(uv_idle_t *handle
lws_pt_lock(pt, __func__);
us = __lws_hrtimer_service(pt);
if (us != LWS_HRTIMER_NOWAIT)
uv_timer_start(&pt->uv_hrtimer, lws_uv_hrtimer_cb, us / 1000, 0);
uv_timer_start(&pt->uv.hrtimer, lws_uv_hrtimer_cb, us / 1000, 0);
lws_pt_unlock(pt);
/* there is nobody who needs service forcing, shut down idle */
@ -89,7 +89,7 @@ static void
lws_io_cb(uv_poll_t *watcher, int status, int revents)
{
struct lws_io_watcher *lws_io = lws_container_of(watcher,
struct lws_io_watcher, uv_watcher);
struct lws_io_watcher, uv.watcher);
struct lws *wsi = lws_container_of(lws_io, struct lws, w_read);
struct lws_context *context = wsi->context;
struct lws_context_per_thread *pt = &context->pt[(int)wsi->tsi];
@ -131,7 +131,7 @@ lws_io_cb(uv_poll_t *watcher, int status, int revents)
__lws_hrtimer_service(pt);
lws_pt_unlock(pt);
uv_idle_start(&pt->uv_idle, lws_uv_idle);
uv_idle_start(&pt->uv.idle, lws_uv_idle);
}
LWS_VISIBLE void
@ -145,11 +145,11 @@ LWS_VISIBLE int
lws_uv_sigint_cfg(struct lws_context *context, int use_uv_sigint,
uv_signal_cb cb)
{
context->use_ev_sigint = use_uv_sigint;
context->use_event_loop_sigint = use_uv_sigint;
if (cb)
context->lws_uv_sigint_cb = cb;
context->uv.sigint_cb = cb;
else
context->lws_uv_sigint_cb = &lws_uv_sigint_cb;
context->uv.sigint_cb = &lws_uv_sigint_cb;
return 0;
}
@ -162,7 +162,7 @@ lws_uv_timeout_cb(uv_timer_t *timer
)
{
struct lws_context_per_thread *pt = lws_container_of(timer,
struct lws_context_per_thread, uv_timeout_watcher);
struct lws_context_per_thread, uv.timeout_watcher);
if (pt->context->requested_kill)
return;
@ -190,12 +190,12 @@ lws_uv_initvhost(struct lws_vhost* vh, struct lws* wsi)
return 0;
pt = &vh->context->pt[(int)wsi->tsi];
if (!pt->io_loop_uv)
if (!pt->uv.io_loop)
return 0;
wsi->w_read.context = vh->context;
n = uv_poll_init_socket(pt->io_loop_uv,
&wsi->w_read.uv_watcher, wsi->desc.sockfd);
n = uv_poll_init_socket(pt->uv.io_loop,
&wsi->w_read.uv.watcher, wsi->desc.sockfd);
if (n) {
lwsl_err("uv_poll_init failed %d, sockfd=%p\n",
n, (void *)(lws_intptr_t)wsi->desc.sockfd);
@ -221,7 +221,7 @@ lws_uv_initloop(struct lws_context *context, uv_loop_t *loop, int tsi)
struct lws_vhost *vh = context->vhost_list;
int status = 0, n, ns, first = 1;
if (!pt->io_loop_uv) {
if (!pt->uv.io_loop) {
if (!loop) {
loop = lws_malloc(sizeof(*loop), "libuv loop");
if (!loop) {
@ -234,15 +234,15 @@ lws_uv_initloop(struct lws_context *context, uv_loop_t *loop, int tsi)
lwsl_err("This libuv is too old to work...\n");
return 1;
#endif
pt->ev_loop_foreign = 0;
pt->event_loop_foreign = 0;
} else {
lwsl_notice(" Using foreign event loop...\n");
pt->ev_loop_foreign = 1;
pt->event_loop_foreign = 1;
}
pt->io_loop_uv = loop;
uv_idle_init(loop, &pt->uv_idle);
LWS_UV_REFCOUNT_STATIC_HANDLE_NEW(&pt->uv_idle, context);
pt->uv.io_loop = loop;
uv_idle_init(loop, &pt->uv.idle);
LWS_UV_REFCOUNT_STATIC_HANDLE_NEW(&pt->uv.idle, context);
ns = ARRAY_SIZE(sigs);
@ -250,16 +250,15 @@ lws_uv_initloop(struct lws_context *context, uv_loop_t *loop, int tsi)
LWS_SERVER_OPTION_UV_NO_SIGSEGV_SIGFPE_SPIN))
ns = 2;
if (pt->context->use_ev_sigint) {
assert(ns <= (int)ARRAY_SIZE(pt->signals));
if (pt->context->use_event_loop_sigint) {
assert(ns <= (int)ARRAY_SIZE(pt->uv.signals));
for (n = 0; n < ns; n++) {
uv_signal_init(loop, &pt->signals[n]);
LWS_UV_REFCOUNT_STATIC_HANDLE_NEW(&pt->signals[n],
uv_signal_init(loop, &pt->uv.signals[n]);
LWS_UV_REFCOUNT_STATIC_HANDLE_NEW(&pt->uv.signals[n],
context);
pt->signals[n].data = pt->context;
uv_signal_start(&pt->signals[n],
context->lws_uv_sigint_cb,
sigs[n]);
pt->uv.signals[n].data = pt->context;
uv_signal_start(&pt->uv.signals[n],
context->uv.sigint_cb, sigs[n]);
}
}
} else
@ -284,11 +283,11 @@ lws_uv_initloop(struct lws_context *context, uv_loop_t *loop, int tsi)
if (!first)
return status;
uv_timer_init(pt->io_loop_uv, &pt->uv_timeout_watcher);
LWS_UV_REFCOUNT_STATIC_HANDLE_NEW(&pt->uv_timeout_watcher, context);
uv_timer_start(&pt->uv_timeout_watcher, lws_uv_timeout_cb, 10, 1000);
uv_timer_init(pt->io_loop_uv, &pt->uv_hrtimer);
LWS_UV_REFCOUNT_STATIC_HANDLE_NEW(&pt->uv_hrtimer, context);
uv_timer_init(pt->uv.io_loop, &pt->uv.timeout_watcher);
LWS_UV_REFCOUNT_STATIC_HANDLE_NEW(&pt->uv.timeout_watcher, context);
uv_timer_start(&pt->uv.timeout_watcher, lws_uv_timeout_cb, 10, 1000);
uv_timer_init(pt->uv.io_loop, &pt->uv.hrtimer);
LWS_UV_REFCOUNT_STATIC_HANDLE_NEW(&pt->uv.hrtimer, context);
return status;
@ -308,7 +307,7 @@ lws_uv_close_cb_sa(uv_handle_t *handle)
int n;
lwsl_info("%s: sa left %d: dyn left: %d\n", __func__,
context->uv_count_static_asset_handles,
context->count_event_loop_static_asset_handles,
context->count_wsi_allocated);
/* any static assets left? */
@ -327,10 +326,10 @@ lws_uv_close_cb_sa(uv_handle_t *handle)
for (n = 0; n < context->count_threads; n++) {
struct lws_context_per_thread *pt = &context->pt[n];
if (!pt->io_loop_uv || !LWS_LIBUV_ENABLED(context))
if (!pt->uv.io_loop || !LWS_LIBUV_ENABLED(context))
continue;
uv_stop(pt->io_loop_uv);
uv_stop(pt->uv.io_loop);
/*
* we can't delete non-foreign loop here, because
@ -390,7 +389,7 @@ lws_libuv_destroyloop(struct lws_context *context, int tsi)
if (!lws_check_opt(context->options, LWS_SERVER_OPTION_LIBUV))
return;
if (!pt->io_loop_uv)
if (!pt->uv.io_loop)
return;
if (pt->event_loop_destroy_processing_done)
@ -398,8 +397,8 @@ lws_libuv_destroyloop(struct lws_context *context, int tsi)
pt->event_loop_destroy_processing_done = 1;
if (context->use_ev_sigint) {
uv_signal_stop(&pt->w_sigint.uv_watcher);
if (context->use_event_loop_sigint) {
uv_signal_stop(&pt->w_sigint.uv.watcher);
ns = ARRAY_SIZE(sigs);
if (lws_check_opt(context->options,
@ -407,18 +406,19 @@ lws_libuv_destroyloop(struct lws_context *context, int tsi)
ns = 2;
for (m = 0; m < ns; m++) {
uv_signal_stop(&pt->signals[m]);
uv_close((uv_handle_t *)&pt->signals[m], lws_uv_close_cb_sa);
uv_signal_stop(&pt->uv.signals[m]);
uv_close((uv_handle_t *)&pt->uv.signals[m],
lws_uv_close_cb_sa);
}
}
uv_timer_stop(&pt->uv_timeout_watcher);
uv_close((uv_handle_t *)&pt->uv_timeout_watcher, lws_uv_close_cb_sa);
uv_timer_stop(&pt->uv_hrtimer);
uv_close((uv_handle_t *)&pt->uv_hrtimer, lws_uv_close_cb_sa);
uv_timer_stop(&pt->uv.timeout_watcher);
uv_close((uv_handle_t *)&pt->uv.timeout_watcher, lws_uv_close_cb_sa);
uv_timer_stop(&pt->uv.hrtimer);
uv_close((uv_handle_t *)&pt->uv.hrtimer, lws_uv_close_cb_sa);
uv_idle_stop(&pt->uv_idle);
uv_close((uv_handle_t *)&pt->uv_idle, lws_uv_close_cb_sa);
uv_idle_stop(&pt->uv.idle);
uv_close((uv_handle_t *)&pt->uv.idle, lws_uv_close_cb_sa);
}
void
@ -432,10 +432,10 @@ lws_libuv_accept(struct lws *wsi, lws_sock_file_fd_type desc)
wsi->w_read.context = context;
if (wsi->role_ops == &role_ops_raw_file || wsi->event_pipe)
uv_poll_init(pt->io_loop_uv, &wsi->w_read.uv_watcher,
uv_poll_init(pt->uv.io_loop, &wsi->w_read.uv.watcher,
(int)(long long)desc.filefd);
else
uv_poll_init_socket(pt->io_loop_uv, &wsi->w_read.uv_watcher,
uv_poll_init_socket(pt->uv.io_loop, &wsi->w_read.uv.watcher,
desc.sockfd);
}
@ -445,19 +445,14 @@ lws_libuv_io(struct lws *wsi, int flags)
struct lws_context *context = lws_get_context(wsi);
struct lws_context_per_thread *pt = &wsi->context->pt[(int)wsi->tsi];
struct lws_io_watcher *w = &wsi->w_read;
//#if defined(WIN32) || defined(_WIN32)
// int current_events = w->uv_watcher.events &
// (UV_READABLE | UV_WRITABLE);
//#else
int current_events = w->actual_events & (UV_READABLE | UV_WRITABLE);
//#endif
if (!LWS_LIBUV_ENABLED(context))
return;
// w->context is set after the loop is initialized
/* w->context is set after the loop is initialized */
if (!pt->io_loop_uv || !w->context) {
if (!pt->uv.io_loop || !w->context) {
lwsl_info("%s: no io loop yet\n", __func__);
return;
}
@ -475,7 +470,7 @@ lws_libuv_io(struct lws *wsi, int flags)
if (flags & LWS_EV_READ)
current_events |= UV_READABLE;
uv_poll_start(&w->uv_watcher, current_events, lws_io_cb);
uv_poll_start(&w->uv.watcher, current_events, lws_io_cb);
} else {
if (flags & LWS_EV_WRITE)
current_events &= ~UV_WRITABLE;
@ -484,9 +479,9 @@ lws_libuv_io(struct lws *wsi, int flags)
current_events &= ~UV_READABLE;
if (!(current_events & (UV_READABLE | UV_WRITABLE)))
uv_poll_stop(&w->uv_watcher);
uv_poll_stop(&w->uv.watcher);
else
uv_poll_start(&w->uv_watcher, current_events,
uv_poll_start(&w->uv.watcher, current_events,
lws_io_cb);
}
@ -510,15 +505,15 @@ lws_libuv_init_fd_table(struct lws_context *context)
LWS_VISIBLE void
lws_libuv_run(const struct lws_context *context, int tsi)
{
if (context->pt[tsi].io_loop_uv && LWS_LIBUV_ENABLED(context))
uv_run(context->pt[tsi].io_loop_uv, 0);
if (context->pt[tsi].uv.io_loop && LWS_LIBUV_ENABLED(context))
uv_run(context->pt[tsi].uv.io_loop, 0);
}
LWS_VISIBLE void
lws_libuv_stop_without_kill(const struct lws_context *context, int tsi)
{
if (context->pt[tsi].io_loop_uv && LWS_LIBUV_ENABLED(context))
uv_stop(context->pt[tsi].io_loop_uv);
if (context->pt[tsi].uv.io_loop && LWS_LIBUV_ENABLED(context))
uv_stop(context->pt[tsi].uv.io_loop);
}
@ -526,8 +521,8 @@ lws_libuv_stop_without_kill(const struct lws_context *context, int tsi)
LWS_VISIBLE uv_loop_t *
lws_uv_getloop(struct lws_context *context, int tsi)
{
if (context->pt[tsi].io_loop_uv && LWS_LIBUV_ENABLED(context))
return context->pt[tsi].io_loop_uv;
if (context->pt[tsi].uv.io_loop && LWS_LIBUV_ENABLED(context))
return context->pt[tsi].uv.io_loop;
return NULL;
}
@ -536,7 +531,7 @@ static void
lws_libuv_closewsi(uv_handle_t* handle)
{
struct lws *n = NULL, *wsi = (struct lws *)(((char *)handle) -
(char *)(&n->w_read.uv_watcher));
(char *)(&n->w_read.uv.watcher));
struct lws_context *context = lws_get_context(wsi);
struct lws_context_per_thread *pt = &context->pt[(int)wsi->tsi];
int lspd = 0, m;
@ -562,7 +557,7 @@ lws_libuv_closewsi(uv_handle_t* handle)
}
lwsl_info("%s: sa left %d: dyn left: %d\n", __func__,
context->uv_count_static_asset_handles,
context->count_event_loop_static_asset_handles,
context->count_wsi_allocated);
/*
@ -646,7 +641,7 @@ lws_libuv_closehandle(struct lws *wsi)
wsi->told_event_loop_closed = 1;
/* required to defer actual deletion until libuv has processed it */
uv_close((uv_handle_t*)&wsi->w_read.uv_watcher, lws_libuv_closewsi);
uv_close((uv_handle_t*)&wsi->w_read.uv.watcher, lws_libuv_closewsi);
}
static void
@ -660,17 +655,17 @@ lws_libuv_closewsi_m(uv_handle_t* handle)
void
lws_libuv_closehandle_manually(struct lws *wsi)
{
uv_handle_t *h = (void *)&wsi->w_read.uv_watcher;
uv_handle_t *h = (void *)&wsi->w_read.uv.watcher;
h->data = (void *)(lws_intptr_t)wsi->desc.sockfd;
/* required to defer actual deletion until libuv has processed it */
uv_close((uv_handle_t*)&wsi->w_read.uv_watcher, lws_libuv_closewsi_m);
uv_close((uv_handle_t*)&wsi->w_read.uv.watcher, lws_libuv_closewsi_m);
}
int
lws_libuv_check_watcher_active(struct lws *wsi)
{
uv_handle_t *h = (void *)&wsi->w_read.uv_watcher;
uv_handle_t *h = (void *)&wsi->w_read.uv.watcher;
return uv_is_active(h);
}
@ -699,14 +694,14 @@ lws_plat_plugins_init(struct lws_context *context, const char * const *d)
lib.errmsg = NULL;
lib.handle = NULL;
uv_loop_init(&context->pu_loop);
uv_loop_init(&context->uv.pu_loop);
lwsl_notice(" Plugins:\n");
while (d && *d) {
lwsl_notice(" Scanning %s\n", *d);
m =uv_fs_scandir(&context->pu_loop, &req, *d, 0, NULL);
m =uv_fs_scandir(&context->uv.pu_loop, &req, *d, 0, NULL);
if (m < 1) {
lwsl_err("Scandir on %s failed\n", *d);
return 1;
@ -830,7 +825,7 @@ lws_plat_plugins_destroy(struct lws_context *context)
context->plugin_list = NULL;
while (uv_loop_close(&context->pu_loop))
while (uv_loop_close(&context->uv.pu_loop))
;
return 0;

View file

@ -0,0 +1,77 @@
/*
* libwebsockets - small server side websockets and web server implementation
*
* Copyright (C) 2010 - 2018 Andy Green <andy@warmcat.com>
*
* 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
*
* This is included from private-libwebsockets.h if LWS_ROLE_WS
*/
#include <uv.h>
/*
* All "static" (per-pt or per-context) uv handles must
*
* - have their .data set to point to the context
*
* - contribute to context->uv_count_static_asset_handles
* counting
*/
#define LWS_UV_REFCOUNT_STATIC_HANDLE_NEW(_x, _ctx) \
{ uv_handle_t *_uht = (uv_handle_t *)(_x); _uht->data = _ctx; \
_ctx->count_event_loop_static_asset_handles++; }
#define LWS_UV_REFCOUNT_STATIC_HANDLE_TO_CONTEXT(_x) \
((struct lws_context *)((uv_handle_t *)((_x)->data)))
#define LWS_UV_REFCOUNT_STATIC_HANDLE_DESTROYED(_x) \
(--(LWS_UV_REFCOUNT_STATIC_HANDLE_TO_CONTEXT(_x)-> \
count_event_loop_static_asset_handles))
struct lws_pt_eventlibs_libuv {
uv_loop_t *io_loop;
uv_signal_t signals[8];
uv_timer_t timeout_watcher;
uv_timer_t hrtimer;
uv_idle_t idle;
};
struct lws_context_eventlibs_libuv {
uv_signal_cb sigint_cb;
uv_loop_t pu_loop;
};
struct lws_io_watcher_libuv {
uv_poll_t watcher;
};
struct lws_signal_watcher_libuv {
uv_signal_t watcher;
};
LWS_EXTERN void
lws_libuv_accept(struct lws *new_wsi, lws_sock_file_fd_type desc);
LWS_EXTERN void
lws_libuv_io(struct lws *wsi, int flags);
LWS_EXTERN int
lws_libuv_init_fd_table(struct lws_context *context);
LWS_EXTERN void
lws_libuv_run(const struct lws_context *context, int tsi);
LWS_EXTERN void
lws_libuv_destroyloop(struct lws_context *context, int tsi);
LWS_EXTERN int
lws_uv_initvhost(struct lws_vhost* vh, struct lws*);
#define LWS_LIBUV_ENABLED(context) lws_check_opt(context->options, LWS_SERVER_OPTION_LIBUV)
LWS_EXTERN void lws_feature_status_libuv(const struct lws_context_creation_info *info);

View file

@ -865,7 +865,7 @@ async_close:
if (LWS_LIBUV_ENABLED(context)) {
if (wsi->listener) {
lwsl_debug("%s: stop listener poll\n", __func__);
uv_poll_stop(&wsi->w_read.uv_watcher);
uv_poll_stop(&wsi->w_read.uv.watcher);
}
lwsl_debug("%s: lws_libuv_closehandle: wsi %p\n",
__func__, wsi);

View file

@ -4603,7 +4603,7 @@ lws_plat_recommended_rsa_bits(void);
typedef void (lws_ev_signal_cb_t)(EV_P_ struct ev_signal *w, int revents);
LWS_VISIBLE LWS_EXTERN int
lws_ev_sigint_cfg(struct lws_context *context, int use_ev_sigint,
lws_ev_sigint_cfg(struct lws_context *context, int use_event_loop_sigint,
lws_ev_signal_cb_t *cb);
LWS_VISIBLE LWS_EXTERN int

View file

@ -165,16 +165,6 @@
#include <arpa/inet.h>
#include <poll.h>
#endif
#if defined(LWS_WITH_LIBEV)
#include <ev.h>
#endif
#ifdef LWS_WITH_LIBUV
#include <uv.h>
#endif
#if defined(LWS_WITH_LIBEVENT) && !defined(LWS_HIDE_LIBEVENT)
#include <event2/event.h>
#endif
#ifndef LWS_NO_FORK
#ifdef LWS_HAVE_SYS_PRCTL_H
#include <sys/prctl.h>
@ -209,6 +199,16 @@
#include "libwebsockets.h"
#if defined(LWS_WITH_LIBEV)
#include "event-libs/libev/private.h"
#endif
#ifdef LWS_WITH_LIBUV
#include "event-libs/libuv/private.h"
#endif
#if defined(LWS_WITH_LIBEVENT) && !defined(LWS_HIDE_LIBEVENT)
#include "event-libs/libevent/private.h"
#endif
#if defined(LWS_WITH_TLS)
#include "tls/private.h"
#endif
@ -722,13 +722,13 @@ struct lws;
struct lws_io_watcher {
#ifdef LWS_WITH_LIBEV
ev_io ev_watcher;
struct lws_io_watcher_libev ev;
#endif
#ifdef LWS_WITH_LIBUV
uv_poll_t uv_watcher;
struct lws_io_watcher_libuv uv;
#endif
#ifdef LWS_WITH_LIBEVENT
struct event *event_watcher;
struct lws_io_watcher_libevent event;
#endif
struct lws_context *context;
@ -737,13 +737,13 @@ struct lws_io_watcher {
struct lws_signal_watcher {
#ifdef LWS_WITH_LIBEV
ev_signal ev_watcher;
struct lws_signal_watcher_libev ev;
#endif
#ifdef LWS_WITH_LIBUV
uv_signal_t uv_watcher;
struct lws_signal_watcher_libuv uv;
#endif
#ifdef LWS_WITH_LIBEVENT
struct event *event_watcher;
struct lws_signal_watcher_libevent event;
#endif
struct lws_context *context;
};
@ -776,9 +776,36 @@ struct lws_context_per_thread {
#if LWS_MAX_SMP > 1
pthread_mutex_t lock;
pthread_mutex_t lock_stats;
pthread_t lock_owner;
const char *last_lock_reason;
#endif
struct lws_context *context;
/*
* usable by anything in the service code, but only if the scope
* does not last longer than the service action (since next service
* of any socket can likewise use it and overwrite)
*/
unsigned char *serv_buf;
struct lws_dll_lws dll_head_timeout;
struct lws_dll_lws dll_head_hrtimer;
struct lws_dll_lws dll_head_buflist; /* guys with pending rxflow */
#if defined(LWS_WITH_TLS)
struct lws *pending_read_list; /* linked list */
#endif
struct lws_pollfd *fds;
volatile struct lws_foreign_thread_pollfd * volatile foreign_pfd_list;
#ifdef _WIN32
WSAEVENT *events;
#endif
lws_sockfd_type dummy_pipe_fds[2];
struct lws *pipe_wsi;
/* --- role based members --- */
#if defined(LWS_ROLE_WS) && !defined(LWS_WITHOUT_EXTENSIONS)
struct lws_pt_role_ws ws;
@ -787,63 +814,35 @@ struct lws_context_per_thread {
struct lws_pt_role_http http;
#endif
struct lws_dll_lws dll_head_timeout;
struct lws_dll_lws dll_head_hrtimer;
struct lws_dll_lws dll_head_buflist; /* guys with pending rxflow */
#if defined(LWS_WITH_LIBUV) || defined(LWS_WITH_LIBEVENT)
struct lws_context *context;
#endif
/* --- event library based members --- */
#if defined(LWS_HAVE_PTHREAD_H)
const char *last_lock_reason;
#endif
#if defined(LWS_WITH_TLS)
struct lws *pending_read_list; /* linked list */
#endif
#if defined(LWS_WITH_LIBEV)
struct ev_loop *io_loop_ev;
struct lws_pt_eventlibs_libev ev;
#endif
#if defined(LWS_WITH_LIBUV)
uv_loop_t *io_loop_uv;
uv_signal_t signals[8];
uv_timer_t uv_timeout_watcher;
uv_timer_t uv_hrtimer;
uv_idle_t uv_idle;
struct lws_pt_eventlibs_libuv uv;
#endif
#if defined(LWS_WITH_LIBEVENT)
struct event_base *io_loop_event_base;
#endif
#if defined(LWS_WITH_LIBEV) || defined(LWS_WITH_LIBUV) || defined(LWS_WITH_LIBEVENT)
struct lws_signal_watcher w_sigint;
unsigned char ev_loop_foreign:1;
unsigned char event_loop_destroy_processing_done:1;
struct lws_pt_eventlibs_libevent event;
#endif
unsigned long count_conns;
/*
* usable by anything in the service code, but only if the scope
* does not last longer than the service action (since next service
* of any socket can likewise use it and overwrite)
*/
unsigned char *serv_buf;
#ifdef _WIN32
WSAEVENT *events;
#if defined(LWS_WITH_LIBEV) || defined(LWS_WITH_LIBUV) || defined(LWS_WITH_LIBEVENT)
struct lws_signal_watcher w_sigint;
#endif
lws_sockfd_type dummy_pipe_fds[2];
struct lws *pipe_wsi;
/* --- */
unsigned long count_conns;
unsigned int fds_count;
volatile unsigned char inside_poll;
volatile unsigned char foreign_spinlock;
unsigned int fds_count;
unsigned char tid;
unsigned char lock_depth;
#if LWS_MAX_SMP > 1
pthread_t lock_owner;
#endif
unsigned char event_loop_foreign:1;
unsigned char event_loop_destroy_processing_done:1;
};
struct lws_conn_stats {
@ -1016,25 +1015,6 @@ struct lws_peer {
};
#endif
#if defined(LWS_WITH_LIBUV)
/*
* All "static" (per-pt or per-context) uv handles must
*
* - have their .data set to point to the context
*
* - contribute to context->uv_count_static_asset_handles
* counting
*/
#define LWS_UV_REFCOUNT_STATIC_HANDLE_NEW(_x, _ctx) \
{ uv_handle_t *_uht = (uv_handle_t *)(_x); _uht->data = _ctx; \
_ctx->uv_count_static_asset_handles++; }
#define LWS_UV_REFCOUNT_STATIC_HANDLE_TO_CONTEXT(_x) \
((struct lws_context *)((uv_handle_t *)((_x)->data)))
#define LWS_UV_REFCOUNT_STATIC_HANDLE_DESTROYED(_x) \
(--(LWS_UV_REFCOUNT_STATIC_HANDLE_TO_CONTEXT(_x)-> \
uv_count_static_asset_handles))
#endif
/*
* the rest is managed per-context, that includes
*
@ -1094,19 +1074,13 @@ struct lws_context {
#endif
#if defined(LWS_WITH_LIBEV)
lws_ev_signal_cb_t * lws_ev_sigint_cb;
struct lws_context_eventlibs_libev ev;
#endif
#if defined(LWS_WITH_LIBUV)
uv_signal_cb lws_uv_sigint_cb;
uv_loop_t pu_loop;
int uv_count_static_asset_handles;
struct lws_context_eventlibs_libuv uv;
#endif
#if defined(LWS_WITH_LIBEVENT)
#if defined(LWS_HIDE_LIBEVENT)
void * lws_event_sigint_cb;
#else
lws_event_signal_cb_t * lws_event_sigint_cb;
#endif
struct lws_context_eventlibs_libevent event;
#endif
char canonical_hostname[128];
#ifdef LWS_LATENCY
@ -1126,7 +1100,8 @@ struct lws_context {
int max_fds;
#if defined(LWS_WITH_LIBEV) || defined(LWS_WITH_LIBUV) || defined(LWS_WITH_LIBEVENT)
int use_ev_sigint;
int use_event_loop_sigint;
int count_event_loop_static_asset_handles;
#endif
int started_with_parent;
int uid, gid;
@ -1218,20 +1193,7 @@ enum {
LWS_EV_PREPARE_DELETION = (1 << 31),
};
#if defined(LWS_WITH_LIBEV)
LWS_EXTERN void
lws_libev_accept(struct lws *new_wsi, lws_sock_file_fd_type desc);
LWS_EXTERN void
lws_libev_io(struct lws *wsi, int flags);
LWS_EXTERN int
lws_libev_init_fd_table(struct lws_context *context);
LWS_EXTERN void
lws_libev_destroyloop(struct lws_context *context, int tsi);
LWS_EXTERN void
lws_libev_run(const struct lws_context *context, int tsi);
#define LWS_LIBEV_ENABLED(context) lws_check_opt(context->options, LWS_SERVER_OPTION_LIBEV)
LWS_EXTERN void lws_feature_status_libev(const struct lws_context_creation_info *info);
#else
#if !defined(LWS_WITH_LIBEV)
#define lws_libev_accept(_a, _b) ((void) 0)
#define lws_libev_io(_a, _b) ((void) 0)
#define lws_libev_init_fd_table(_a) (0)
@ -1246,22 +1208,7 @@ LWS_EXTERN void lws_feature_status_libev(const struct lws_context_creation_info
#endif
#endif
#if defined(LWS_WITH_LIBUV)
LWS_EXTERN void
lws_libuv_accept(struct lws *new_wsi, lws_sock_file_fd_type desc);
LWS_EXTERN void
lws_libuv_io(struct lws *wsi, int flags);
LWS_EXTERN int
lws_libuv_init_fd_table(struct lws_context *context);
LWS_EXTERN void
lws_libuv_run(const struct lws_context *context, int tsi);
LWS_EXTERN void
lws_libuv_destroyloop(struct lws_context *context, int tsi);
LWS_EXTERN int
lws_uv_initvhost(struct lws_vhost* vh, struct lws*);
#define LWS_LIBUV_ENABLED(context) lws_check_opt(context->options, LWS_SERVER_OPTION_LIBUV)
LWS_EXTERN void lws_feature_status_libuv(const struct lws_context_creation_info *info);
#else
#if !defined(LWS_WITH_LIBUV)
#define lws_libuv_accept(_a, _b) ((void) 0)
#define lws_libuv_io(_a, _b) ((void) 0)
#define lws_libuv_init_fd_table(_a) (0)
@ -1276,22 +1223,7 @@ LWS_EXTERN void lws_feature_status_libuv(const struct lws_context_creation_info
#endif
#endif
#if defined(LWS_WITH_LIBEVENT)
LWS_EXTERN void
lws_libevent_accept(struct lws *new_wsi, lws_sock_file_fd_type desc);
LWS_VISIBLE void
lws_libevent_destroy(struct lws *wsi);
LWS_EXTERN void
lws_libevent_io(struct lws *wsi, int flags);
LWS_EXTERN int
lws_libevent_init_fd_table(struct lws_context *context);
LWS_EXTERN void
lws_libevent_destroyloop(struct lws_context *context, int tsi);
LWS_EXTERN void
lws_libevent_run(const struct lws_context *context, int tsi);
#define LWS_LIBEVENT_ENABLED(context) lws_check_opt(context->options, LWS_SERVER_OPTION_LIBEVENT)
LWS_EXTERN void lws_feature_status_libevent(struct lws_context_creation_info *info);
#else
#if !defined(LWS_WITH_LIBEVENT)
#define lws_libevent_accept(_a, _b) ((void) 0)
#define lws_libevent_destroy(_a) ((void) 0)
#define lws_libevent_io(_a, _b) ((void) 0)

View file

@ -270,8 +270,8 @@ int main(int argc, char **argv)
openlog("lwsts", syslog_options, LOG_DAEMON);
#endif
/* tell the library what debug level to emit and to send it to syslog */
lws_set_log_level(debug_level, lwsl_emit_syslog);
/* tell the library what debug level to emit and to send it to stderr */
lws_set_log_level(debug_level, NULL);
lwsl_notice("libwebsockets test server libev - license LGPL2.1+SLE\n");
lwsl_notice("(C) Copyright 2010-2018 Andy Green <andy@warmcat.com>\n");
@ -306,7 +306,6 @@ int main(int argc, char **argv)
}
info.gid = -1;
info.uid = -1;
info.max_http_header_pool = 1;
info.options = opts | LWS_SERVER_OPTION_LIBEV;
context = lws_create_context(&info);

View file

@ -37,7 +37,6 @@ char crl_path[1024] = "";
#define LWS_PLUGIN_STATIC
#include "../plugins/protocol_lws_mirror.c"
#include "../plugins/protocol_lws_status.c"
#include "../plugins/protocol_lws_meta.c"
/* singlethreaded version --> no locks */
@ -69,7 +68,6 @@ enum demo_protocols {
PROTOCOL_DUMB_INCREMENT,
PROTOCOL_LWS_MIRROR,
PROTOCOL_LWS_META,
/* always last */
DEMO_PROTOCOL_COUNT
@ -95,7 +93,6 @@ static struct lws_protocols protocols[] = {
LWS_PLUGIN_PROTOCOL_MIRROR,
LWS_PLUGIN_PROTOCOL_LWS_STATUS,
LWS_PLUGIN_PROTOCOL_LWS_META,
{ NULL, NULL, 0, 0 } /* terminator */
};

View file

@ -215,9 +215,6 @@ int main(int argc, char **argv)
int use_ssl = 0;
int opts = 0;
int n = 0;
#ifndef _WIN32
int syslog_options = LOG_PID | LOG_PERROR;
#endif
#ifndef LWS_NO_DAEMONIZE
int daemonize = 0;
#endif
@ -297,14 +294,10 @@ int main(int argc, char **argv)
return 1;
}
#endif
/* we will only try to log things according to our debug_level */
setlogmask(LOG_UPTO (LOG_DEBUG));
openlog("lwsts", syslog_options, LOG_DAEMON);
#endif
/* tell the library what debug level to emit and to send it to syslog */
lws_set_log_level(debug_level, lwsl_emit_syslog);
/* tell the library what debug level to emit and to send it to stderr */
lws_set_log_level(debug_level, NULL);
lwsl_notice("libwebsockets test server libuv - license LGPL2.1+SLE\n");
lwsl_notice("(C) Copyright 2010-2016 Andy Green <andy@warmcat.com>\n");