7 handle::handle(std::string m)
17 ScopedLock ml(&h->cl_mutex);
23 make_sockaddr(h->m.c_str(), &dstsock);
24 rpcc *cl = new rpcc(dstsock);
25 tprintf("handler_mgr::get_handle trying to bind...%s\n", h->m.c_str());
27 // Starting with lab 6, our test script assumes that the failure
28 // can be detected by paxos and rsm layer within few seconds. We have
29 // to set the timeout with a small value to support the assumption.
31 // Note: with RPC_LOSSY=5, your lab would failed to pass the tests of
32 // lab 6 and lab 7 because the rpc layer may delay your RPC request,
33 // and cause a time out failure. Please make sure RPC_LOSSY is set to 0.
34 ret = cl->bind(rpcc::to(1000));
36 tprintf("handle_mgr::get_handle bind failure! %s %d\n", h->m.c_str(), ret);
40 tprintf("handle_mgr::get_handle bind succeeded %s\n", h->m.c_str());
48 if (h) mgr.done_handle(h);
51 handle_mgr::handle_mgr()
53 VERIFY (pthread_mutex_init(&handle_mutex, NULL) == 0);
57 handle_mgr::get_handle(std::string m)
59 ScopedLock ml(&handle_mutex);
61 if (hmap.find(m) == hmap.end()) {
67 pthread_mutex_init(&h->cl_mutex, NULL);
69 } else if (!hmap[m]->del) {
77 handle_mgr::done_handle(struct hinfo *h)
79 ScopedLock ml(&handle_mutex);
81 if (h->refcnt == 0 && h->del)
82 delete_handle_wo(h->m);
86 handle_mgr::delete_handle(std::string m)
88 ScopedLock ml(&handle_mutex);
92 // Must be called with handle_mutex locked.
94 handle_mgr::delete_handle_wo(std::string m)
96 if (hmap.find(m) == hmap.end()) {
97 tprintf("handle_mgr::delete_handle_wo: cl %s isn't in cl list\n", m.c_str());
99 tprintf("handle_mgr::delete_handle_wo: cl %s refcnt %d\n", m.c_str(),
101 struct hinfo *h = hmap[m];
102 if (h->refcnt == 0) {
107 pthread_mutex_destroy(&h->cl_mutex);