diff options
| -rw-r--r-- | shaping/src/shaper.cpp | 15 | ||||
| -rw-r--r-- | shaping/test/stub.cpp | 8 |
2 files changed, 12 insertions, 11 deletions
diff --git a/shaping/src/shaper.cpp b/shaping/src/shaper.cpp index 95277f1..a8a955a 100644 --- a/shaping/src/shaper.cpp +++ b/shaping/src/shaper.cpp @@ -426,7 +426,7 @@ static int shaper_deposit_token_is_enough(struct shaping_profile_info *pf_info, } } -static int shaper_token_get_from_profile(struct swarmkv *db, struct shaping_flow *sf, struct shaping_profile_info *pf_info, int profile_type, int req_token, unsigned char direction) +static int shaper_token_get_from_profile(struct swarmkv *db, struct shaping_flow *sf, struct shaping_profile_info *pf_info, int profile_type, int req_token_bits, unsigned char direction) { struct shaping_async_cb_arg *arg; char key[32] = {0}; @@ -440,9 +440,9 @@ static int shaper_token_get_from_profile(struct swarmkv *db, struct shaping_flow arg->sf = sf; arg->direction = direction; - swarmkv_tconsume(db, key, strlen(key), req_token, shaper_token_get_cb, arg); + swarmkv_tconsume(db, key, strlen(key), req_token_bits, shaper_token_get_cb, arg); if (__atomic_load_n(&pf_info->async_token_ref_count, __ATOMIC_SEQ_CST) != 0) {//has async operation not completed - shaper_deposit_token_sub(pf_info, req_token, direction); + shaper_deposit_token_sub(pf_info, req_token_bits, direction); return 0; } @@ -454,8 +454,8 @@ static int shaper_token_get_from_profile(struct swarmkv *db, struct shaping_flow } } - if (shaper_deposit_token_is_enough(pf_info, req_token, direction)) { - shaper_deposit_token_sub(pf_info, req_token, direction); + if (shaper_deposit_token_is_enough(pf_info, req_token_bits, direction)) { + shaper_deposit_token_sub(pf_info, req_token_bits, direction); return 0; } @@ -517,13 +517,14 @@ static int shaper_profile_is_priority_blocked(struct swarmkv *db, struct shaping } } -static int shaper_token_consume(struct swarmkv *db, struct shaping_flow *sf, int req_token, +static int shaper_token_consume(struct swarmkv *db, struct shaping_flow *sf, int req_token_bytes, struct shaping_profile_info *profile, int profile_type, unsigned char direction) { if (shaper_profile_is_priority_blocked(db, sf, profile)) { return -1; } else { - return shaper_token_get_from_profile(db, sf, profile, profile_type, req_token, direction); + int req_token_bits = req_token_bytes * 8; + return shaper_token_get_from_profile(db, sf, profile, profile_type, req_token_bits, direction); } } diff --git a/shaping/test/stub.cpp b/shaping/test/stub.cpp index f16d351..3af3cf9 100644 --- a/shaping/test/stub.cpp +++ b/shaping/test/stub.cpp @@ -84,11 +84,11 @@ void * stub_get_token_thread_func(void *data) void stub_set_token_bucket_avl_per_sec(int profile_id, unsigned int tokens, unsigned char direction) { if (direction == SHAPING_DIR_IN) { - pf_array[profile_id].in_limit_bandwidth = tokens; - pf_curr_avl_token[profile_id].in_limit_bandwidth = tokens; + pf_array[profile_id].in_limit_bandwidth = tokens * 8; + pf_curr_avl_token[profile_id].in_limit_bandwidth = tokens * 8; } else { - pf_array[profile_id].out_limit_bandwidth = tokens; - pf_curr_avl_token[profile_id].out_limit_bandwidth = tokens; + pf_array[profile_id].out_limit_bandwidth = tokens * 8; + pf_curr_avl_token[profile_id].out_limit_bandwidth = tokens * 8; } return; |
