library/src/network/httpd/BP-HTTPdDataRateLimits.cc
// One or more recv rates has been exceeded.
One or more recv rates has been exceeded.
One or more recv rates has been exceeded .
BP_BOOL BP_HTTPdRateLimitCheckRecvExceedsLimit(P_BP_HTTPD_DATA_RATE_LIMITER rate_limit)
{
	if(!rate_limit)
		return BP_FALSE;
	if(rate_limit->curr_websocket_recv_bytes_per_second > rate_limit->max_websocket_recv_bytes_per_second)
	{
		if((rate_limit->curr_websocket_recv_bytes_per_second / rate_limit->max_websocket_recv_bytes_per_second) >= 1)
		{
			float byte_difference = rate_limit->curr_websocket_recv_bytes_per_second - rate_limit->max_websocket_recv_bytes_per_second;
			float tmp = (byte_difference / rate_limit->max_websocket_recv_bytes_per_second) * 100;
			size_t percentage_of_second = (size_t) tmp;
			size_t sleep_duration = percentage_of_second * 10000;
			rate_limit->curr_websocket_recv_bytes_per_second -= byte_difference;
			printf("\n Sleeping to decrease kbps: %f - %u - %u - %f", byte_difference, rate_limit->max_websocket_recv_bytes_per_second, sleep_duration, tmp);
			printf("\n");
			printf("\n");
			usleep(sleep_duration);
		}
		return BP_TRUE;
	}
	return BP_FALSE;
}
BP_BOOL BP_HTTPdRateLimitCheckRecvExceedsLimit ( P_BP_HTTPD_DATA_RATE_LIMITER rate_limit ) { if ( ! rate_limit ) return BP_FALSE ; if ( rate_limit -> curr_websocket_recv_bytes_per_second > rate_limit -> max_websocket_recv_bytes_per_second ) { if ( ( rate_limit -> curr_websocket_recv_bytes_per_second / rate_limit -> max_websocket_recv_bytes_per_second ) >= 1 ) { float byte_difference = rate_limit -> curr_websocket_recv_bytes_per_second - rate_limit -> max_websocket_recv_bytes_per_second ; float tmp = ( byte_difference / rate_limit -> max_websocket_recv_bytes_per_second ) * 100 ; size_t percentage_of_second = ( size_t ) tmp ; size_t sleep_duration = percentage_of_second * 10000 ; rate_limit -> curr_websocket_recv_bytes_per_second -= byte_difference ; printf ( " \n " , byte_difference , rate_limit -> max_websocket_recv_bytes_per_second , sleep_duration , tmp ) ; printf ( " \n " ) ; printf ( " \n " ) ; usleep ( sleep_duration ) ; } return BP_TRUE ; } return BP_FALSE ; }
One or more recv rates has been exceeded.
One or more recv rates has been exceeded .
// check to see if we have a rate limit // if the number of websocket recv bytes per second is greater than the // number of recv bytes capped, return indicating so. // sleep test // calculate the byte difference // perform floating point calculation // set the percentage of a second // set the sleep duration // reduce the recv bytes per second // sleep for the nececessary duration // return indicating that no send rate has been exceeded