| 412 | |
| 413 | |
| 414 | void 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 | } |
nothing calls this directly
no test coverage detected