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. */
| 3216 | * Return value: non-zero if the client reached the soft or the hard limit. |
| 3217 | * Otherwise zero is returned. */ |
| 3218 | int checkClientOutputBufferLimits(client *c) { |
| 3219 | int soft = 0, hard = 0, class; |
| 3220 | unsigned long used_mem = getClientOutputBufferMemoryUsage(c); |
| 3221 | |
| 3222 | class = getClientType(c); |
| 3223 | /* For the purpose of output buffer limiting, masters are handled |
| 3224 | * like normal clients. */ |
| 3225 | if (class == CLIENT_TYPE_MASTER) class = CLIENT_TYPE_NORMAL; |
| 3226 | |
| 3227 | if (server.client_obuf_limits[class].hard_limit_bytes && |
| 3228 | used_mem >= server.client_obuf_limits[class].hard_limit_bytes) |
| 3229 | hard = 1; |
| 3230 | if (server.client_obuf_limits[class].soft_limit_bytes && |
| 3231 | used_mem >= server.client_obuf_limits[class].soft_limit_bytes) |
| 3232 | soft = 1; |
| 3233 | |
| 3234 | /* We need to check if the soft limit is reached continuously for the |
| 3235 | * specified amount of seconds. */ |
| 3236 | if (soft) { |
| 3237 | if (c->obuf_soft_limit_reached_time == 0) { |
| 3238 | c->obuf_soft_limit_reached_time = server.unixtime; |
| 3239 | soft = 0; /* First time we see the soft limit reached */ |
| 3240 | } else { |
| 3241 | time_t elapsed = server.unixtime - c->obuf_soft_limit_reached_time; |
| 3242 | |
| 3243 | if (elapsed <= |
| 3244 | server.client_obuf_limits[class].soft_limit_seconds) { |
| 3245 | soft = 0; /* The client still did not reached the max number of |
| 3246 | seconds for the soft limit to be considered |
| 3247 | reached. */ |
| 3248 | } |
| 3249 | } |
| 3250 | } else { |
| 3251 | c->obuf_soft_limit_reached_time = 0; |
| 3252 | } |
| 3253 | return soft || hard; |
| 3254 | } |
| 3255 | |
| 3256 | /* Asynchronously close a client if soft or hard limit is reached on the |
| 3257 | * output buffer size. The caller can check if the client will be closed |
no test coverage detected