[core] short-circuit connection_write_throttle()
short-circuit connection_write_throttle() when throttling not enabled
@@ -244,34 +244,39 @@ static void connection_handle_response_end_state(request_st * const r, connectio
}
}
+
+__attribute_pure__
static off_t
-connection_write_throttle (connection * const con, off_t max_bytes)
+connection_write_throttled (const connection * const con, off_t max_bytes)
{
- request_st * const r = &con->request;
- if (r->conf.global_bytes_per_second) {
- off_t limit = (off_t)r->conf.global_bytes_per_second
- - *(r->conf.global_bytes_per_second_cnt_ptr);
- if (limit <= 0) {
- /* we reached the global traffic limit */
- con->traffic_limit_reached = 1;
- return 0;
- }
- else if (max_bytes > limit)
+ const request_config * const restrict rconf = &con->request.conf;
+ if (0 == rconf->global_bytes_per_second && 0 == rconf->bytes_per_second)
+ return max_bytes;
+
+ if (rconf->global_bytes_per_second) {
+ off_t limit = (off_t)rconf->global_bytes_per_second
+ - *(rconf->global_bytes_per_second_cnt_ptr);
+ if (max_bytes > limit)
max_bytes = limit;
}
- if (r->conf.bytes_per_second) {
- off_t limit = (off_t)r->conf.bytes_per_second
+ if (rconf->bytes_per_second) {
+ off_t limit = (off_t)rconf->bytes_per_second
- con->bytes_written_cur_second;
- if (limit <= 0) {
- /* we reached the traffic limit */
- con->traffic_limit_reached = 1;
- return 0;
- }
- else if (max_bytes > limit)
+ if (max_bytes > limit)
max_bytes = limit;
}
+ return max_bytes > 0 ? max_bytes : 0; /*(0 == reached traffic limit)*/
+}
+
+
+static off_t
+connection_write_throttle (connection * const con, off_t max_bytes)
+{
+ /*assert(max_bytes > 0);*/
+ max_bytes = connection_write_throttled(con, max_bytes);
+ if (0 == max_bytes) con->traffic_limit_reached = 1;
return max_bytes;
}
