MCPcopy Create free account
hub / github.com/Snapchat/KeyDB / checkClientOutputBufferLimits

Function checkClientOutputBufferLimits

src/networking.cpp:3863–3899  ·  view source on GitHub ↗

The function checks if the client reached output buffer soft or hard * limit, and also update the state needed to check the soft limit as * a side effect. * * Return value: non-zero if the client reached the soft or the hard limit. * Otherwise zero is returned. */

Source from the content-addressed store, hash-verified

3861 * Return value: non-zero if the client reached the soft or the hard limit.
3862 * Otherwise zero is returned. */
3863int checkClientOutputBufferLimits(client *c) {
3864 int soft = 0, hard = 0;
3865 unsigned long used_mem = getClientOutputBufferMemoryUsage(c);
3866
3867 int clientType = getClientType(c);
3868 /* For the purpose of output buffer limiting, masters are handled
3869 * like normal clients. */
3870 if (clientType == CLIENT_TYPE_MASTER) clientType = CLIENT_TYPE_NORMAL;
3871
3872 if (cserver.client_obuf_limits[clientType].hard_limit_bytes &&
3873 used_mem >= cserver.client_obuf_limits[clientType].hard_limit_bytes)
3874 hard = 1;
3875 if (cserver.client_obuf_limits[clientType].soft_limit_bytes &&
3876 used_mem >= cserver.client_obuf_limits[clientType].soft_limit_bytes)
3877 soft = 1;
3878
3879 /* We need to check if the soft limit is reached continuously for the
3880 * specified amount of seconds. */
3881 if (soft) {
3882 if (c->obuf_soft_limit_reached_time == 0) {
3883 c->obuf_soft_limit_reached_time = g_pserver->unixtime;
3884 soft = 0; /* First time we see the soft limit reached */
3885 } else {
3886 time_t elapsed = g_pserver->unixtime - c->obuf_soft_limit_reached_time;
3887
3888 if (elapsed <=
3889 cserver.client_obuf_limits[clientType].soft_limit_seconds) {
3890 soft = 0; /* The client still did not reached the max number of
3891 seconds for the soft limit to be considered
3892 reached. */
3893 }
3894 }
3895 } else {
3896 c->obuf_soft_limit_reached_time = 0;
3897 }
3898 return soft || hard;
3899}
3900
3901/* Asynchronously close a client if soft or hard limit is reached on the
3902 * output buffer size. The caller can check if the client will be closed

Callers 2

flushDataMethod · 0.85

Calls 2

getClientTypeFunction · 0.85

Tested by

no test coverage detected