X-Git-Url: http://xvm.mit.edu/gitweb/invirt/third/libt4.git/blobdiff_plain/5d99dbf06a14904944f5593c63705934bdfdcfb7..06282fd37814c4a9d53bca089b048709b368f5b3:/handle.h diff --git a/handle.h b/handle.h index d4b6223..e569002 100644 --- a/handle.h +++ b/handle.h @@ -1,60 +1,32 @@ -// manage a cache of RPC connections. -// assuming cid is a string holding the -// host:port of the RPC server you want -// to talk to: -// -// handle h(cid); -// rpcc *cl = h.safebind(); -// if(cl){ -// ret = cl->call(...); -// } else { -// bind() failed -// } -// -// if the calling program has not contacted -// cid before, safebind() will create a new -// connection, call bind(), and return -// an rpcc*, or 0 if bind() failed. if the -// program has previously contacted cid, -// safebind() just returns the previously -// created rpcc*. best not to hold any -// mutexes while calling safebind(). - #ifndef handle_h #define handle_h #include "types.h" #include "rpc/rpc.h" -class hinfo; +// Manage a cache of RPC connections. Typical usage: +// handle h(dst); +// rpc_protocol::status ret = rpc_protocol::bind_failure; +// if (rpcc *cl = h.safebind()) +// ret = cl->call(...); +// assuming dst is a string holding the host:port of the RPC server you want to +// talk to. +// +// If the calling program has not contacted dst before, safebind() will create +// a new connection, call bind(), and return an rpcc*, or 0 if bind() failed. +// if the program has previously contacted dst, safebind() just returns the +// previously created rpcc*. Because safebind() may block, callers should +// probably not hold mutexes. class handle { private: - hinfo *h; + shared_ptr h; + const string destination_; public: - handle(const string & m); - ~handle(); - /* safebind will try to bind with the rpc server on the first call. - * Since bind may block, the caller probably should not hold a mutex - * when calling safebind. - * - * return: - * if the first safebind succeeded, all later calls would return - * a rpcc object; otherwise, all later calls would return NULL. - * - * Example: - * handle h(dst); - * XXX_protocol::status ret; - * if (h.safebind()) { - * ret = h.safebind()->call(...); - * } - * if (!h.safebind() || ret != XXX_protocol::OK) { - * // handle failure - * } - */ + handle(const string & destination); rpcc *safebind(); + void invalidate(); + static void shutdown(); }; -void invalidate_handle(const string & m); - #endif