code:
if (u->limit_rate) {
excess = u->received - u->limit_rate_after
- u->limit_rate * (ngx_time() - r->start_sec + 1);
if (excess > 0) {
if (ngx_handle_read_event(r->connection->read, 0) != NGX_OK) {
return NGX_HTTP_INTERNAL_SERVER_ERROR;
}
delay = excess * 1000 /u->limit_rate;
if (delay > 0) {
c->read->delayed = 1;
ngx_add_timer(r->connection->read, delay);
return NGX_AGAIN;
}
}
}
Variable and description:
a. u->limit_rate
Description:
This variable can be set by user. The configure file include the phrase to set.
Limit the rate to upload file.
Example: proxy_limit_rate 10k;
b. u->limit_rate_after
Description:
This variable can be set by user. The configure file include the phrase to set.
Limit rate after 10k byte.
Example: proxy_limit_rate_after 10k;
Function and description:
ngx_add_timer(r->connection->read, delay);
http://blog.csdn.net/marcky/article/details/7623335
ngx_add_timer函数就是用来完成将一个新的定时事件加入定时器红黑树中,定时事件被执行后,就会从树中移除.
Summary:
After above, we only need to rewrite the
ngx_http_read_client_request_body ==> ngx_http_proxy_read_client_request_body
Notice:
a. ngx_http_proxy_read_client_request_body_handler
This function should be modify. Because ngx_handle_read_event(rev, clcf->send_lowat)
need to add for process read delay.
This code is important to deal read timeout. Or your code will be exit.
r->connection->read->timedout, r->connection->read->delayed = 0;