Skip to content

Commit

Permalink
Merge r1439623 from trunk:
Browse files Browse the repository at this point in the history
Fix error because of negative rate-limit
PR : 52964
Submitted by: Tianyin Xu <tixu cs ucsd edu>
Submitted by: jailletc36
Reviewed/backported by: jim


git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/branches/2.4.x@1455219 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
Jim Jagielski committed Mar 11, 2013
1 parent cdd5cda commit c8385f0
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 16 deletions.
6 changes: 0 additions & 6 deletions STATUS
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,6 @@ PATCHES ACCEPTED TO BACKPORT FROM TRUNK:
[ start all new proposals below, under PATCHES PROPOSED. ]


* mod_rate_limit: Fix error because of negative rate-limit
PR 52964 [ianyin Xu <tixu cs ucsd edu>]
trunk patch: http://svn.apache.org/viewvc?view=revision&revision=1439623
2.4.x patch: trunk patch applies.
+1: jailletc36, fuankg, jim

* Set of easy patches to keep 2.4.x in line with trunk
1442865: Change bzero/bcopy into memset/memcpy (PR 54346)
1442759: Can't figure out why we allocate len+2 bytes here. Len+1 should be enough.
Expand Down
20 changes: 10 additions & 10 deletions modules/filters/mod_ratelimit.c
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ rate_limit_filter(ap_filter_t *f, apr_bucket_brigade *input_bb)
if (ctx == NULL) {

const char *rl = NULL;
int ratelimit;

/* no subrequests. */
if (f->r->main != NULL) {
Expand All @@ -87,22 +88,21 @@ rate_limit_filter(ap_filter_t *f, apr_bucket_brigade *input_bb)
ap_remove_output_filter(f);
return ap_pass_brigade(f->next, bb);
}

/* first run, init stuff */
ctx = apr_palloc(f->r->pool, sizeof(rl_ctx_t));
f->ctx = ctx;
ctx->speed = 0;
ctx->state = RATE_LIMIT;


/* rl is in kilo bytes / second */
ctx->speed = atoi(rl) * 1024;

if (ctx->speed == 0) {
ratelimit = atoi(rl) * 1024;
if (ratelimit <= 0) {
/* remove ourselves */
ap_remove_output_filter(f);
return ap_pass_brigade(f->next, bb);
}

/* first run, init stuff */
ctx = apr_palloc(f->r->pool, sizeof(rl_ctx_t));
f->ctx = ctx;
ctx->state = RATE_LIMIT;
ctx->speed = ratelimit;

/* calculate how many bytes / interval we want to send */
/* speed is bytes / second, so, how many (speed / 1000 % interval) */
ctx->chunk_size = (ctx->speed / (1000 / RATE_INTERVAL_MS));
Expand Down

0 comments on commit c8385f0

Please sign in to comment.