- if (h->cl)
- return h->cl;
- rpcc *cl = new rpcc(h->m);
- LOG("trying to bind..." << h->m);
- // The test script assumes that the failure can be detected by paxos and
- // rsm layer within few seconds. We have to set the timeout with a small
- // value to support the assumption.
- //
- // With RPC_LOSSY=5, tests may fail due to delays and time outs.
- int ret = cl->bind(milliseconds(1000));
- if (ret < 0) {
- LOG("bind failure! " << h->m << " " << ret);
- delete cl;
- h->del = true;
- } else {
- LOG("bind succeeded " << h->m);
- h->cl = cl;
- }
- return h->cl;
-}
-
-handle::~handle() {
- if (h) mgr.release_handle(h);
-}
-
-hinfo * handle_mgr::acquire_handle(string m) {
- lock ml(mgr_mutex);
- hinfo *h = nullptr;
- if (hmap.find(m) == hmap.end()) {
- h = new hinfo(m);
- hmap[m] = h;
- h->refcnt++;
- } else if (!hmap[m]->del) {
- h = hmap[m];
- h->refcnt++;
+ if (!h->client) {
+ unique_ptr<rpcc> client(new rpcc(h->destination));
+ LOG("bind(\"" << h->destination << "\")");
+ int ret = client->bind(milliseconds(1000));
+ if (ret < 0) {
+ LOG("bind failure! " << h->destination << " " << ret);
+ h->valid = false;
+ } else {
+ LOG("bind succeeded " << h->destination);
+ h->client = move(client);
+ }