Specifications
Page 20 Remote Procedure Call Programming Guide
Here is an example of a client that uses batching to render a bunch of strings; the batching is flushed when
the client gets a null string (EOF):
#include <stdio.h>
#include <rpc/rpc.h>
#include <sys/socket.h>
#include <sys/time.h>
#include <netdb.h>
#include <suntool/windows.h>
main(argc, argv)
int argc;
char **argv;
{
struct hostent *hp;
struct timeval pertry_timeout, total_timeout;
struct sockaddr_in server_addr;
int sock = RPC_ANYSOCK;
register CLIENT *client;
enum clnt_stat clnt_stat;
char buf[1000], *s = buf;
if ((client = clnttcp_create(&server_addr,
WINDOWPROG, WINDOWVERS, &sock, 0, 0)) == NULL) {
perror("clnttcp_create");
exit(-1);
}
total_timeout.tv_sec = 0;
total_timeout.tv_usec = 0;
while (scanf("%s", s) != EOF) {
clnt_stat = clnt_call(client, RENDERSTRING_BATCHED,
xdr_wrapstring, &s, NULL, NULL, total_timeout);
if (clnt_stat != RPC_SUCCESS) {
clnt_perror(client, "batched rpc");
exit(-1);
}
}
/* Now flush the pipeline */
total_timeout.tv_sec = 20;
clnt_stat = clnt_call(client, NULLPROC, xdr_void, NULL,
xdr_void, NULL, total_timeout);
if (clnt_stat != RPC_SUCCESS) {
clnt_perror(client, "rpc");
exit(-1);
}
clnt_destroy(client);
exit(0);
}
Since the server sends no message, the clients cannot be notified of any of the failures that may occur.
Therefore, clients are on their own when it comes to handling errors.
The above example was completed to render all of the (2000) lines in the file /etc/termcap. The rendering
service did nothing but throw the lines away. The example was run in the following four configurations: 1)
machine to itself, regular RPC; 2) machine to itself, batched RPC; 3) machine to another, regular RPC; and
4) machine to another, batched RPC. The results are as follows: 1) 50 seconds; 2) 16 seconds; 3) 52 sec-
onds; 4) 10 seconds. Running fscanf() on /etc/termcap only requires six seconds. These timings show the
advantage of protocols that allow for overlapped execution, though these protocols are often hard to design.