RPC -WR5441 Dokumentacja

Przeglądaj online lub pobierz Dokumentacja dla Nie RPC -WR5441. RPC -WR5441 Specifications Instrukcja obsługi

  • Pobierz
  • Dodaj do moich podręczników
  • Drukuj
  • Strona
    / 34
  • Spis treści
  • BOOKMARKI
  • Oceniono. / 5. Na podstawie oceny klientów
Przeglądanie stron 0
Remote Procedure Call Programming Guide
This document assumes a working knowledge of network theory. It is intended for programmers who wish
to write network applications using remote procedure calls (explained below), and who want to understand
the RPC mechanisms usually hidden by the rpcgen(1) protocol compiler. rpcgen is described in detail in
the previous chapter, the rpcgen Programming Guide.
Note: Before attempting to write a network application, or to convert an existing non-network application
to run over the network, you may want to understand the material in this chapter. However, for most appli-
cations, you can circumvent the need to cope with the details presented here by using rpcgen. The Generat-
ing XDR Routines section of that chapter contains the complete source for a working RPC service—a
remote directory listing service which uses rpcgen to generate XDR routines as well as client and server
stubs.
What are remote procedure calls? Simply put, they are the high-level communications paradigm used in
the operating system. RPC presumes the existence of low-level networking mechanisms (such as TCP/IP
and UDP/IP), and upon them it implements a logical client to server communications system designed
specifically for the support of network applications. With RPC, the client makes a procedure call to send a
data packet to the server. When the packet arrives, the server calls a dispatch routine, performs whatever
service is requested, sends back the reply, and the procedure call returns to the client.
1. Layers of RPC
The RPC interface can be seen as being divided into three layers.
1
The Highest Layer: The highest layer is totally transparent to the operating system, machine and network
upon which is is run. It’s probably best to think of this level as a way of using RPC, rather than as a part of
RPC proper. Programmers who write RPC routines should (almost) always make this layer available to
others by way of a simple C front end that entirely hides the networking.
To illustrate, at this level a program can simply make a call to rnusers(), a C routine which returns the num-
ber of users on a remote machine. The user is not explicitly aware of using RPC — they simply call a pro-
cedure, just as they would call malloc().
The Middle Layer: The middle layer is really “RPC proper. Here, the user doesn’t need to consider details
about sockets, the UNIX system, or other low-level implementation mechanisms. They simply make
remote procedure calls to routines on other machines. The selling point here is simplicity. It’s this layer
that allows RPC to pass the “hello world” test — simple things should be simple. The middle-layer rou-
tines are used for most applications.
RPC calls are made with the system routines registerrpc() callrpc() and svc_run(). The first two of these
are the most fundamental: registerrpc() obtains a unique system-wide procedure-identification number, and
callrpc() actually executes a remote procedure call. At the middle level, a call to rnusers() is implemented
by way of these two routines.
The middle layer is unfortunately rarely used in serious programming due to its inflexibility (simplicity). It
does not allow timeout specifications or the choice of transport. It allows no UNIX process control or flexi-
bility in case of errors. It doesn’t support multiple kinds of call authentication. The programmer rarely
needs all these kinds of control, but one or two of them is often necessary.
The Lowest Layer: The lowest layer does allow these details to be controlled by the programmer, and for
that reason it is often necessary. Programs written at this level are also most efficient, but this is rarely a
real issue — since RPC clients and servers rarely generate heavy network loads.
Although this document only discusses the interface to C, remote procedure calls can be made from any
language. Even though this document discusses RPC when it is used to communicate between processes
on different machines, it works just as well for communication between different processes on the same
machine.
1
For a complete specification of the routines in the remote procedure call Library, see the rpc(3N) manual
page.
-1-
Przeglądanie stron 0
1 2 3 4 5 6 ... 33 34

Podsumowanie treści

Strona 1

Remote Procedure Call Programming GuideThis document assumes a working knowledge of network theory. It is intended for programmers who wishto write ne

Strona 2

Page 10 Remote Procedure Call Programming Guide3.1. More on the Server SideThe server for the nusers() program shown below does the same thing as the

Strona 3

Remote Procedure Call Programming Guide Page 11First, the server gets a transport handle, which is used for receiving and replying to RPC messages. re

Strona 4

Page 12 Remote Procedure Call Programming GuideThe relevant routine is svc_getargs() which takes an SVCXPRT handle, the XDR routine, and a pointer tow

Strona 5

Remote Procedure Call Programming Guide Page 13simple examples like those in this section, a user doesn’t hav e to worry about the three modes. See th

Strona 6

Page 14 Remote Procedure Call Programming Guide3.3. The Calling SideWhen you use callrpc() you have no control over the RPC delivery mechanism or the

Strona 7

Remote Procedure Call Programming Guide Page 15argument, a pointer to the argument, the XDR routine for deserializing the return value, a pointer to w

Strona 8

Page 16 Remote Procedure Call Programming Guide4. Other RPC FeaturesThis section discusses some other aspects of RPC that are occasionally useful.4.1.

Strona 9

Remote Procedure Call Programming Guide Page 174.2.1. Broadcast RPC Synopsis#include <rpc/pmap_clnt.h>...enum clnt_stat clnt_stat;...clnt_stat

Strona 10

Page 18 Remote Procedure Call Programming Guide#include <stdio.h>#include <rpc/rpc.h>#include <suntool/windows.h>void windowdispatch

Strona 11

Remote Procedure Call Programming Guide Page 19fprintf(stderr, "can’t decode arguments\n");/** We are silent in the face of protocol errors*

Strona 12

Page 2 Remote Procedure Call Programming Guide1.1. The RPC ParadigmHere is a diagram of the RPC paradigm:Figure 1-1 Network Communication with the Rem

Strona 13

Page 20 Remote Procedure Call Programming GuideHere is an example of a client that uses batching to render a bunch of strings; the batching is flushed

Strona 14

Remote Procedure Call Programming Guide Page 214.4. AuthenticationIn the examples presented so far, the caller never identified itself to the server, a

Strona 15

Page 22 Remote Procedure Call Programming Guide/** An RPC Service request*/struct svc_req {u_long rq_prog; /* service program number */u_long rq_vers;

Strona 16

Remote Procedure Call Programming Guide Page 23nuser(rqstp, transp)struct svc_req *rqstp;SVCXPRT *transp;{struct authunix_parms *unix_cred;int uid;uns

Strona 17

Page 24 Remote Procedure Call Programming Guidecall the service primitive svcerr_systemerr() instead.The last point underscores the relation between t

Strona 18

Remote Procedure Call Programming Guide Page 25The final argument to authdes_create() is the address of a DES encryption key to use for encrypting time

Strona 19

Page 26 Remote Procedure Call Programming Guide4.6. Using InetdAn RPC server can be started from inetd The only difference from the usual code is that

Strona 20

Remote Procedure Call Programming Guide Page 27nuser(rqstp, transp)struct svc_req *rqstp;SVCXPRT *transp;{unsigned long nusers;unsigned short nusers2;

Strona 21

Page 28 Remote Procedure Call Programming Guide5.2. TCPHere is an example that is essentially rcp. The initiator of the RPC snd call takes its standar

Strona 22

Remote Procedure Call Programming Guide Page 29/** The sender routines*/#include <stdio.h>#include <netdb.h>#include <rpc/rpc.h>#inc

Strona 23

Remote Procedure Call Programming Guide Page 32. Higher Layers of RPC2.1. Highest LayerImagine you’re writing a program that needs to know how many u

Strona 24

Page 30 Remote Procedure Call Programming Guidereturn (int)clnt_stat;}/** The receiving routines*/#include <stdio.h>#include <rpc/rpc.h>ma

Strona 25

Remote Procedure Call Programming Guide Page 315.3. Callback ProceduresOccasionally, it is useful to have a server become a client, and make an RPC ca

Strona 26

Page 32 Remote Procedure Call Programming Guide#include <stdio.h>#include <rpc/rpc.h>#include <sys/socket.h>gettransient(proto, vers

Strona 27

Remote Procedure Call Programming Guide Page 33The following pair of programs illustrate how to use the gettransient() routine. The client makes an R

Strona 28

Page 34 Remote Procedure Call Programming Guidefprintf(stderr, "client got callback\n");if (!svc_sendreply(transp, xdr_void, 0)) {fprintf(st

Strona 29

Page 4 Remote Procedure Call Programming Guide2.2. Intermediate LayerThe simplest interface, which explicitly makes RPC calls, uses the functions call

Strona 30

Remote Procedure Call Programming Guide Page 5discussed later in this document. The remote server procedure corresponding to the above might look like

Strona 31

Page 6 Remote Procedure Call Programming Guide2.3. Assigning Program NumbersProgram numbers are assigned in groups of 0x20000000 according to the foll

Strona 32

Remote Procedure Call Programming Guide Page 7RPC Number Program Description100020 LOCKPROG local lock manager100021 NETLOCKPROG network lock manager

Strona 33

Page 8 Remote Procedure Call Programming Guidethen you would call callrpc() ascallrpc(hostname, PROGNUM, VERSNUM, PROCNUM,xdr_simple, &simple ...)

Strona 34

Remote Procedure Call Programming Guide Page 9If the size of the array is known in advance, one can use xdr_vector(), which serializes fixed-length arr

Komentarze do niniejszej Instrukcji

Brak uwag