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>
17 #include "util/h/rpcUtil.h"
19 int RPCdefaultXDRRead(int handle, char *buf, u_int len)
24 ret = read(handle, buf, len);
25 } while (ret < 0 && errno == EINTR);
27 if (ret <= 0) return(-1);
31 int RPCdefaultXDRWrite(int handle, char *buf, u_int len)
36 ret = write(handle, buf, len);
37 } while (ret < 0 && errno == EINTR);
43 // prepare for RPC's to be done/received on the passed fd.
45 XDRrpc::XDRrpc(int f, xdrIOFunc readRoutine, xdrIOFunc writeRoutine)
48 __xdrs__ = (XDR *) malloc(sizeof(XDR));
49 if (!readRoutine) readRoutine = RPCdefaultXDRRead;
50 if (!writeRoutine) writeRoutine = RPCdefaultXDRWrite;
51 (void) xdrrec_create(__xdrs__, 0, 0, (char *) fd, readRoutine,writeRoutine);
56 // prepare for RPC's to be done/received on the passed fd.
58 XDRrpc::XDRrpc(char *machine,
61 xdrIOFunc readRoutine,
62 xdrIOFunc writeRoutine)
64 fd = RPCprocessCreate(machine, user, program);
66 __xdrs__ = (XDR *) malloc(sizeof(XDR));
67 if (!readRoutine) readRoutine = RPCdefaultXDRRead;
68 if (!writeRoutine) writeRoutine = RPCdefaultXDRWrite;
69 (void) xdrrec_create(__xdrs__, 0, 0, (char *) fd,
70 readRoutine, writeRoutine);
78 // prepare for RPC's to be done/received on the passed thread id.
80 THREADrpc::THREADrpc(int thread)
86 // This should never be called, it should be replaced by a virtual function
87 // from the derived class created by igen.
89 void RPCUser::verifyProtocolAndVersion()
95 // our version of string encoding that does malloc as needed.
97 bool_t xdr_String(XDR *xdrs, String *str)
101 if (xdrs->x_op == XDR_ENCODE) {
106 // should we have a better max length ???.
107 xdr_bytes(xdrs, str, &len, 65536*32768);
111 int RPCprocessCreate(char *hostName, char *userName, char *command)
118 if (!hostName || !strcmp(hostName, "") || !strcmp(hostName, "localhost")) {
119 ret = socketpair(AF_UNIX, SOCK_STREAM, 0, sv);
120 if (ret) return(ret);
126 execl(command, command);
129 } else if (pid > 0 && !execlERROR) {
136 // need to rsh to machine and setup io path.
137 printf("remote starts not implemented\n");
143 // wait for an expected RPC responce, but also handle upcalls while waiting.
144 // Should not be called directly !!!
146 void RPCUser::awaitResponce(int tag)