| 402 | } |
| 403 | |
| 404 | std::pair<int, std::string> fetchLocalShards(const std::string& host, uint16_t port, Duration timeout, std::array<ShardInfo, 256>& shards) { |
| 405 | const auto [sock, errStr] = registrySock(host, port, timeout); |
| 406 | if (sock.error()) { |
| 407 | return {sock.getErrno(), errStr}; |
| 408 | } |
| 409 | |
| 410 | RegistryReqContainer reqContainer; |
| 411 | reqContainer.setLocalShards(); |
| 412 | { |
| 413 | const auto [err, errStr] = writeRegistryRequest(sock.get(), reqContainer, timeout); |
| 414 | if (err) { return {err, errStr}; } |
| 415 | } |
| 416 | |
| 417 | RegistryRespContainer respContainer; |
| 418 | { |
| 419 | const auto [err, errStr] = readRegistryResponse(sock.get(), respContainer, timeout); |
| 420 | if (err) { return {err, errStr}; } |
| 421 | } |
| 422 | if (respContainer.getLocalShards().shards.els.size() != shards.size()) { |
| 423 | throw TERN_EXCEPTION("expecting %s shards, got %s", shards.size(), respContainer.getLocalShards().shards.els.size()); |
| 424 | } |
| 425 | for (int i = 0; i < shards.size(); i++) { |
| 426 | shards[i] = respContainer.getLocalShards().shards.els[i]; |
| 427 | } |
| 428 | |
| 429 | return {}; |
| 430 | } |
| 431 | |
| 432 | bool parseRegistryAddress(const std::string& fullRegistryAddress, std::string& registryHost, uint16_t& registryPort) { |
| 433 | // split host:port |
no test coverage detected