|
nanoMMO 0.97.8
Building an MMO: The Engineering Series
|
#include <world_list.h>
Public Types | |
| using | Clock = std::chrono::steady_clock |
| using | Fetch = std::function<absl::StatusOr<std::vector<ListedWorld>>()> |
Public Member Functions | |
| WorldList (asio::io_context &io, Fetch fetch) | |
| WorldList (const WorldList &)=delete | |
| WorldList & | operator= (const WorldList &)=delete |
| ~WorldList () | |
| Destroy it once the io_context has stopped. | |
| void | Start () |
| Asks for the list now, and every second after. | |
| void | Take (absl::StatusOr< std::vector< ListedWorld > > worlds, Clock::time_point at) |
| absl::StatusOr< std::string > | Find (std::string_view public_host, uint16_t port, Clock::time_point now) const |
Static Public Attributes | |
| static constexpr std::chrono::seconds | kStale {10} |
| A list this old says nothing about now, so every world is refused. | |
The worlds Consul lists, which the gateway may connect pages to. Asking Consul waits on the network, so it's done on a thread of its own, once a second, and the list it brings back is read and changed on the io_context's thread alone, where the gateway runs: a page's route never waits for Consul.
Definition at line 32 of file world_list.h.
| using nanommo::WorldList::Clock = std::chrono::steady_clock |
Definition at line 34 of file world_list.h.
| using nanommo::WorldList::Fetch = std::function<absl::StatusOr<std::vector<ListedWorld>>()> |
Definition at line 35 of file world_list.h.
| nanommo::WorldList::WorldList | ( | asio::io_context & | io, |
| Fetch | fetch ) |
Definition at line 15 of file world_list.cc.
|
delete |
| nanommo::WorldList::~WorldList | ( | ) |
Destroy it once the io_context has stopped.
Definition at line 18 of file world_list.cc.
| absl::StatusOr< std::string > nanommo::WorldList::Find | ( | std::string_view | public_host, |
| uint16_t | port, | ||
| Clock::time_point | now ) const |
The world's own address: NotFound when it isn't on the list, and Unavailable when there's no list newer than kStale.
Definition at line 59 of file world_list.cc.
| void nanommo::WorldList::Start | ( | ) |
Asks for the list now, and every second after.
Definition at line 23 of file world_list.cc.
| void nanommo::WorldList::Take | ( | absl::StatusOr< std::vector< ListedWorld > > | worlds, |
| Clock::time_point | at ) |
A list that came back at the time, on the io_context's thread. An error keeps the list from before, which grows stale.
Definition at line 48 of file world_list.cc.
|
staticconstexpr |
A list this old says nothing about now, so every world is refused.
Definition at line 38 of file world_list.h.