-handle::handle(std::string m)
-{
- h = mgr.get_handle(m);
-}
-
-rpcc *
-handle::safebind()
-{
- if (!h)
- return NULL;
- lock ml(h->cl_mutex);
- if (h->del)
- return NULL;
- if (h->cl)
- return h->cl;
- sockaddr_in dstsock;
- make_sockaddr(h->m.c_str(), &dstsock);
- rpcc *cl = new rpcc(dstsock);
- tprintf("handler_mgr::get_handle trying to bind...%s\n", h->m.c_str());
- int ret;
- // Starting with lab 6, our 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.
- //
- // Note: with RPC_LOSSY=5, your lab would failed to pass the tests of
- // lab 6 and lab 7 because the rpc layer may delay your RPC request,
- // and cause a time out failure. Please make sure RPC_LOSSY is set to 0.
- ret = cl->bind(rpcc::to(1000));
- if (ret < 0) {
- tprintf("handle_mgr::get_handle bind failure! %s %d\n", h->m.c_str(), ret);
- delete cl;
- h->del = true;
- } else {
- tprintf("handle_mgr::get_handle bind succeeded %s\n", h->m.c_str());
- h->cl = cl;
- }
- return h->cl;
-}
-
-handle::~handle()
-{
- if (h) mgr.done_handle(h);
-}