Simple analysis of "C + +" "CPR" Remote Procedure call rpc__c++

Source: Internet
Author: User
Tags stub

One, what is remote procedure call

What is remote procedure call RPC (Sqlremote Procedure called)? You may be a little unfamiliar with this concept, and you may be very familiar with NFS, yes,
NFS is based on RPC. To understand the remote procedure call, let's look at the procedure call first.

A procedure call is the transfer of control from a process A to another process B, and the process B returns the control process to process a. Most systems currently
, both the caller and the callee are in a process in a given host system that is connected by the linker when the executable is generated, which is called
Called for a local procedure.

Remote Procedure Call (RPC) refers to a process on a local system that activates a process on a remote system, which we call the procedure invocation because it behaves as if the programmer
Called for a general procedure. There are two processes for processing remote procedure calls, one for the local client process and one for the remote server process. For local processes, remote
The process call displays this control of the client process, and then the client processes generate a message to the remote server via a network system call. Include process tuning in Network information
With the required parameters, the remote server invokes the process after receiving the message, then sends the result back to the client process over the network, and the client process returns the result to the calling
Process. Therefore, the remote system call behaves as a local procedure call to the caller, but it actually invokes the procedure on the remote system.


Second, remote procedure call model

Local procedure Call: A traditional program consists of one or more processes. They are often arranged according to a call level. As shown in the following illustration:


Remote Procedure Call: It uses the same abstraction as the traditional procedure, except that it allows the boundaries of a process to span two computers. As shown in the following illustration:


Iii. comparison of remote processes and local processes

First, network latency can make a remote process much more expensive than the local process
Second, the traditional procedure call can pass the pointer between procedures because the invoked procedure and the calling procedure run on the same memory space. The remote procedure does not enable
Pointer as a parameter because the remote procedure runs in a completely different address space from the caller.
Again, because a remote call cannot share the caller's environment, it cannot directly access the caller's I/O descriptor or operating system functionality.


Iv. Several versions of remote procedure calls
(1) Sun RPC (UDP, TCP)
(2) Xerox Courier (SPP)
(3) Apollo RPC (UDP, DDS)

Where Sun RPC can be used for connection-oriented or non-connection-oriented protocols; Xerox Courier is used only for connection-oriented protocols; Apollo RPC is used only for connectionless protocols


V. How to write a remote procedure call program

In order to rewrite a traditional program into an RPC program, we have to add some additional code to the program, called the stub process. We can imagine a
Traditional program, one of its processes is transferred to a remote machine. At one end of the remote procedure, the stub process replaces the caller. This stub implements a remote
All communication required by the process call. Because the stub uses the same interface as the original invocation, adding these stub procedures does not require changing the original call
Process, nor does it require you to change the original invoked procedure. As shown in the following illustration:

Turn from: http://www.cppblog.com/jb8164/default.html?page=2

thank him.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.