// enkeyDEV(Ottavio84) - Accurate speed measurement- struct TransferredData { uint32 datalen; uint32 timestamp;
then change in uploadqueue.h
CList<int,int> avarage_dr_list;
in
CList<TransferredData,TransferredData> avarage_dr_list;
in updownclient.h
CList<TransferredData,TransferredData> m_AvarageUDR_list; uint32 sendtimestamp;
in UploadQueue.cpp
add to CUploadQueue::CUploadQueue(CPreferences* in_prefs)
//patch by BadWolf TransferredData newitem = {0,::GetTickCount()}; for (int i = 0;i != 400;i++) avarage_dr_list.AddHead(newitem);
and
void CUploadQueue::Process(){ // Patch by BadWolf (on an EnkeyDEV(Ottavio84) idea) TransferredData newitem = {theApp.stat_sessionSentBytes, ::GetTickCount()}; avarage_dr_list.RemoveHead(); avarage_dr_list.AddTail(newitem); float deltat = (float)(avarage_dr_list.GetTail().timestamp - avarage_dr_list.GetHead().timestamp) / 1000.0; if (deltat > 0.0) datarate = (uint32)((float)(avarage_dr_list.GetTail().datalen - avarage_dr_list.GetHead().datalen) / deltat); else datarate = 0; dataratems = 0; if (AcceptNewClient() && waitinglist.GetCount()) AddUpNextClient(); if (!uploadinglist.GetCount()) return; int16 clientsrdy = 0; for (POSITION pos = uploadinglist.GetHeadPosition();pos != 0;uploadinglist.GetNext(pos)){ CUpDownClient* cur_client = uploadinglist.GetAt(pos); if ( (cur_client->socket) && (!cur_client->socket->IsBusy()) && cur_client->HasBlocks()) clientsrdy++; } if (!clientsrdy){ estadatarate -= 200; if (estadatarate < 100) estadatarate = 100; clientsrdy++; } else{ int timediff = GetTickCount() - sendtimestamp; sendtimestamp = GetTickCount(); estadatarate += 200; int maxrate = app_prefs->GetMaxUpload()*112; // why 112?? experimental if (estadatarate > maxrate) estadatarate = maxrate; } uint32 sendperclient = estadatarate/clientsrdy; for (POSITION pos = uploadinglist.GetHeadPosition(); pos; ) dataratems += uploadinglist.GetNext(pos)->SendBlockData(sendperclient); };
in Uploadclient.cpp substitute
uint32 CUpDownClient::SendBlockData(uint32 nMaxAmmount){ // By Maella TransferredData newitem = {dataratems,::GetTickCount()}; m_AvarageUDR_list.AddTail(newitem); sumavguprate += dataratems; if (m_AvarageUDR_list.GetCount() > 500) sumavguprate -= m_AvarageUDR_list.RemoveHead().datalen; if(m_AvarageUDR_list.GetCount() > 10) m_nUpDatarate = sumavguprate /((m_AvarageUDR_list.GetTail().timestamp - m_AvarageUDR_list.GetHead().timestamp)/1000); else m_nUpDatarate = 0; // Refresh GUI m_cSendblock++; if (m_cSendblock == 30){ m_cSendblock = 0; theApp.emuledlg->transferwnd.uploadlistctrl.RefreshClient(this); } dataratems = 0; uint32 timesend = ::GetTickCount(); // Send Block if (socket && !socket->IsBusy()){ if (m_BlockSend_queue.IsEmpty()){ if (!CreateNextBlockPackage()) return 0; } // Splitting packets if necessary // Remark: - don't use 2*MAXFRAGSIZE (see CEMSocket::Send()), otherwise the // counter m_nMaxSendAllowed will trigged the sending of two TCP packets // of 1300 (2*1300) at the same time => increase the ping of the application. // - should be moved to CreateNextBlockPackage() if (m_BlockSend_queue.GetHead()->GetRealPacketSize() > 0 && m_BlockSend_queue.GetHead()->GetRealPacketSize() > MAXFRAGSIZE){ uint32 nSize = m_BlockSend_queue.GetHead()->GetRealPacketSize(); const char* pBuffer = m_BlockSend_queue.GetHead()->DetachPacket(); delete m_BlockSend_queue.RemoveHead(); uint32 nPos = nSize; bool bLast = true; while (nPos){ uint32 nNewSize = (nPos < MAXFRAGSIZE) ? nPos : MAXFRAGSIZE; nPos -= nNewSize; char* pBuffer2 = new char[nNewSize]; memcpy(pBuffer2,pBuffer+nPos,nNewSize); m_BlockSend_queue.AddHead(new Packet(pBuffer2,nNewSize,bLast)); bLast = false; } delete[] pBuffer; } // Send packet(s) m_nMaxSendAllowed += nMaxAmmount; while (!socket->IsBusy() && !m_BlockSend_queue.IsEmpty() && m_BlockSend_queue.GetHead()->GetRealPacketSize() <= m_nMaxSendAllowed){ Packet* tosend = m_BlockSend_queue.RemoveHead(); uint32 nBlockSize = tosend->GetRealPacketSize(); m_nMaxSendAllowed -= nBlockSize; dataratems += nBlockSize; // theApp.uploadqueue->AddUpDataOverheadOther(0, 24); socket->SendPacket(tosend, true, false); if (m_BlockSend_queue.IsEmpty()) CreateNextBlockPackage(); } // Update credits m_nTransferedUp += dataratems; theApp.UpdateSentBytes(dataratems); credits->AddUploaded(dataratems); // Return the real size of sent packet(s) => true bandwidth (it means less wrong here) return dataratems; } return 0; }
then to fix the stats:
in statisticsDlg.h
list<TransferredData> uprateHistory;
in statisticsdlg.cpp
void CStatisticsDlg::RecordRate() { if (theApp.stat_transferStarttime==0) return; // every second TransferredData newitem = {theApp.stat_sessionSentBytes, ::GetTickCount()}; downrateHistory.push_front(theApp.stat_sessionReceivedBytes); uprateHistory.push_front(newitem); // limit to maxmins while ((int)downrateHistory.size()>(int)( theApp.glob_prefs->GetStatsAverageMinutes()*60)) downrateHistory.pop_back(); while ((float)(uprateHistory.front().timestamp - uprateHistory.back().timestamp) / 1000.0>(int)( theApp.glob_prefs->GetStatsAverageMinutes()*60)) uprateHistory.pop_back(); }
and
float CStatisticsDlg::GetAvgUploadRate(int averageType) { if (averageType==AVG_SESSION) { if (theApp.stat_transferStarttime==0) return 0; float running=(GetTickCount()-theApp.stat_transferStarttime)/1000; if (running<5) return 0; return (float)(theApp.stat_sessionSentBytes/1024) / running; } else { if (uprateHistory.size()==0) return 0; float deltat = (float)(uprateHistory.front().timestamp - uprateHistory.back().timestamp) / 1000.0; if (deltat > 0.0) return (float)((float)(uprateHistory.front().datalen-uprateHistory.back().datalen) / deltat)/1024; else return 0; } }
BadWolf
This post has been edited by BadWolf63: 16 February 2003 - 11:55 AM