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

Method SendQueue

src/ServerUDPSocket.cpp:414–484  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

412
413
414void CServerUDPSocket::SendQueue()
415{
416 while (!m_queue.empty()) {
417 ServerUDPPacket item = m_queue.front();
418 CPacket* packet = item.packet;
419
420 // Do we need to do a DNS lookup before sending?
421 wxASSERT(item.ip || !item.addr.IsEmpty());
422 if (!item.addr.IsEmpty()) {
423 // This not an ip but a hostname. Resolve it.
424 CServer* update = theApp->serverlist->GetServerByAddress(item.addr, item.port);
425 if (update) {
426 const uint64 now = ::GetTickCount64();
427 if (update->GetLastDNSSolve() + DNS_SOLVE_TIME < now) {
428 // Its time for a new check.
429 CAsyncDNS* dns = new CAsyncDNS(item.addr, DNS_UDP, theApp, this);
430 if ((dns->Create() != wxTHREAD_NO_ERROR) || (dns->Run() != wxTHREAD_NO_ERROR)) {
431 // Not much we can do here, just drop the packet.
432 dns->Delete();
433 m_queue.pop_front();
434 continue;
435 }
436 update->SetDNSError(false);
437 update->SetLastDNSSolve(now);
438 // Wait for the DNS query to be resolved
439 return;
440 } else {
441 // It has been checked recently, don't re-check yet.
442 if (update->GetDNSError()) {
443 // Drop the packet, dns failed last time
444 AddDebugLogLineN(logServerUDP, "Trying to send a UDP packet to a server host that failed DNS: "+item.addr);
445 m_queue.pop_front();
446 continue;
447 } else {
448 // It has been solved or is solving.
449 if (update->GetIP()) {
450 // It has been solved and ok
451 AddDebugLogLineN(logServerUDP, "Sending a UDP packet to a resolved DNS server host: "+item.addr);
452 // Update the item IP
453 item.ip = update->GetIP();
454 // It'll fallback to the sending.
455 } else {
456 AddDebugLogLineN(logServerUDP, "Trying to send a UDP packet to a server host that is checking DNS: "+item.addr);
457 // Let the packet queued, and wait for resolution
458 // Meanwhile, send other packets.
459 m_queue.pop_front();
460 m_queue.push_back(item);
461 return;
462 }
463 }
464 }
465 } else {
466 AddDebugLogLineN(logServerUDP, "Trying to send a UDP packet to a server host that is not on serverlist");
467 // Not much we can do here, just drop the packet.
468 m_queue.pop_front();
469 continue;
470 }
471 }

Callers

nothing calls this directly

Calls 13

GetTickCount64Function · 0.85
Uint32_16toStringIP_PortFunction · 0.85
GetLastDNSSolveMethod · 0.80
RunMethod · 0.80
SetDNSErrorMethod · 0.80
SetLastDNSSolveMethod · 0.80
GetDNSErrorMethod · 0.80
GetServerByIPUDPMethod · 0.80
emptyMethod · 0.45
IsEmptyMethod · 0.45
GetServerByAddressMethod · 0.45
CreateMethod · 0.45

Tested by

no test coverage detected