MCPcopy Create free account
hub / github.com/amule-project/amule / AddUpNextClient

Method AddUpNextClient

src/UploadQueue.cpp:169–237  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

167
168
169void CUploadQueue::AddUpNextClient(CUpDownClient* directadd)
170{
171 CUpDownClient* newclient = NULL;
172 CClientRef newClientRef;
173 // select next client or use given client
174 if (!directadd) {
175 SortGetBestClient(&newClientRef);
176 newclient = newClientRef.GetClient();
177#if EXTENDED_UPLOADQUEUE
178 if (!newclient) {
179 // Nothing to upload. Try to find something from the sources.
180 if (PopulatePossiblyWaitingList() > 0) {
181 newClientRef = * m_possiblyWaitingList.begin();
182 m_possiblyWaitingList.pop_front();
183 newclient = newClientRef.GetClient();
184 AddDebugLogLineN( logLocalClient, "Added client from possiblyWaitingList " + newclient->GetFullIP() );
185 }
186 }
187#endif
188 if (!newclient) {
189 return;
190 }
191 } else {
192 // Check if requested file is suspended or not shared (maybe deleted recently)
193
194 if (IsSuspended(directadd->GetUploadFileID())
195 || !theApp->sharedfiles->GetFileByID(directadd->GetUploadFileID())) {
196 return;
197 } else {
198 newclient = directadd;
199 }
200 }
201
202 if (IsDownloading(newclient)) {
203 return;
204 }
205 // tell the client that we are now ready to upload
206 if (!newclient->IsConnected()) {
207 newclient->SetUploadState(US_CONNECTING);
208 if (!newclient->TryToConnect(true)) {
209 return;
210 }
211 } else {
212 CPacket* packet = new CPacket(OP_ACCEPTUPLOADREQ, 0, OP_EDONKEYPROT);
213 theStats::AddUpOverheadFileRequest(packet->GetPacketSize());
214 AddDebugLogLineN( logLocalClient, "Local Client: OP_ACCEPTUPLOADREQ to " + newclient->GetFullIP() );
215 newclient->SendPacket(packet,true);
216 newclient->SetUploadState(US_UPLOADING);
217 }
218 newclient->SetUpStartTime();
219 newclient->ResetSessionUp();
220
221 {
222 // Guard against concurrent iteration by the disk I/O thread.
223 wxMutexLocker lock(m_uploadingListMutex);
224 theApp->uploadBandwidthThrottler->AddToStandardList(m_uploadinglist.size(), newclient->GetSocket());
225 m_uploadinglist.push_back(CCLIENTREF(newclient, "CUploadQueue::AddUpNextClient"));
226 }

Callers

nothing calls this directly

Calls 15

SetUploadStateMethod · 0.80
TryToConnectMethod · 0.80
GetPacketSizeMethod · 0.80
SetUpStartTimeMethod · 0.80
ResetSessionUpMethod · 0.80
AddToStandardListMethod · 0.80
GetSocketMethod · 0.80
AddAcceptedMethod · 0.80
ECIDMethod · 0.80
GetClientMethod · 0.45
beginMethod · 0.45
GetFullIPMethod · 0.45

Tested by

no test coverage detected