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

service: restrict effective wait to platform resolution

This commit is contained in:
Andy Green 2021-01-17 11:27:59 +00:00
parent 4dbf5454c9
commit 1062149e9f
5 changed files with 32 additions and 4 deletions

View file

@ -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 */

View file

@ -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;

View file

@ -1,7 +1,7 @@
/*
* libwebsockets - small server side websockets and web server implementation
*
* Copyright (C) 2010 - 2019 Andy Green <andy@warmcat.com>
* Copyright (C) 2010 - 2021 Andy Green <andy@warmcat.com>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to

View file

@ -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);

View file

@ -1,7 +1,7 @@
/*
* libwebsockets - small server side websockets and web server implementation
*
* Copyright (C) 2010 - 2019 Andy Green <andy@warmcat.com>
* Copyright (C) 2010 - 2021 Andy Green <andy@warmcat.com>
*
* 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);
}