OSF DCE Application Development Guide--Core Components
Topics in RPC Application Development
CATCH_ALL
display_message("Stock quote not currently available");
ENDTRY
This example assumes that update_a_quote( ) eventually calls the remote operation
query_stock_quote() and that this call may raise an exception that is detected and
reported here.
The advantage of using exceptions in this case is that all of the work done in
update_a_quote( ) has the same error recovery and it does not need to be repeated at
every call to a remote operation. Another advantage is that, if one of the remote
operations does have a recovery for one exception, it can handle that one exception and
allow the rest to propagate to the more general handler in an outer layer of the code.
16.3 Context Handles
During a series of remote procedure calls, the client may need to refer to a context
maintained by a specific server instance. Server application code can maintain
information it needs for a particular client (such as the state of RPC the client is using) as
a context. To provide a client with a means of referring to its context, the client and
server pass back and forth an RPC-specific parameter called a context handle. A context
handle is a reference (a pointer) to the server instance and the context of a particular
client. A context handle ensures that subsequent remote procedure calls from the client
can reach the server instance that is maintaining context for the client.
On completing the first procedure in a series, the server passes a context handle to the
client. The context handle identifies the context that the server uses for subsequent
operations. The client is not supposed to do anything with the context handle; it merely
passes it to subsequent calls as needed, and it is used internally by the remote calls. This
allows applications to have such things as remote calls that handle file operations much
as local calls would; that is, a client application can remotely open a file, get back a
handle to it, and then perform various other remote operations on it, passing the context
handle as an argument to the calls. A context handle can be used across interfaces
(where a single server offers the multiple interfaces), but a context handle belongs only
to the client that caused it to be activated.
The server maintains the context for a client until the client calls a remote procedure that
terminates use of the context or communications are lost. In the latter case, the server’s
runtime can invoke a context rundown procedure. This application-specific routine is
called by the server stub automatically to reclaim (rundown) the pointed-to resource in
the event of a communications break between the server and client. For example, in the
case of the remote file pointer just mentioned, the context rundown routine would simply
close the file.
As usual with RPC, you need to apply indirection operators in a variety of ways to
maintain the correct [in] and [out] semantics. Typical declarations for a context handle
are as follows. In the .idl file, declare a named type such as
typedef [context_handle] void* my_handle_t;
124245 Tandem Computers Incorporated 16− 11