diff --git a/lib/core/context.c b/lib/core/context.c index d11246ef1..f52d7e7d8 100644 --- a/lib/core/context.c +++ b/lib/core/context.c @@ -394,6 +394,7 @@ lws_create_context(const struct lws_context_creation_info *info) #if defined(LWS_WITH_NETWORK) unsigned short count_threads = 1; uint8_t *u; + uint16_t us_wait_resolution = 0; #endif #if defined(__ANDROID__) struct rlimit rt; @@ -469,6 +470,13 @@ lws_create_context(const struct lws_context_creation_info *info) { extern const lws_plugin_evlib_t evlib_poll; plev = &evlib_poll; +#if !defined(LWS_PLAT_FREERTOS) + /* + * ... freertos has us-resolution select()... + * others are to ms-resolution poll() + */ + us_wait_resolution = 1000; +#endif } #endif @@ -575,6 +583,7 @@ lws_create_context(const struct lws_context_creation_info *info) extern const lws_plugin_evlib_t evlib_uv; plev = &evlib_uv; fatal_exit_defer = !!info->foreign_loops; + us_wait_resolution = 0; } #endif @@ -582,6 +591,7 @@ lws_create_context(const struct lws_context_creation_info *info) if (lws_check_opt(info->options, LWS_SERVER_OPTION_LIBEVENT)) { extern const lws_plugin_evlib_t evlib_event; plev = &evlib_event; + us_wait_resolution = 0; } #endif @@ -589,6 +599,7 @@ lws_create_context(const struct lws_context_creation_info *info) if (lws_check_opt(info->options, LWS_SERVER_OPTION_GLIB)) { extern const lws_plugin_evlib_t evlib_glib; plev = &evlib_glib; + us_wait_resolution = 0; } #endif @@ -596,6 +607,7 @@ lws_create_context(const struct lws_context_creation_info *info) if (lws_check_opt(info->options, LWS_SERVER_OPTION_LIBEV)) { extern const lws_plugin_evlib_t evlib_ev; plev = &evlib_ev; + us_wait_resolution = 0; } #endif @@ -603,6 +615,7 @@ lws_create_context(const struct lws_context_creation_info *info) if (lws_check_opt(info->options, LWS_SERVER_OPTION_SDEVENT)) { extern const lws_plugin_evlib_t evlib_sd; plev = &evlib_sd; + us_wait_resolution = 0; } #endif @@ -628,6 +641,7 @@ lws_create_context(const struct lws_context_creation_info *info) #if defined(LWS_WITH_NETWORK) context->event_loop_ops = plev->ops; + context->us_wait_resolution = us_wait_resolution; #endif #if defined(LWS_WITH_EVENT_LIBS) /* at the very end */ diff --git a/lib/core/private-lib-core.h b/lib/core/private-lib-core.h index e713b064e..c2f5a3576 100644 --- a/lib/core/private-lib-core.h +++ b/lib/core/private-lib-core.h @@ -640,6 +640,8 @@ struct lws_context { #if defined(LWS_WITH_SECURE_STREAMS_PROXY_API) uint16_t ss_proxy_port; #endif + /* 0 if not known, else us resolution of the poll wait */ + uint16_t us_wait_resolution; uint8_t max_fi; uint8_t udp_loss_sim_tx_pc; diff --git a/lib/event-libs/private-lib-event-libs.h b/lib/event-libs/private-lib-event-libs.h index 35bfcd885..3c249498e 100644 --- a/lib/event-libs/private-lib-event-libs.h +++ b/lib/event-libs/private-lib-event-libs.h @@ -1,7 +1,7 @@ /* * libwebsockets - small server side websockets and web server implementation * - * Copyright (C) 2010 - 2019 Andy Green + * Copyright (C) 2010 - 2021 Andy Green * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to diff --git a/lib/plat/unix/unix-service.c b/lib/plat/unix/unix-service.c index 8428bf86c..e076a8871 100644 --- a/lib/plat/unix/unix-service.c +++ b/lib/plat/unix/unix-service.c @@ -115,7 +115,13 @@ _lws_plat_service_tsi(struct lws_context *context, int timeout_ms, int tsi) */ us = __lws_sul_service_ripe(pt->pt_sul_owner, LWS_COUNT_PT_SUL_OWNERS, us); if (us && us < timeout_us) - timeout_us = us; + /* + * If something wants zero wait, that's OK, but if the next sul + * coming ripe is an interval less than our wait resolution, + * bump it to be the wait resolution. + */ + timeout_us = us < context->us_wait_resolution ? + context->us_wait_resolution : us; lws_pt_unlock(pt); diff --git a/lib/plat/windows/windows-service.c b/lib/plat/windows/windows-service.c index 4cc94e5b7..a64501d36 100644 --- a/lib/plat/windows/windows-service.c +++ b/lib/plat/windows/windows-service.c @@ -1,7 +1,7 @@ /* * libwebsockets - small server side websockets and web server implementation * - * Copyright (C) 2010 - 2019 Andy Green + * Copyright (C) 2010 - 2021 Andy Green * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to @@ -133,7 +133,13 @@ _lws_plat_service_tsi(struct lws_context *context, int timeout_ms, int tsi) LWS_COUNT_PT_SUL_OWNERS, lws_now_usecs()); if (us && us < timeout_us) - timeout_us = us; + /* + * If something wants zero wait, that's OK, but if the next sul + * coming ripe is an interval less than our wait resolution, + * bump it to be the wait resolution. + */ + timeout_us = us < context->us_wait_resolution ? + context->us_wait_resolution : us; lws_pt_unlock(pt); }