Getting a Taste of Remote Procedure Calls

Resourceful Code Reuse — by Dmitry Zinoviev (19 / 20)

The Pragmatic Programmers
The Pragmatic Programmers

--

👈 Harnessing Dynamic Loading | TOC | Bibliography 👉

Remember the function read_json that you called over and over again directly and in different disguises? In this section, read_json is a part of another program on another computer, and you’ll still be able to call it. Welcome to the fantastic world of remote procedure calls. (By the way, for the rest of this book, assume that “procedure” is a synonym of “function.”)

Remote procedure calls take at most one parameter.

Remote procedure calls are fundamentally different from local procedure calls in two ways. First, the caller and the callee communicate via a network (typically, a UDP/IP network). Second, they don’t share the address space. The first difference limits the size of the parameter and return value (usually to 8 kB). The second difference prevents the use of pointers, which means that you should reconsider the way read_json behaves.

Let’s assume that read_json takes two parameters. The first is a file name. The second is a path to an element within the file (for example, a colon-separated character string of array indexes and object keys). As you’ll see shortly in ​RPC Basics​, a remote procedure can take only one parameter. It could be a struct or an array, but it’s much easier to create one parameter by joining the file name and the path, say, with another colon. For example, string…

--

--

The Pragmatic Programmers
The Pragmatic Programmers

We create timely, practical books and learning resources on classic and cutting-edge topics to help you practice your craft and accelerate your career.