Note that there are some explanatory texts on larger screens.

plurals
  1. PODownload speed jumping around allover
    primarykey
    data
    text
    <p>I have a little program that downloads files from ftp using curl. And in the function passed in CURLOPT_PROGRESSFUNCTION, I do calculations to know the download speed, the problem is the download speed jumps all over the place, from 512kbps to 8mbps on a 2mbps internet connection. And I couldn't determine what's wrong here.</p> <p><strong>EDIT :</strong> I have changed the code to average out the readings, the problem with curl download is you can not predict when the TraceProgress function will be called, it can be called again in less then 1 second, so program waits for 5 iterations to note down the readings, and take 6 such readings before averaging, I have also considered time(seconds) elapsed since last reading was taken, since we can not guarantee that TraceProgress function will be called at equal intervals.</p> <p>Let me know if it looks better now.</p> <p>Here is the code :</p> <pre><code>int minorCounter = 0; int majorCounter = 0; int minorCycle = 4; int majorCycle = 5; double blockDL[6]; double blockTime[6]; int TraceProgress( void *clientp, double dltotal, double dlnow, double ultotal, double ulnow ) { if ( minorCounter == minorCycle ) { blockDL[majorCounter] = dlnow - oldDownloadNow; myTimer.Tick(); blockTime[majorCounter] = myTimer.GetDurationInSecs(); minorCounter = 0; if ( majorCounter == majorCycle ) { double dl = 0; double tm = 0; for ( int i = 0; i &lt; majorCycle ; i++ ) { dl += blockDL[i]; tm += blockTime[i]; } dl = dl/(majorCycle+1); tm = tm/(majorCycle+1); double currentDownloadSpeed = dl / tm; /* download speed - divide by 1024 to get speed in kilobytes instead of bytes */ double idownloadSpeed = currentDownloadSpeed / 1024; string post; if ( idownloadSpeed &gt; 1024 ) { idownloadSpeed = idownloadSpeed / 1024; post = " MB/s"; } else { post = " KB/s"; } string downloadSpeed = DoubleToString( idownloadSpeed ); size_t x = downloadSpeed.find( "." ); downloadSpeed.erase( x+2 ); downSize = "Download Speed: " + downloadSpeed + post; SendMessage( hDownloadSpeedSTATIC, WM_SETTEXT, (WPARAM)0, (LPARAM)downSize.c_str() ); majorCounter = 0; } else { majorCounter++; } oldDownloadNow = dlnow; myTimer.Start(); } else { minorCounter++; } return 0; } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload