| 446 | } |
| 447 | |
| 448 | void StopHTTPServer() |
| 449 | { |
| 450 | LogPrint(BCLog::HTTP, "Stopping HTTP server\n"); |
| 451 | if (g_work_queue) { |
| 452 | LogPrint(BCLog::HTTP, "Waiting for HTTP worker threads to exit\n"); |
| 453 | for (auto& thread : g_thread_http_workers) { |
| 454 | thread.join(); |
| 455 | } |
| 456 | g_thread_http_workers.clear(); |
| 457 | } |
| 458 | // Unlisten sockets, these are what make the event loop running, which means |
| 459 | // that after this and all connections are closed the event loop will quit. |
| 460 | for (evhttp_bound_socket *socket : boundSockets) { |
| 461 | evhttp_del_accept_socket(eventHTTP, socket); |
| 462 | } |
| 463 | boundSockets.clear(); |
| 464 | if (eventBase) { |
| 465 | LogPrint(BCLog::HTTP, "Waiting for HTTP event thread to exit\n"); |
| 466 | if (g_thread_http.joinable()) g_thread_http.join(); |
| 467 | } |
| 468 | if (eventHTTP) { |
| 469 | evhttp_free(eventHTTP); |
| 470 | eventHTTP = nullptr; |
| 471 | } |
| 472 | if (eventBase) { |
| 473 | event_base_free(eventBase); |
| 474 | eventBase = nullptr; |
| 475 | } |
| 476 | g_work_queue.reset(); |
| 477 | LogPrint(BCLog::HTTP, "Stopped HTTP server\n"); |
| 478 | } |
| 479 | |
| 480 | struct event_base* EventBase() |
| 481 | { |