| 533 | } |
| 534 | |
| 535 | void Delete(HHttpService http_service) |
| 536 | { |
| 537 | dmMessage::URL url; |
| 538 | url.m_Socket = http_service->m_Socket; |
| 539 | dmMessage::Post(0, &url, 0, 0, (uintptr_t) dmHttpDDF::StopHttp::m_DDFDescriptor, 0, 0, 0); |
| 540 | |
| 541 | // Stop the balancer first, so we don't accept any new requests |
| 542 | dmThread::Join(http_service->m_Balancer); |
| 543 | |
| 544 | // Cancel them all first, as opposed to one-by-one |
| 545 | for (uint32_t i = 0; i < http_service->m_Workers.Size(); ++i) |
| 546 | { |
| 547 | dmHttpService::Worker* worker = http_service->m_Workers[i]; |
| 548 | |
| 549 | url.m_Socket = worker->m_Socket; |
| 550 | dmMessage::Post(0, &url, 0, 0, (uintptr_t) dmHttpDDF::StopHttp::m_DDFDescriptor, 0, 0, 0); |
| 551 | |
| 552 | worker->m_Canceled = 1; |
| 553 | } |
| 554 | |
| 555 | for (uint32_t i = 0; i < http_service->m_Workers.Size(); ++i) |
| 556 | { |
| 557 | dmHttpService::Worker* worker = http_service->m_Workers[i]; |
| 558 | |
| 559 | // DNS lookups using dmSocket::GetHostByName are using getaddrinfo which may block for an undefined |
| 560 | // amount of time. We do not wish to wait for the thread during shutdown |
| 561 | // We now use detach() on the thread on creation so that we don't have to wait for the thread |
| 562 | if (worker->m_Thread) |
| 563 | { |
| 564 | dmThread::Join(worker->m_Thread); |
| 565 | } |
| 566 | |
| 567 | dmMessage::DeleteSocket(worker->m_Socket); |
| 568 | if (worker->m_Client) |
| 569 | { |
| 570 | dmHttpClient::Delete(worker->m_Client); |
| 571 | } |
| 572 | delete worker; |
| 573 | } |
| 574 | |
| 575 | dmMessage::DeleteSocket(http_service->m_Socket); |
| 576 | delete http_service; |
| 577 | } |
| 578 | |
| 579 | } |