Professional Documents
Culture Documents
Communication Between Process
Communication Between Process
Communication Between Process
Unstructured Communication
use shared memory or shared structure
Structured Communication
uses explicit messages (IPCs)
Layered Protocols (I)
2-8
Machine B
Machine A
Copy value a and contents of loc b
a into a’ and loc b’ a’
b Return Copy contents of loc b’ into b
b’
Client stub
Server 3. The client stub send this to the
stub
2 remote system (via TCP/UDP)
RPC RPC
4
runtime runtime 4. The server stub unmarshalls the call
and args from the client
Process Process
kernel kernel
5. The server stub calls the actual
3 6 procedure on the server
Network Network 6. The server stub marshalls the
routines routines
reply and sends it back to the client
p = message;
p = put_int(p, SETTIME);
p = put_int(p, t->seconds);
p = put_int(p, t->minutes);
p = put_int(p, t->hours);
p = put_int(p, t->day);
p = put_int(p, t->month);
p = put_int(p, t->year);
p = put_string(p, t->timezone, 4);
stat = do_operation(“time_server”, message, 32);
if(stat == SUCCESS) get_int(message, &stat);
return(stat);
}
Example1: Server Stub (1)
void main_loop() { p = get_int(p, &t.minutes);
char *p, message[32]; p = get_int(p, &t.hours);
int len, op_code; p = get_int(p, &t.day);
struct time t; p = get_int(p, &t.month);
p = get_int(p, &t.year);
for(;;) { p = get_string(p, &t.timezone, 4);
len = receive_request(message, 32); len = settime(&t);
if(len < 4) { put_int(message, len);
/* error handling code */ len = 4;
} break;
p = message; case GETTIME:
p = get_int(p, op_code);
switch(op_code) { /* code for unmarshalling and
case SETTIME: calling gettime */
if (len < 32) { }
/* error handling code */
} send_reply(message, len);
p = get_int(p, &t.seconds); }
Writing a Client
and a Server
2-12
2-13
/* interface.x */
/* Example Interface Definition */
struct square_in {
long arg;
};
struct square_out {
long result;
};
program SQUARE_PROG {
version SQUARE_VERS {
square_out SQUAREPROC( square_in ) = 1; /* Procedure number = 1 */
} = 1; /* Version number = 1 */
} = 0x31230000; /* program number */
interface.x
rpcgen
interface.h
Runtime lib
Client Server