RPCs have been around for quite some time, and I never have got around to reading up about them. Then I read this article by Jeff Bezanson (glibc on Linux) which seemed a good place to start.
RPCs will execute your code on a remote machine without your needing to make network calls.
Client -> makes the call.
Server -> processes the call and executes whatever it is asked to do.
Passing pointers to data etc. is handled by XDR, which serializes the data before sending it across the network. Thus, even link lists can be sent across without your explicit intervention! This is done using an RPC compiler (rpcgen)
1. Create a file file.x which contains a description of the data, and the procedures that will be called remotely. Program_id (decided arbitrarily) and version_number must be specified – program_id will be used to setup port numbers, and version_number is used to check that clients are communicating with a server that understands the language (in case of backward/forward incompatibility)
2. Invoke rpcgen on file.x – this results in file.h, file_svc.c, file_xdr.c, file_clnt.c
file.h: contains declarations, function prototypes in C – read this!
file_svc.c to be linked with the server, file_clnt.c with the client, and file_xdr.c with both.
3. For the server, function prototypes ending in _svc are what we need to implement.
(Note: handle quirky result value – functions return pointer to return value)
4. In the client main(), call clnt_create() with hostname, program_id and version_number.
5. Then call your rpc, note: result will be a pointer.
6. Link everything together, fire the server and then the client!
Questions as yet unanswered:
1. If the result is a pointer, does this mean that the memory location where the result is stored will get overwritten by multiple rpc calls?
2. What about permissions? How are they handled? Can user A call a server running under user B? If User B has sudo access on the server, but user A does not, what happens. Basically, how are permissions handled?
Of course, this is not really a detailed description – it’s only meant to jog my memory. For a proper tutorial, refer to the original article.