3 // This file defines a set of utility routines for RPC services.
10 #include <sys/types.h>
11 #include <sys/socket.h>
14 #include <rpc/types.h>
16 #include "util/h/rpcUtil.h"
18 int RPCdefaultXDRRead(int handle, char *buf, u_int len)
23 ret = read(handle, buf, len);
24 } while (ret < 0 && errno == EINTR);
26 if (ret <= 0) return(-1);
30 int RPCdefaultXDRWrite(int handle, char *buf, u_int len)
35 ret = write(handle, buf, len);
36 } while (ret < 0 && errno == EINTR);
42 // prepare for RPC's to be done/received on the passed fd.
44 XDRrpc::XDRrpc(int f, xdrIOFunc readRoutine, xdrIOFunc writeRoutine)
47 __xdrs__ = (XDR *) malloc(sizeof(XDR));
48 if (!readRoutine) readRoutine = RPCdefaultXDRRead;
49 if (!writeRoutine) writeRoutine = RPCdefaultXDRWrite;
50 (void) xdrrec_create(__xdrs__, 0, 0, (char *) fd, readRoutine,writeRoutine);
55 // prepare for RPC's to be done/received on the passed fd.
57 XDRrpc::XDRrpc(char *machine,
60 xdrIOFunc readRoutine,
61 xdrIOFunc writeRoutine)
63 fd = RPCprocessCreate(&pid, machine, user, program);
65 __xdrs__ = (XDR *) malloc(sizeof(XDR));
66 if (!readRoutine) readRoutine = RPCdefaultXDRRead;
67 if (!writeRoutine) writeRoutine = RPCdefaultXDRWrite;
68 (void) xdrrec_create(__xdrs__, 0, 0, (char *) fd,
69 readRoutine, writeRoutine);
77 // prepare for RPC's to be done/received on the passed thread id.
79 THREADrpc::THREADrpc(int thread)
85 // This should never be called, it should be replaced by a virtual function
86 // from the derived class created by igen.
88 void RPCUser::verifyProtocolAndVersion()
94 // our version of string encoding that does malloc as needed.
96 bool_t xdr_String(XDR *xdrs, String *str)
100 if (xdrs->x_op == XDR_ENCODE) {
101 len = strlen(*str)+1;
105 // should we have a better max length ???.
106 xdr_bytes(xdrs, str, &len, 65536*32768);
110 int RPCprocessCreate(int *pid, char *hostName, char *userName, char *command)
116 if (!hostName || !strcmp(hostName, "") || !strcmp(hostName, "localhost")) {
117 ret = socketpair(AF_UNIX, SOCK_STREAM, 0, sv);
118 if (ret) return(ret);
124 execl(command, command);
127 } else if (*pid > 0 && !execlERROR) {
134 // need to rsh to machine and setup io path.
135 printf("remote starts not implemented\n");
141 // wait for an expected RPC responce, but also handle upcalls while waiting.
142 // Should not be called directly !!!
144 void RPCUser::awaitResponce(int tag)