![throttle android sdk manager download throttle android sdk manager download](http://www.droidviews.com/wp-content/uploads/2015/02/android-sdk-manager.png)
I made a screenshot:īut as you can see, the reading on the test program and the actual network BPS values differ greatly. (It's hard to explain without running an example.)įor a test I began downloading a large binary file (Windows 10 MSI, off Microsoft's server) and at the same time had the Task Manager open on a Performance tab that was showing me the current network throughput. I created a small test project that is attached to this post to illustrate the issue.
#Throttle android sdk manager download code
So I decided to add a little bit more tracking code to actually be able to see what BPS values I'm getting. }So I implemented it into the code above but it didn't work - the Sleep API would produce very strange delays.
#Throttle android sdk manager download download
::Sleep(dwW) //Sleep to throttle the download speed to the one we need
![throttle android sdk manager download throttle android sdk manager download](https://watson1978.github.io/images/blog/Android/Android_SDK_Manager_Accelerator.png)
So the formula I'd use to calculate BPS is this:Ĭode: DWORD DesiredBitsPerSec = 50 * 1000 //for 50 kbpsĭWORD dwW = (DWORD)((fBps - DesiredBitsPerSec) * 1000) / DesiredBitsPerSec Someone suggested measuring my current download speed (in bps) and depending on the value make the thread "sleep" before calling WinHttpReadData again. My goal is to make it "throttle" itself on a configurable "bps" level, say at 50 kbps and not use any more bandwidth. If (hSession) WinHttpCloseHandle(hSession) The issue I'm experiencing is that while downloading, the code above "hogs" most of the bandwidth available on the client computer. If (hConnect) WinHttpCloseHandle(hConnect) If (hRequest) WinHttpCloseHandle(hRequest)
![throttle android sdk manager download throttle android sdk manager download](https://www.guidingtech.com/wp-content/uploads/Google-Chrome-Manage-Download-Speed-4_4d470f76dc99e18ad75087b1b8410ea9.png)
Printf( "Error %d has occurred.\n", GetLastError() ) This condition should never be reached since WinHttpQueryDataAvailable Free the memory allocated to the buffer. Printf( "Error %u in WinHttpReadData.\n", GetLastError()) If (!WinHttpReadData( hRequest, (LPVOID)pszOutBuffer, Printf( "Error %u in WinHttpQueryDataAvailable.\n", If (!WinHttpQueryDataAvailable( hRequest, &dwSize)) Keep checking for data until there is nothing left. HRequest = WinHttpOpenRequest( hConnect, L"GET", NULL,īResults = WinHttpReceiveResponse( hRequest, NULL) HConnect = WinHttpConnect( hSession, L"INTERNET_DEFAULT_HTTPS_PORT, 0) HSession = WinHttpOpen( L"WinHTTP Example/1.0", Use WinHttpOpen to obtain a session handle.