int deflate_flush(struct comp_ctx *comp_ctx, struct buffer *out, int flag) { int ret; int out_len = 0; z_stream *strm = &comp_ctx->strm; strm->next_out = (unsigned char *)bi_end(out); strm->avail_out = out->size - buffer_len(out); ret = deflate(strm, flag); if (ret != Z_OK && ret != Z_STREAM_END) return -1; out_len = (out->size - buffer_len(out)) - strm->avail_out; out->i += out_len; /* compression limit */ if ((global.comp_rate_lim > 0 && (read_freq_ctr(&global.comp_bps_out) > global.comp_rate_lim)) || /* rate */ (idle_pct < compress_min_idle)) { /* idle */ /* decrease level */ if (comp_ctx->cur_lvl > 0) { comp_ctx->cur_lvl--; deflateParams(&comp_ctx->strm, comp_ctx->cur_lvl, Z_DEFAULT_STRATEGY); } } else if (comp_ctx->cur_lvl < global.tune.comp_maxlevel) { /* increase level */ comp_ctx->cur_lvl++ ; deflateParams(&comp_ctx->strm, comp_ctx->cur_lvl, Z_DEFAULT_STRATEGY); } return out_len; }
/* set temp integer to the number of connections per second reaching the frontend. * Accepts exactly 1 argument. Argument is a frontend, other types will cause * an undefined behaviour. */ static int smp_fetch_fe_sess_rate(struct proxy *px, struct session *l4, void *l7, unsigned int opt, const struct arg *args, struct sample *smp) { smp->flags = SMP_F_VOL_TEST; smp->type = SMP_T_UINT; smp->data.uint = read_freq_ctr(&args->data.prx->fe_sess_per_sec); return 1; }
/* set test->i to the number of connections per second reaching the backend */ static int acl_fetch_be_sess_rate(struct proxy *px, struct session *l4, void *l7, int dir, struct acl_expr *expr, struct acl_test *test) { test->flags = ACL_TEST_F_VOL_TEST; if (expr->arg_len) { /* another proxy was designated, we must look for it */ for (px = proxy; px; px = px->next) if ((px->cap & PR_CAP_BE) && !strcmp(px->id, expr->arg.str)) break; } if (!px) return 0; test->i = read_freq_ctr(&px->be_sess_per_sec); return 1; }
/* Compresses the data accumulated using add_data(), and optionally sends the * format-specific trailer if <finish> is non-null. <out> is expected to have a * large enough free non-wrapping space as verified by http_comp_buffer_init(). * The number of bytes emitted is reported. */ static int rfc195x_flush_or_finish(struct comp_ctx *comp_ctx, struct buffer *out, int finish) { struct slz_stream *strm = &comp_ctx->strm; const char *in_ptr; int in_len; int out_len; in_ptr = comp_ctx->direct_ptr; in_len = comp_ctx->direct_len; if (comp_ctx->queued) { in_ptr = comp_ctx->queued->p; in_len = comp_ctx->queued->i; } out_len = out->i; if (in_ptr) out->i += slz_encode(strm, bi_end(out), in_ptr, in_len, !finish); if (finish) out->i += slz_finish(strm, bi_end(out)); out_len = out->i - out_len; /* very important, we must wipe the data we've just flushed */ comp_ctx->direct_len = 0; comp_ctx->direct_ptr = NULL; comp_ctx->queued = NULL; /* Verify compression rate limiting and CPU usage */ if ((global.comp_rate_lim > 0 && (read_freq_ctr(&global.comp_bps_out) > global.comp_rate_lim)) || /* rate */ (idle_pct < compress_min_idle)) { /* idle */ if (comp_ctx->cur_lvl > 0) strm->level = --comp_ctx->cur_lvl; } else if (comp_ctx->cur_lvl < global.tune.comp_maxlevel && comp_ctx->cur_lvl < 1) { strm->level = ++comp_ctx->cur_lvl; } /* and that's all */ return out_len; }