PreviousNext

Nested Calls and Callbacks

A called remote procedure can call another remote procedure. The call to the second remote procedure is nested within the first call; that is, the second call is a nested remote procedure call. A nested call involves the following general phases, as illustrated in the following figure:

1. A client makes an initial remote procedure call to the first remote procedure.

2. The first remote procedure makes a nested call to the second remote procedure.

3. The second remote procedure executes the nested call and returns it to the first remote procedure.

4. The first remote procedure then resumes executing the initial call.


Phases of a Nested RPC Call

A specialized form of a nested remote procedure call involves a called remote procedure that is making a remote procedure call (callback) to the address space of the calling client application thread. Calling the client's address space requires that a server application thread be listening in that address space. Also, the second remote procedure needs a server binding handle for the address space of the calling client.

The remote procedure can ask the local RPC runtime to convert the client binding handle, provided by the server runtime, into a server binding handle. This is done by calling the rpc_binding_server_from_client( ) routine. This routine returns a partially bound binding handle (the server binding information lacks an endpoint). For a nested remote procedure call to find the address space of the calling client, the application must ensure that the partially bound binding handle is filled in with the endpoint of that address space. The rpc_binding_server_from_client(3rpc) reference page discusses alternatives for ensuring that the endpoint is obtainable for a nested remote procedure call.

Using the server binding handle, a remote procedure can attempt a nested remote procedure call. The nested call involves the general phases illustrated by the following figure.


Phases of a Nested RPC Call to Client Address Space

The application threads in the preceding figure are performing the following activities:

1. A client application thread from a multithreaded RPC application makes an initial remote procedure call to the first remote procedure.

2. After converting the client binding handle into a server binding handle and obtaining the endpoint for the address space of the calling client application thread, the first remote procedure makes a nested call to the second remote procedure at that address space.

3. The second remote procedure executes the nested call and returns it to the first remote procedure.

4. The first remote procedure then resumes executing the initial call (the client).