| 420 | |
| 421 | |
| 422 | uint32 CUpDownClient::SendBlockData() |
| 423 | { |
| 424 | uint64 curTick = ::GetTickCount64(); |
| 425 | uint64 sentBytesCompleteFile = 0; |
| 426 | uint64 sentBytesPartFile = 0; |
| 427 | uint64 sentBytesPayload = 0; |
| 428 | |
| 429 | if (m_socket) { |
| 430 | CEMSocket* s = m_socket; |
| 431 | // uint32 uUpStatsPort = GetUserPort(); |
| 432 | |
| 433 | // Extended statistics information based on which client software and which port we sent this data to... |
| 434 | // This also updates the grand total for sent bytes, etc. And where this data came from. |
| 435 | sentBytesCompleteFile = s->GetSentBytesCompleteFileSinceLastCallAndReset(); |
| 436 | sentBytesPartFile = s->GetSentBytesPartFileSinceLastCallAndReset(); |
| 437 | // thePrefs.Add2SessionTransferData(GetClientSoft(), uUpStatsPort, false, true, sentBytesCompleteFile, (IsFriend() && GetFriendSlot())); |
| 438 | // thePrefs.Add2SessionTransferData(GetClientSoft(), uUpStatsPort, true, true, sentBytesPartFile, (IsFriend() && GetFriendSlot())); |
| 439 | |
| 440 | m_nTransferredUp += sentBytesCompleteFile + sentBytesPartFile; |
| 441 | credits->AddUploaded(sentBytesCompleteFile + sentBytesPartFile, GetIP(), theApp->CryptoAvailable()); |
| 442 | |
| 443 | sentBytesPayload = s->GetSentPayloadSinceLastCallAndReset(); |
| 444 | m_nCurQueueSessionPayloadUp += sentBytesPayload; |
| 445 | |
| 446 | // Wake the disk I/O thread so it can re-check its buffer condition with the |
| 447 | // freshly updated m_nCurQueueSessionPayloadUp. Without this, the thread might |
| 448 | // wait up to its WaitTimeout (100ms) before noticing curPayload advanced. |
| 449 | if (sentBytesPayload > 0 && theApp->uploadDiskIOThread) { |
| 450 | theApp->uploadDiskIOThread->SocketNeedsMoreData(); |
| 451 | } |
| 452 | |
| 453 | if (theApp->uploadqueue->CheckForTimeOver(this)) { |
| 454 | theApp->uploadqueue->RemoveFromUploadQueue(this); |
| 455 | SendOutOfPartReqsAndAddToWaitingQueue(); |
| 456 | } |
| 457 | } |
| 458 | |
| 459 | if(sentBytesCompleteFile + sentBytesPartFile > 0 || |
| 460 | m_AvarageUDR_list.empty() || (curTick - m_AvarageUDR_list.back().timestamp) > 1*1000) { |
| 461 | // Store how much data we've transferred this round, |
| 462 | // to be able to calculate average speed later |
| 463 | // keep sum of all values in list up to date |
| 464 | TransferredData newitem = {(uint32) (sentBytesCompleteFile + sentBytesPartFile), curTick}; |
| 465 | m_AvarageUDR_list.push_back(newitem); |
| 466 | m_nSumForAvgUpDataRate += sentBytesCompleteFile + sentBytesPartFile; |
| 467 | } |
| 468 | |
| 469 | // remove to old values in list |
| 470 | while ((!m_AvarageUDR_list.empty()) && (curTick - m_AvarageUDR_list.front().timestamp) > 10*1000) { |
| 471 | // keep sum of all values in list up to date |
| 472 | m_nSumForAvgUpDataRate -= m_AvarageUDR_list.front().datalen; |
| 473 | m_AvarageUDR_list.pop_front(); |
| 474 | } |
| 475 | |
| 476 | // Calculate average speed for this slot |
| 477 | if ((!m_AvarageUDR_list.empty()) && (curTick - m_AvarageUDR_list.front().timestamp) > 0 && GetUpStartTimeDelay() > 2*1000) { |
| 478 | m_nUpDatarate = ((uint64)m_nSumForAvgUpDataRate*1000) / (curTick-m_AvarageUDR_list.front().timestamp); |
| 479 | } else { |
no test coverage detected