Unformatted text preview:

1CS 417Programming withSUN RPCCS 417Distributed SystemsPaul KrzyzanowskiDigitally signed by Paul KrzyzanowskiDN: cn=Paul Krzyzanowski, o=Rutgers University, c=USDate: 2002.02.24 16:48:53 -05'00'Signature Not Verified2CS 417Remote Procedure Call• remote procedures appear local through stub functions• stub functions have the same functional interface– communicate with server– await results from serverclient codeclient stubmarshal paramssend to serverwait for responseunmarshal resultsreturn to clientserver stubserver functioncreate socketregister portaccept connectionsreceive messageunmarshal paramscall server functionmarshal returnsend back resultsinitialize connectionRemote procedure calls appear local because a local procedure exists that provides the same interface.This procedure gathers up the parameters and converts them into a flat, pointerlessrepresentation that is sent as a network message to a server. This data conversion is known as marshaling.N.B.: pointers are useless on the remote side since they refer to local memory locations.The server, upon receiving the message, reassembles the parameters into a form that is readable on that machine (correct byte ordering, word sizes, etc.) and calls the user-written server function. Upon return from the server function, any return value is marshaled into a network message and sent back to the client.The client receives the return message, unmarshals the data, and returns it back to the calling client code.3CS 417Stub function generation• Programming languages do not support Sun RPC.– A separate pre-compiler, rpcgen, must be used• Input:– Interface definition language• Output:– server main routine– client stub functions–header file– data conversion functions, if neededRPC is a language construct, meaning it is a property of the programming language (since it deals with the semantics of function calls).However, no languages support Sun RPC, so a pre-compiler must be used to generate the stub functions on the client and the server.The Sun RPC compiler is called rpcgen. As input, it takes a list of remote procedures (interfaces) defined in an interface definition language (IDL).The output from rpcgen is a set of files that include:server code: main function that sets up a socket, registers the port with a name server, listens for and accepts connections, receives messages, unmarshals parameters, calls the user-written server function, marshals the return value, and sends back a network message.client stub: code with the interface of the remote function that marshals parameters, sends the message to the server, and unmarshals the return valueheader: contains definitions of symbols used by client and server as well as function prototypesdata conversion functions: a separate file may be generated if special functions need to be called to convert between local data types and their marshaled forms.4CS 417Interface Definition Language• Used by rpcgen to generate stub functions• defines an RPC program: collection of RPC procedures• structure:type definitionsprogram identifier {version version_id {procedure list} = value;…} = value;program PROG {version PROG1 {void PROC_A(int) = 1;} = 1;} = 0x3a3afeeb;The Interface Definition Language (IDL) is the one bit of input needed by rpcgen to generate the stub functions.The structure of IDL is vaguely similar to a set of C prototype definitions.Note that any similarity to C is essentially coincidental: RPC IDL is a separate definition language that is not C.Each IDL program contains the following structure:- optional constant definitions and typedefs may be present- the entire interface is enveloped in a program block. The sample on the right gives a name PROG to the set of interfaces and a numeric value of 0x3a3afeeb. Sun decreed that each collection of RPC interfaces is identified by a 32 bit value that you have to select. The restrictions given are:0x00000000-0x1fffffff: defined by sun0x20000000-0x3fffffff defined by the user0x40000000-0x5fffffff transient processes0x60000000-0x7fffffff reserved- within the program block, one or more sets of versions may be defined. A client program will always request an interface by asking for a {program#, version#} tuple. Each version contains a version name and number. In the sample on the right, the version name is PROG1 and the number is 1.- within each version block, a set of functions is defined. These look similar to C prototypes and are tagged with a function number (each function gets a unique number within a version block).5CS 417Data types• constants– may be used in place of an integer value - converted to #define statement by rpcgenconst MAXSIZE = 512;• structures– similar to C structures - rpcgen transfers structure definition and adds a typedef for the name of the structurestruct intpair { int a, b };is translated to:struct intpair { int a, b };typedef struct intpair intpair;6CS 417Data types• enumerations– similar to Cenum state { BUSY=1, IDLE=2, TRANSIT=3 };• unions– not like C– a union is a specification of data types based on some criteria:union identifier switch (declaration) {case_list}– for example:const MAXBUF=30;union time_results switch (int status) {case 0: char timeval[MAXBUF];case 1: void;case 2: int reason;}enumerations- defines that state can have the value of one of the symbols: BUSY, IDLE, or TRANSIT. The symbols are defined to be the values 1, 2, and 3 respectively.unions- very different from C (similar to discriminated unions of Pascal or ADA)The example shows that the union has a field of status. If status is set to 0, then the union also has a character array called timeval. If status is set to 1, then the union has no other fields, and if status is set to 2, then the union has an integer field called reason.7CS 417Data types• type definitions–like C:typedef long counter;• arrays– like C but may have a fixed or variable length:int proc_hits[100];defines a fixed size array of 100 integers.long x_vals<50>defines a variable-size array of a maximum of 50 longs• pointers– like C, but nit sent over the network. What is sent is a boolean value (true for pointer, false for null) followed by the data to which the pointer points.8CS 417Data types• strings– declared as if they were variable length arraysstring name<50>;declares a string of at most 50 characters.string anyname<>;declares a string of any number of characters.• boolean– can have the


View Full Document

Rutgers University CS 417 - Programming with SUN RPC

Download Programming with SUN RPC
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Programming with SUN RPC and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Programming with SUN RPC 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?