C.4. Some RPC Examples

In the examples below, each set of entries in an RPC .x file is followed by a sequence of statements in gray, which are those produced by the rpcgen compiler.

/*
 ***************** const *********************
 */
const MAX = 1024;
const DELIMITER = "@";
/* is converted to: */

#define MAX 1024


<-- 1


#define DELIMITER "@"

/*
 **************** enum **********************
 */
enum primary { red, yellow = 4, blue };
/* is converted to: */

enum primary {


<-- 2


red = 0,


yellow = 4,


blue = 4 + 1


};

typedef enum primary primary;
/*
 **************** typedef ********************/
typedef colors strange; /* simple */
typedef char line[80]; /* fixed length array */
typedef string var_line<80>; /* variable len array with max */
typedef int some_ints< >; /* variable len array - NO max */
typedef var_line *line_ptr; /* pointer */
/* is converted to: */

typedef colors strange;


<-- 3


typedef char line[80];


typedef char *var_line;


typedef struct {


u_int some_ints

_len

;


int *some_ints

_val

;


} some_ints;


typedef var_line *line_ptr;

/*
 **************** struct **********************
 */
struct record {
 var_line name;
 int age;
};
/* is converted to: */

struct record {


<-- 4


var_line name;


int age;


};


typedef struct record record;

/*
 **************** union **********************
*/
union ret_value switch( extern errno ) {
case 0:
 line answer;
default:
 void;
};
/* is converted to: */

struct ret_value {


<-- 5


extern errno;


union {


line answer;


} ret_value_u;


};


typedef struct ret_value ret_value;

(1) The equal sign and semicolon are removed, and const is replaced with #define

(2) Notice how the assignment of each color is handled. The duplicate use of primary is acceptable, as the C/C++ compiler stores these identifiers in a different namespace.

(3) The variable length array is mapped to a structure with two members. The first stores the number of elements in the array. The second references the base address of the array. Note how the members are named incorporating the base name of the array.

(4) This conversion is pretty much what one would expect. Again, because of namespace, there is no conflict with using record twice in the typedef .

(5) The union is mapped to a structure containing a reference to the externally declared errno value and a union whose element is the larger (storage-wise) of the initially listed members.

Programs and Processes

Processing Environment

Using Processes

Primitive Communications

Pipes

Message Queues

Semaphores

Shared Memory

Remote Procedure Calls

Sockets

Threads

Appendix A. Using Linux Manual Pages

Appendix B. UNIX Error Messages

Appendix C. RPC Syntax Diagrams

Appendix D. Profiling Programs



Interprocess Communication in Linux
Interprocess Communications in Linux: The Nooks and Crannies
ISBN: 0130460427
EAN: 2147483647
Year: 2001
Pages: 136

Flylib.com © 2008-2020.
If you may any questions please contact us: flylib@qtcs.net