| 879 | |
| 880 | |
| 881 | bool CDownloadQueue::SendNextUDPPacket() |
| 882 | { |
| 883 | if ( m_filelist.empty() || !theApp->serverconnect->IsUDPSocketAvailable() || !theApp->IsConnectedED2K()) { |
| 884 | return false; |
| 885 | } |
| 886 | |
| 887 | // Start monitoring the server and the files list |
| 888 | if ( !m_queueServers.IsActive() ) { |
| 889 | AddObserver( &m_queueFiles ); |
| 890 | |
| 891 | theApp->serverlist->AddObserver( &m_queueServers ); |
| 892 | } |
| 893 | |
| 894 | |
| 895 | bool packetSent = false; |
| 896 | while ( !packetSent ) { |
| 897 | // Get max files ids per packet for current server |
| 898 | int filesAllowed = GetMaxFilesPerUDPServerPacket(); |
| 899 | |
| 900 | if (filesAllowed < 1 || !m_udpserver || IsConnectedServer(m_udpserver)) { |
| 901 | // Select the next server to ask, must not be the connected server |
| 902 | do { |
| 903 | m_udpserver = m_queueServers.GetNext(); |
| 904 | } while (IsConnectedServer(m_udpserver)); |
| 905 | |
| 906 | m_cRequestsSentToServer = 0; |
| 907 | filesAllowed = GetMaxFilesPerUDPServerPacket(); |
| 908 | } |
| 909 | |
| 910 | |
| 911 | // Check if we have asked all servers, in which case we are done |
| 912 | if (m_udpserver == NULL) { |
| 913 | DoStopUDPRequests(); |
| 914 | |
| 915 | return false; |
| 916 | } |
| 917 | |
| 918 | // Memoryfile containing the hash of every file to request |
| 919 | // 28bytes allocation because 16b + 4b + 8b is the worse case scenario. |
| 920 | CMemFile hashlist( 28 ); |
| 921 | |
| 922 | CPartFile* file = m_queueFiles.GetNext(); |
| 923 | |
| 924 | while ( file && filesAllowed ) { |
| 925 | uint8 status = file->GetStatus(); |
| 926 | |
| 927 | if ( ( status == PS_READY || status == PS_EMPTY ) && file->GetSourceCount() < thePrefs::GetMaxSourcePerFileUDP() ) { |
| 928 | if (file->IsLargeFile() && !m_udpserver->SupportsLargeFilesUDP()) { |
| 929 | AddDebugLogLineN(logDownloadQueue, "UDP Request for sources on a large file ignored: server doesn't support it"); |
| 930 | } else { |
| 931 | ++m_cRequestsSentToServer; |
| 932 | hashlist.WriteHash( file->GetFileHash() ); |
| 933 | // See the notes on TCP packet |
| 934 | if ( m_udpserver->GetUDPFlags() & SRV_UDPFLG_EXT_GETSOURCES2 ) { |
| 935 | if (file->IsLargeFile()) { |
| 936 | wxASSERT(m_udpserver->SupportsLargeFilesUDP()); |
| 937 | hashlist.WriteUInt32( 0 ); |
| 938 | hashlist.WriteUInt64( file->GetFileSize() ); |
nothing calls this directly
no test coverage detected