X-Git-Url: http://xvm.mit.edu/gitweb/invirt/third/libt4.git/blobdiff_plain/06282fd37814c4a9d53bca089b048709b368f5b3..869c0cc91d8f6b2bb80026616372d16450b64d9f:/rpc/rpc.cc diff --git a/rpc/rpc.cc b/rpc/rpc.cc index de33675..2889db9 100644 --- a/rpc/rpc.cc +++ b/rpc/rpc.cc @@ -85,7 +85,8 @@ rpcc::rpcc(const string & d) : dst_(make_sockaddr(d)) // IMPORTANT: destruction should happen only when no external threads // are blocked inside rpcc or will use rpcc in the future rpcc::~rpcc() { - cancel(); + lock ml(m_); + cancel(ml); IF_LEVEL(2) LOG << "delete nonce " << clt_nonce_ << " chan " << (chan_?(int)chan_->fd:-1); chan_.reset(); VERIFY(calls_.size() == 0); @@ -104,9 +105,29 @@ int rpcc::bind(milliseconds to) { return ret; } +shared_ptr rpcc::bind_cached(const string & destination) { + auto client = global->get_handle(destination); + lock cl = lock(client->bind_m_); + if (!client->bind_done_) { + LOG_NONMEMBER << "bind(\"" << destination << "\")"; + int ret = client->bind(milliseconds(1000)); + if (ret < 0) { + LOG_NONMEMBER << "bind failure! " << destination << " " << ret; + client.reset(); + } else { + LOG_NONMEMBER << "bind succeeded " << destination; + } + } + return client; +} + +void rpcc::unbind_cached(const string & destination) { + global->erase_handle(destination); +} + // Cancel all outstanding calls -void rpcc::cancel(void) { - lock ml(m_); +void rpcc::cancel(lock & m_lock) { + VERIFY(m_lock); if (calls_.size()) { LOG << "force callers to fail"; for (auto & p : calls_) { @@ -122,7 +143,7 @@ void rpcc::cancel(void) { destroy_wait_ = true; while (calls_.size () > 0) - destroy_wait_c_.wait(ml); + destroy_wait_c_.wait(m_lock); LOG << "done"; }