This file documents a C++ interface to Sun remote procedure calls.

Copyright © 1992 Michael N. Lipp Permission is granted to make and distribute verbatim copies of this manual provided the copyright notice and this permission notice are preserved on all copies.

Permission is granted to copy and distribute modified versions of this manual under the conditions for verbatim copying, provided also that the section entitled ``GNU Library General Public License'' is included exactly as in the original, and provided that the entire resulting derived work is distributed under the terms of a permission notice identical to this one.

Permission is granted to copy and distribute translations of this manual into another language, under the above conditions for modified versions, except that the section entitled ``GNU Library General Public License'' and this permission notice may be included in translations approved by the Free Software Foundation instead of in the original English.

Overview
********

This document describes my C++ interface to Sun Remote Procedure Calls. It is based on sources from Peter Bersen that I got from some newsgroup, though I don't remember which one. I liked the basic idea but disliked several aspects of the interface details. So I adapted it to my likes. I intended some minor changes but soon found myself renaming classes, changing method parameters, introducing new classes, etc. The result is by no way compatible with the original version. It is, I hope, nevertheless useful.

Basically, the interface defines six class: XdrInfo, RpcRequest, RpcCallback/RpcMethodCall, RpcService and RpcStub.

XdrInfo objects describe the external data representation of a type. There are predefined XdrInfos for the basic types. RpcRequest objects describe the available procedure calls. They are constructed from a unique request number, the XdrInfos of the procedure's arguments and its return type. RpcCallback is an object that holds a pointer to a function and information about the number of its arguments. RpcMethodCall is a template that in a similar way holds a pointer to an object and one of its methods and Information about the number of its arguments.

An RpcRequest and its matching RpcCallback or RpcMethodCall may be registered with an RpcService. Exactly one object of type RpcService may be instantiated in a program that implements an RPC server. Method Provide () is a loop that waits for requests and dispatches them.

A client program instantiates an object of type RpcStub.  The constructor establishes a connection to the server specified by its arguments. Procedures of the server may be invoked using method Call (...).

Installation
************

The rpc++ library has successfully been tested using a patched gcc-2.2.2 on a SparcStation running SunOS 4.1.[12] and a 386 system running Interactive Unix (a SYSV 3.2). Patching gcc-2.2.2 was necessary because the unpatched version can't handle typedefs that are local to templates. The bug report with patches can be found in the source directory in file gcc-2.2.2.fix.

As a prerequisite to using RPCs with C++ you need ANSI-C/C++ conformant header files for RPC. I have provided such files in the directory StdHdrs/rpc of the source tree. To avoid any copyright conflicts, they are derived from the public available RPC source code rather than from the files that come with SunOS 4.1.X. The differences are minor. The SunOS 4.1.X files define some additional functions. You have to either copy the files from StdHdrs/rpc or patched files from your /usr/include/rpc to a directory where gcc can find them. If you don't want to install them globally in gcc's include directory, you can include them by using an additional ``-I'' flag during compilation.

In SunOS you can simply type `make install INSTROOT=...' which will make the library and install it in INSTROOT/lib and the header files in INSTROOT/include/rpc++.  Other Unices will probably have problems with the `install' command. Type only `make' and copy the resulting librpc++.a to your local library directory and the files rpc++/* to an rpc++-subdirectory of your local include directory.

The classes
***********

XdrInfo
=======

Declared in: "rpc++/xdr++.h"

 -- Class: XdrInfo
     Class XdrInfo describes serializers. It combines the xdrproc_t with the size info (the size of the data to be converted) usually needed if you want to apply a serializer.

There is only one constructor for XdrInfo:

 -- Constructor: XdrInfo (xdrproc_t T, size_t S)
     Construct an XdrInfo for a type. The type can be converted to an external data representation (serielized) with function T. Its size (in bytes, from sizeof (type)), is S.

The methods query the information given to the constructor:

 -- Method: xdrproc_t Proc () const
     Return the conversion function stored in an XdrInfo.

 -- Method: size_t Size () const
     Return the size of the type described by the XdrInfo.

There are a number of predefined XdrInfos. They are defined as static members of a class Xdr for scoping reasons.

 -- XdrInfo: Xdr::Xchar
     The conversion and size information for a character.

 -- XdrInfo: Xdr::Xshort
     The conversion and size information for a short integer.

 -- XdrInfo: Xdr::Xint
     The conversion and size information for an integer.

 -- XdrInfo: Xdr::Xlong
     The conversion and size information for a long integer.

 -- XdrInfo: Xdr::Xuchar
     The conversion and size information for an unsigned character.

 -- XdrInfo: Xdr::Xushort
     The conversion and size information for an unsigned short integer.

 -- XdrInfo: Xdr::Xulong
     The conversion and size information for an unsigned long integer.

 -- XdrInfo: Xdr::Xfloat
     The conversion and size information for a float.

 -- XdrInfo: Xdr::Xdouble
     The conversion and size information for a double.

 -- XdrInfo: Xdr::Xenum_t
     The conversion and size information for any enumeration type.

 -- XdrInfo: Xdr::Xbool_t
     The conversion and size information for a bool.

 -- XdrInfo: Xdr::Xvoid
     A special XdrInfo for the return type of a procedure that returns nothing.

 -- XdrInfo: Xdr::Xnull
     A special XdrInfo for the return type of a procedure that is to be executed batched or asynchronously (see RpcRequest).

RpcRequest
==========

Declared in: "rpc++/request.h"

 -- Class: RpcRequest
     RpcRequest is a class that specifies a request for a procedure that is part of (registered with) a service.

There are several constructors for RpcRequest. They vary in the number of XdrInfos used to describe the input parameters of the procedure.

 -- Constructor: RpcRequest (u_long REQID, const XdrInfo* OUT, ReqType T=normal)

 -- Constructor: RpcRequest (u_long REQID, const XdrInfo* OUT, const XdrInfo* IN1, ReqType T=normal)

 -- Constructor: RpcRequest (u_long REQID, const XdrInfo* OUT, const XdrInfo* IN1, const XdrInfo* IN2, ReqType T=normal)
     These constructors construct an RpcRequest for a procedure with zero, one or two arguments. Additional similar constructors are defined for procedures with up to seven arguments. REQID uniquely identifies the request (the procedure of the server). REQID may not be 0. The XdrInfo*s following REQID specify the types of the input parameters. They are followed by the XdrInfo* that describes the type of the value returned by the RPC. If no value is returned, &Xdr::Xvoid must be given as argument (see XdrInfo). The final optional argument T specifies the call mode: RpcRequest::normal, RpcRequest::batched or RpcRequest::async (see below).

 -- Constructor: RpcRequest (u_long REQID, const XdrInfo* OUT, const XdrInfo** INTYPES, ReqType T=normal)
     This constructor can be used to construct an RpcRequest with an arbitrary number of arguments. The pointers to XdrInfo are passed in an array. The number of elements in the array must be one more than the number of parameters and the last element must be zero.

If the request type T is RpcRequest::normal, method Call (see RpcStub) assembles the message to the server, sends it, waits for a reply and returns the result.

If the request type is RpcRequest::batched, method RpcStub::Call assembles the message to the server and puts it in a buffer. Messages are only flushed if the buffer is full or RpcStub::Call is used with a normal or async request.

If the request type is RpcRequest::async, method RpcStub::Call (see RpcStub) assembles the message to the server and sends it, as with normal. It does, however, not wait for a result. Mode async is implemented by calling the underlying RPC--function clnt_call with a timeout of zero.

As in both non--normal cases (batched and async) RpcStub::Call does not wait for a return value from the server, the return type of the RpcRequest must be specified as &Xdr::Xnull.

Note that requests that are registered for a service are stored in an array using the request identification as the index, so keep ids small.

Normally, requests should be specified in a header file included by both the server and the client program (see Matching server and clients).

Callbacks
=========

If a server receives a request from a client, it needs to know how a particular procedure is to be invoked. This information is specified using objects RpcCallback or RpcMethodCall when the procedure resp. method is specified.

The class
 -- Class: AnyRpcCallback

serves as an abstract base class for the two kinds of callbacks.

The following sections describe the constructors for RpcCallback and RpcMethodCall and the calling conventions for the functions or methods called back.

RpcCallback
-----------

Declared in: "rpc++/callback.h"

 -- Class: RpcCallback
     An RpcCallback describes a function that is to be called by the server on request from the client.

 -- Constructor: RpcCallback (void* (*)() PROC)

 -- Constructor: RpcCallback (void* (*)(void*) PROC)

 -- Constructor: RpcCallback (void* (*)(void*, void*) PROC)
     Construct an RpcCallback for a function that takes zero, one or two arguments and returns a result. Constructors for functions with up to seven arguments are defined.

 -- Constructor: RpcCallback (void* (*)(void**) PROC)
     Construct an RpcCallback for a function that takes an arbitrary number of arguments and returns a result.

 -- Constructor: RpcCallback (void (*)() PROC)

 -- Constructor: RpcCallback (void (*)(void*) PROC)

 -- Constructor: RpcCallback (void (*)(void*, void*) PROC)
     Construct an RpcCallback for a function that takes zero, one or two arguments and returns no result. Constructors for functions with up to seven arguments are defined.

 -- Constructor: RpcCallback (void (*)(void**) PROC)
     Construct an RpcCallback for a function that takes an arbitrary number of arguments and return no result.

 -- Constructor: RpcCallback (void* (*)(RpcService*) PROC)

 -- Constructor: RpcCallback (void* (*)(void*, RpcService*) PROC)

 -- Constructor: RpcCallback (void* (*)(void*, void*, RpcService*) PROC)
     Construct an RpcCallback for a function that takes zero, one or two arguments and returns a result. Constructors for functions with up to seven arguments are defined. Upon invocation, a pointer to the object of type RpcService that received the request and called the function is passed as an additional argument.

 -- Constructor: RpcCallback (void* (*)(void**) PROC)
     Construct an RpcCallback for a function that takes an arbitrary number of arguments and returns a result. Upon invocation, a pointer to the object of type RpcService that received the request and called the function is passed as an additional argument.

 -- Constructor: RpcCallback (void (*)(RpcService*) PROC)

 -- Constructor: RpcCallback (void (*)(void*, RpcService*) PROC)

 -- Constructor: RpcCallback (void (*)(void*, void*, RpcService*) PROC)
     Construct an RpcCallback for a function that takes zero, one or two arguments and returns a result. Constructors for functions with up to seven arguments are defined. Upon invocation, a pointer to the object of type RpcService that received the request and called the function is passed as an additional argument.

 -- Constructor: RpcCallback (void (*)(void**) PROC)
     Construct an RpcCallback for a function that takes an arbitrary number of arguments and returns a result. Upon invocation, a pointer to the object of type RpcService that received the request and called the function is passed as an additional argument.

RpcMethodCall
-------------

Declared in: "rpc++/callback.h"

 -- Class: RpcMethodCall
     An RpcMethodCall describes a method of an object that is to be called by the server on request from the client.

 -- Constructor: RpcMethodCall <class T> (void* (T::*)() PROC)

 -- Constructor: RpcMethodCall <class T> (void* (T::*)(void*) PROC)

 -- Constructor: RpcMethodCall <class T> (void* (T::*)(void*, void*) PROC)
     Construct an RpcMethodCall for an object and one of its methods that takes zero, one or two arguments and returns a result. Constructors for methods with up to seven arguments are defined.

 -- Constructor: RpcMethodCall <class T> (void* (T::*)(void**) PROC)
     Construct an RpcMethodCall for an object and one of its methods that takes an arbitrary number of arguments and returns a result.

 -- Constructor: RpcMethodCall <class T> (void (T::*)() PROC)

 -- Constructor: RpcMethodCall <class T> (void (T::*)(void*) PROC)

 -- Constructor: RpcMethodCall <class T> (void (T::*)(void*, void*) PROC)
     Construct an RpcMethodCall for an object and one of its methods that takes zero, one or two arguments and returns no result. Constructors for methods with up to seven arguments are defined.

 -- Constructor: RpcMethodCall <class T> (void (T::*)(void**) PROC)
     Construct an RpcMethodCall for an object and one of its methods that takes an arbitrary number of arguments and return no result.

 -- Constructor: RpcMethodCall <class T> (void* (T::*)(RpcService*) PROC)

 -- Constructor: RpcMethodCall <class T> (void* (T::*)(void*, RpcService*) PROC)

 -- Constructor: RpcMethodCall <class T> (void* (T::*)(void*, void*, RpcService*) PROC)
     Construct an RpcMethodCall for an object and one of its methods that takes zero, one or two arguments and returns a result. Constructors for methods with up to seven arguments are defined. Upon invocation, a pointer to the object of type RpcService that received the request and called the method is passed as an additional argument.

 -- Constructor: RpcMethodCall <class T> (void* (T::*)(void**) PROC)
     Construct an RpcMethodCall for an object and one of its methods that takes an arbitrary number of arguments and returns a result. Upon invocation, a pointer to the object of type RpcService that received the request and called the method is passed as an additional argument.

 -- Constructor: RpcMethodCall <class T> (void (T::*)(RpcService*) PROC)

 -- Constructor: RpcMethodCall <class T> (void (T::*)(void*, RpcService*) PROC)

 -- Constructor: RpcMethodCall <class T> (void (T::*)(void*, void*, RpcService*) PROC)
     Construct an RpcMethodCall for an object and one of its methods that takes zero, one or two arguments and returns a result. Constructors for methods with up to seven arguments are defined. Upon invocation, a pointer to the object of type RpcService that received the request and called the method is passed as an additional argument.

 -- Constructor: RpcMethodCall <class T> (void (T::*)(void**) PROC)
     Construct an RpcMethodCall for an object and one of its methods that takes an arbitrary number of arguments and returns a result. Upon invocation, a pointer to the object of type RpcService that received the request and called the method is passed as an additional argument.

Calling Conventions
-------------------

As could be seen from the parameter types in the constructors, functions and methods that are called in response to a request from a client know only about pointers to void as arguments and result values because their real type is coded in the RpcRequest and not known at compile time. The only way to avoid this is to implement some kind of rpcgen++. However, I never liked this kind of tools and I'm willing to risk a bit of type unsafeness in this case.

When a procedure (or method) is called, its arguments point to values (the variants with an arbitrary number of arguments receive an array of pointers to values) of the types specified in the constructor of the RpcRequest that led to the invocation of the procedure. I recommend to access the values and assign them to local variables of the procedure in the first statements. E.g.:

     void* Add (void* s1p, void* s2p)
     {
       int s1 = *(int*)s1p;
       int s2 = *(int*)s2p;
       ...

The return value of the procedure is a pointer to the result. Therefore, results may never be put in automatic variables. They must be global or static. E.g.:

       ...
       static int sum;
       sum = s1 + s2;
       return (void*)&sum;
     }

Note the special case of strings (defined as parameters or return values using Xdr::Xwrapstring, see XdrInfo). If you think of a string as being defined as a type ``typedef char* string'', it is obvious that a string is passed as argument or returned as result by a string*, i.e., a char**. E.g.:

     void* Capitalize (void* strp)
     {
       static char* str;
       str = *(char**)strp;
       str[0] = toupper (str[0]);
       return (void*)&str;
     }

RpcService
==========

Declared in: "rpc++/service.h"

 -- Class: RpcService
     An object of type RpcService provides the server capabilities within a program.

There are two constructors for RpcService:

 -- Constructor: RpcService (u_long PROG, u_long VERS)
     Construct an object representing the VERS'th version of program (service) number prog.

 -- Constructor: RpcService (u_long VERS)
     Construct an object representing the VERS'th version of a transient program (service).

 -- Method: bool OK ()
     Returns TRUE if the service is ready for operation, i.e., has successfully been established during construction.

The number of a service, especially a transient service, can be obtained with method Program ():

 -- Method: u_long Program ()
     Returns the number of the program (service). This is either the number passed as an argument to the constructor or a number from the transient program area.

The next step after the construction of an RpcService is to register the requests handled by the service:

 -- Method: virtual void Register (const RpcRequest& REQ, const AnyRpcCallback& CB)
     Associate request REQ with the procedure or object/method pair specified by cb. The usual way to call Register is

          {
            RpcService svc (...);
            svc.register (addreq, RpcCallback (Add));
            ...
          }

If a service is to be provided no longer, it can be unregistered:

 -- Method: virtual void Unregister (const RpcRequest& REQ)
     Undoes the effect of a previous Register with the same argument REQ.

Sometimes servers provide ``dynamic'' services. The numbers of these services are send to the clients as, e.g., results of some well known request and can be used by the server and the client to construct an RpcRequest. A number representing such a dynamic service can be allocated with ReserverService:

 -- Method: u_long ReserveService ()
     Returns a service number that is not in use yet.

Of course, ReserveService should only be called after all well known services have been registered.  A Service number allocated by ReserveService is freed if the service is subsequently unregistered.

After all requests have been registered, the object of type RpcService can provide the service:
 -- Method: void Provide ()
     Repeatedly wait for a request and handle it by calling the procedure or method registered for it.

 -- Method: void Provide (timeval& MAXWAIT)
     Waits until the time specified by MAXWAIT has expired or a service has been requested and handled.

 -- Method: virtual void* HandleError ()
     HandleError is a protected method that is called when an error occurs. The cause of the error is stored in a protected member variable errorState. If the default error handling (shown below) is not appropriate for your application, derive your own class from RpcService that implements a different error handling policy. If you consider an error recoverable, reset errorState to RpcService::noError in your error handler. Else, OK () keeps returning FALSE.

          void RpcService::HandleError ()
          {
            switch (errorState)
              {
              case reconstructionAttempt:
                cerr << "rpc++: Attempt to construct another instance of RpcService.\n";
                exit (1);
              case cantCreateTCPService:
                cerr << "rpc++: can't create tcp service.\n";
                exit(1);
              case cantRegisterService:
                cerr << form ("rpc++: can't register (%d, %d, tcp).", prog, vers);
                exit(1);
              case cantSendReply:
                cerr << "rpc++: can't reply to RPC call.\n";
                break;
              case invalidResult:
                cerr << "rpc++: registered routine has return NULL pointer.\n";
                abort ();
              case notRegistered:
                cerr << "rpc++: requested RPC routine not registered.\n";
                break;
              case cantGetArgs:
                cerr << "rpc++: can't get procedure arguments.\n";
                break;
              case cantFreeArgs:
                cerr << "rpc++: can't free XDR arguments.\n";
                break;
              }
            errorState = noError;
          }

If the program that provides the service has other things to do as well, i.e., does not only handle requests, it usually has its own main loop that handles events. This loop must be extended to handle RPC events, i.e., if anything happens on the RPC file descriptors, it must call svc_getreqset just as Provide () does.

     void RpcService::Provide ()
     {
       int dtbsz = getdtablesize();
       fd_set readfds;

       for(;;)
         {
           readfds = svc_fdset;
           switch(select (dtbsz, &readfds, 0, 0, 0))
             {
             case -1:
               if (errno != EBADF)
                 continue;
               cerr << "PRC++: select: " << sys_errlist[errno] << '\n';
               return;
               break;
             case 0:
               continue;
             default:
               svc_getreqset (&readfds);
               break;
             }
         }
     }

The following methods are only available during the execution of a callback, i.e., they can be applied to RpcService if a pointer to the invoking object has been declared as last parameter of a callback routine.

 -- Method: struct sockaddr_in* Caller ()
     Return the socket address information of the calling host.

 -- Method: char* CallerName ()
     Return the name of the calling host.

 -- Method: void Reply ()

 -- Method: void Reply (void* RES)
     Normally, a request to the server terminates when the callback completes (either with or without returning a value, depending on the return type). In some cases it is desirable to reply to the client before all the actions related to the request have been completed. This allows the client to resume execution. The result (if any) must of course not depend on the functions still to be executed.

 -- Method: void Interrupt ()
     This is the proper way to terminate the loop entered by calling Provide(). After return from the callback that invoked Interrupt() method Provide() will return.

RpcStub
=======

Declared in: "rpc++/stub.h"

 -- Class: RpcStub
     An RpcStub represents the client side of a connection.

There are two constructors for RpcStub that vary in the position of their arguments only:

 -- Constructor: RpcStub (u_long prognum, u_long versnum, char* HOSTNAME="localhost", timeval TIMEOUT=defaultTimeout, bool CONNECT=TRUE)

 -- Constructor: RpcStub (u_long prognum, u_long versnum, char* HOSTNAME="localhost", bool CONNECT=TRUE, timeval TIMEOUT=defaultTimeout)
     Construct an RpcStub that connects to the VERSNUM'th version of program (service) PROGNUM on host HOSTNAME. The timeout for successful completion of communication operations is TIMEOUT which defaults to 25 seconds. Unless CONNECT is false, the constructor makes a connection attempt.

There are various methods:

 -- Method: void Reconnect (bool HANDLE_ERRORS = TRUE)
     Connect to the server. Usually this method is called if the connection was not to be established by the constructor or if the connection attempt failed and is to be repeated. If HANDLE_ERRORS is FALSE, no error handler is called in case of failure.

 -- Method: bool OK ()
     Returns TRUE if the stub is ready for operation, i.e., connected to a server.

 -- Method: CLIENT* Service ()
     Access to the standard RPC level. Returns the handle that identifies the server.

 -- Method: timeval GetTimeout () const
     Returns the default timeout for network operations.

 -- Method: void SetTimeout (timeval& TIMO)
     Sets the default timeout for network operations

 -- Method: void* Call (RpcRequest& REQ, bool HANDLE_ERRORS=TRUE)

 -- Method: void* Call (RpcRequest& REQ, void* IN1, bool HANDLE_ERRORS=TRUE)

 -- Method: void* Call (RpcRequest& REQ, void* IN1, IN2 bool HANDLE_ERRORS=TRUE)
     Request the operation specified by REQ from the server, passing zero, one or two arguments. There are declarations of this method for up two seven arguments. Arguments are passed as pointers to the argument values. The value returned by Call is a pointer to the result returned by the server. The result is valid until Call is called again. If HANDLE_ERRORS is FALSE and an error occurs, Call simply returns 0. Else, it calls method HandleError (see below).

 -- Method: void* Call (RpcRequest& REQ, void** INVALS, bool HANDLE_ERRORS=TRUE)
     The variant of Call that handles an arbitrary number of arguments.  Pointers to the arguments are passed in an array in parameter INVALS. The size of the array must match the number of arguments given to the constructor of REQ.

 -- Method: virtual void* HandleError ()
     HandleError is a protected method that is called when an error occurs. The cause of the error is stored in a protected member variable errorState. If the default error handling policy (shown below) is not appropriate for your application, derive your own class from RpcStub that implements a different one. If you consider an error recoverable, reset errorState to RpcStub::noError in your error handler. Else, OK () keeps returning FALSE.  If an error occurs during a Call and parameter HANDLE_ERRORS is TRUE, Call invokes HandleError and returns its result as result of the call.

          void* RpcStub::HandleError ()
          {
            switch (errorState)
              {
              case notConnected:
                cerr << "rpc++: Stub has not been connected to server.\n";
              case cantCreate:
                cerr << clnt_spcreateerror ("rpc++") << '\n';
                break;
              case cantCall:
                cerr << clnt_sperror (svc, "rpc++") << '\n';
                exit (1);
              }
            return 0;
          }

If the cause of an error can be detected and fixed (e.g., using Reconnect, ReCall can be called to repeat the call that caused the error in the first place with its original arguments:

 -- Method: void* ReCall (bool HANDLE_ERRORS)
     May be called from within an error handler only. Repeats any previous call and returns its result (or 0 in case of failure). Normally, HANDLE_ERRORS should be FALSE to avoid infinite recursive calls of the error handler.

While no or little improvement of coding quality can be gained from deriving a service specific class from RpcService, the opposite is true for RpcStub.  A service specific derivation may define methods that have the ``real'' argument lists instead of pointers to void. These methods are simply implemented by casting the arguments and (inline) calling one of the Call--methods. Apart from better type checking, this has the advantage of keeping details like the available RpcRequests local to the definition of the derived class (see the example in the example--directory).

Caveats
*******

Global objects
==============

As a general C++ rule, be careful with global objects. The sequence of constructor invocations for global objects is not defined. This is the reason, why RpcRequests are constructed from pointers to XdrInfos rather than from XdrInfos.

Both XdrInfos and RpcRequests tend to be instantiated as global objects or static member variables. If the constructor of RpcRequest received XdrInfos instead of pointers and copied the information contained in the XdrInfo (the solution I had preferred), it may happen that the XdrInfo has not been constructed yet and thus contains invalid data.

The same problem occurs if you want to define a global ``alias--XdrInfo'' matching a ``typedef int myint''. Don't use XdrInfo Xmyint (Xdr::Xint) as this may copy the uninitialized Xdr::Xint. Use XdrInfo& Xmyint = Xdr::Xint instead.

Destruction rules
=================

Objects of type XdrInfo are resources that can be used more than once, i.e., in different RpcRequests. If they were handled properly, references to XdrInfo would be counted and the XdrInfo destructed automatically if the last reference is removed (unless it is the XdrInfo of a predefined type).

Such a resource management for XdrInfos has been considered unnecessary as XdrInfos will rarely be dynamic objects. If the user allocates an XdrInfo on the stack or the heap, it is his responsibility to assure that the object is valid until the last RpcResource that uses it has been destructed.

Matching server and clients
===========================

In order to make sure that the server and the clients agree about the protocol, all RpcRequests for a service should be declared in a header file and instantiated in a corresponding source file. The header file and the compiled source file make the ``library'' that provides the service. Thus a server consists of three files: the server executable, a header file defining the service that is to be included in client sources and an object file which must be linked to the client executable.

References
**********

Margaret A. Ellis, The Annotated C++ Reference Manual, Addison-Wesley, 1990.

Stanley B. Lippmann, A C++ Primer, Addison-Wesley, 1989.

Bjarne Stroustrup, The C++ Programming Language, Addison-Wesley, 1986.

Sun Microsystems, Network Programming, March 1990.

GNU LIBRARY GENERAL PUBLIC LICENSE
**********************************

Version 2, June 1991

     Copyright © 1991 Free Software Foundation, Inc.
     675 Mass Ave, Cambridge, MA 02139, USA
     Everyone is permitted to copy and distribute verbatim copies
     of this license document, but changing it is not allowed.

Preamble
========

The licenses for most software are designed to take away your freedom to share and change it.  By contrast, the GNU General Public Licenses are intended to guarantee your freedom to share and change free software---to make sure the software is free for all its users.

This license, the Library General Public License, applies to some specially designated Free Software Foundation software, and to any other libraries whose authors decide to use it.  You can use it for your libraries, too.

When we speak of free software, we are referring to freedom, not price.  Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for this service if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs; and that you know you can do these things.

To protect your rights, we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights. These restrictions translate to certain responsibilities for you if you distribute copies of the library, or if you modify it.

For example, if you distribute copies of the library, whether gratis or for a fee, you must give the recipients all the rights that we gave you.  You must make sure that they, too, receive or can get the source code.  If you link a program with the library, you must provide complete object files to the recipients so that they can relink them with the library, after making changes to the library and recompiling it.  And you must show them these terms so they know their rights.

Our method of protecting your rights has two steps: (1) copyright the library, and (2) offer you this license which gives you legal permission to copy, distribute and/or modify the library.

Also, for each distributor's protection, we want to make certain that everyone understands that there is no warranty for this free library.  If the library is modified by someone else and passed on, we want its recipients to know that what they have is not the original version, so that any problems introduced by others will not reflect on the original authors' reputations.

Finally, any free program is threatened constantly by software patents.  We wish to avoid the danger that companies distributing free software will individually obtain patent licenses, thus in effect transforming the program into proprietary software.  To prevent this, we have made it clear that any patent must be licensed for everyone's free use or not licensed at all.

Most GNU software, including some libraries, is covered by the ordinary GNU General Public License, which was designed for utility programs.  This license, the GNU Library General Public License, applies to certain designated libraries.  This license is quite different from the ordinary one; be sure to read it in full, and don't assume that anything in it is the same as in the ordinary license.

The reason we have a separate public license for some libraries is that they blur the distinction we usually make between modifying or adding to a program and simply using it.  Linking a program with a library, without changing the library, is in some sense simply using the library, and is analogous to running a utility program or application program.  However, in a textual and legal sense, the linked executable is a combined work, a derivative of the original library, and the ordinary General Public License treats it as such.

Because of this blurred distinction, using the ordinary General Public License for libraries did not effectively promote software sharing, because most developers did not use the libraries.  We concluded that weaker conditions might promote sharing better.

However, unrestricted linking of non-free programs would deprive the users of those programs of all benefit from the free status of the libraries themselves.  This Library General Public License is intended to permit developers of non-free programs to use free libraries, while preserving your freedom as a user of such programs to change the free libraries that are incorporated in them.  (We have not seen how to achieve this as regards changes in header files, but we have achieved it as regards changes in the actual functions of the Library.)  The hope is that this will lead to faster development of free libraries.

The precise terms and conditions for copying, distribution and modification follow.  Pay close attention to the difference between a ``work based on the library'' and a ``work that uses the library''.  The former contains code derived from the library, while the latter only works together with the library.

Note that it is possible for a library to be covered by the ordinary General Public License rather than by this special one.

TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION

 1. This License Agreement applies to any software library which contains a notice placed by the copyright holder or other authorized party saying it may be distributed under the terms of this Library General Public License (also called ``this License'').  Each licensee is addressed as ``you''.

     A ``library'' means a collection of software functions and/or data prepared so as to be conveniently linked with application programs (which use some of those functions and data) to form executables.

     The ``Library'', below, refers to any such software library or work which has been distributed under these terms.  A ``work based on the Library'' means either the Library or any derivative work under copyright law: that is to say, a work containing the Library or a portion of it, either verbatim or with modifications and/or translated straightforwardly into another language.  (Hereinafter, translation is included without limitation in the term ``modification''.)

     ``Source code'' for a work means the preferred form of the work for making modifications to it.  For a library, complete source code means all the source code for all modules it contains, plus any associated interface definition files, plus the scripts used to control compilation and installation of the library.

     Activities other than copying, distribution and modification are not covered by this License; they are outside its scope.  The act of running a program using the Library is not restricted, and output from such a program is covered only if its contents constitute a work based on the Library (independent of the use of the Library in a tool for writing it).  Whether that is true depends on what the Library does and what the program that uses the Library does.

 2. You may copy and distribute verbatim copies of the Library's complete source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this License and to the absence of any warranty; and distribute a copy of this License along with the Library.

     You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee.

 3. You may modify your copy or copies of the Library or any portion of it, thus forming a work based on the Library, and copy and distribute such modifications or work under the terms of Section 1 above, provided that you also meet all of these conditions:

      1. The modified work must itself be a software library.

      2. You must cause the files modified to carry prominent notices stating that you changed the files and the date of any change.

      3. You must cause the whole of the work to be licensed at no charge to all third parties under the terms of this License.

      4. If a facility in the modified Library refers to a function or a table of data to be supplied by an application program that uses the facility, other than as an argument passed when the facility is invoked, then you must make a good faith effort to ensure that, in the event an application does not supply such function or table, the facility still operates, and performs whatever part of its purpose remains meaningful.

          (For example, a function in a library to compute square roots has a purpose that is entirely well-defined independent of the application.  Therefore, Subsection 2d requires that any application-supplied function or table used by this function must be optional: if the application does not supply it, the square root function must still compute square roots.)

     These requirements apply to the modified work as a whole.  If identifiable sections of that work are not derived from the Library, and can be reasonably considered independent and separate works in themselves, then this License, and its terms, do not apply to those sections when you distribute them as separate works.  But when you distribute the same sections as part of a whole which is a work based on the Library, the distribution of the whole must be on the terms of this License, whose permissions for other licensees extend to the entire whole, and thus to each and every part regardless of who wrote it.

     Thus, it is not the intent of this section to claim rights or contest your rights to work written entirely by you; rather, the intent is to exercise the right to control the distribution of derivative or collective works based on the Library.

     In addition, mere aggregation of another work not based on the Library with the Library (or with a work based on the Library) on a volume of a storage or distribution medium does not bring the other work under the scope of this License.

 4. You may opt to apply the terms of the ordinary GNU General Public License instead of this License to a given copy of the Library.  To do this, you must alter all the notices that refer to this License, so that they refer to the ordinary GNU General Public License, version 2, instead of to this License.  (If a newer version than version 2 of the ordinary GNU General Public License has appeared, then you can specify that version instead if you wish.)  Do not make any other change in these notices.

     Once this change is made in a given copy, it is irreversible for that copy, so the ordinary GNU General Public License applies to all subsequent copies and derivative works made from that copy.

     This option is useful when you wish to copy part of the code of the Library into a program that is not a library.

 5. You may copy and distribute the Library (or a portion or derivative of it, under Section 2) in object code or executable form under the terms of Sections 1 and 2 above provided that you accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange.

     If distribution of object code is made by offering access to copy from a designated place, then offering equivalent access to copy the source code from the same place satisfies the requirement to distribute the source code, even though third parties are not compelled to copy the source along with the object code.

 6. A program that contains no derivative of any portion of the Library, but is designed to work with the Library by being compiled or linked with it, is called a ``work that uses the Library''.  Such a work, in isolation, is not a derivative work of the Library, and therefore falls outside the scope of this License.

     However, linking a ``work that uses the Library'' with the Library creates an executable that is a derivative of the Library (because it contains portions of the Library), rather than a ``work that uses the library''.  The executable is therefore covered by this License. Section 6 states terms for distribution of such executables.

     When a ``work that uses the Library'' uses material from a header file that is part of the Library, the object code for the work may be a derivative work of the Library even though the source code is not. Whether this is true is especially significant if the work can be linked without the Library, or if the work is itself a library.  The threshold for this to be true is not precisely defined by law.

     If such an object file uses only numerical parameters, data structure layouts and accessors, and small macros and small inline functions (ten lines or less in length), then the use of the object file is unrestricted, regardless of whether it is legally a derivative work.  (Executables containing this object code plus portions of the Library will still fall under Section 6.)

     Otherwise, if the work is a derivative of the Library, you may distribute the object code for the work under the terms of Section 6. Any executables containing that work also fall under Section 6, whether or not they are linked directly with the Library itself.

 7. As an exception to the Sections above, you may also compile or link a ``work that uses the Library'' with the Library to produce a work containing portions of the Library, and distribute that work under terms of your choice, provided that the terms permit modification of the work for the customer's own use and reverse engineering for debugging such modifications.

     You must give prominent notice with each copy of the work that the Library is used in it and that the Library and its use are covered by this License.  You must supply a copy of this License.  If the work during execution displays copyright notices, you must include the copyright notice for the Library among them, as well as a reference directing the user to the copy of this License.  Also, you must do one of these things:

      1. Accompany the work with the complete corresponding machine-readable source code for the Library including whatever changes were used in the work (which must be distributed under Sections 1 and 2 above); and, if the work is an executable linked with the Library, with the complete machine-readable ``work that uses the Library'', as object code and/or source code, so that the user can modify the Library and then relink to produce a modified executable containing the modified Library.  (It is understood that the user who changes the contents of definitions files in the Library will not necessarily be able to recompile the application to use the modified definitions.)

      2. Accompany the work with a written offer, valid for at least three years, to give the same user the materials specified in Subsection 6a, above, for a charge no more than the cost of performing this distribution.

      3. If distribution of the work is made by offering access to copy from a designated place, offer equivalent access to copy the above specified materials from the same place.

      4. Verify that the user has already received a copy of these materials or that you have already sent this user a copy.

     For an executable, the required form of the ``work that uses the Library'' must include any data and utility programs needed for reproducing the executable from it.  However, as a special exception, the source code distributed need not include anything that is normally distributed (in either source or binary form) with the major components (compiler, kernel, and so on) of the operating system on which the executable runs, unless that component itself accompanies the executable.

     It may happen that this requirement contradicts the license restrictions of other proprietary libraries that do not normally accompany the operating system.  Such a contradiction means you cannot use both them and the Library together in an executable that you distribute.

 8. You may place library facilities that are a work based on the Library side-by-side in a single library together with other library facilities not covered by this License, and distribute such a combined library, provided that the separate distribution of the work based on the Library and of the other library facilities is otherwise permitted, and provided that you do these two things:

      1. Accompany the combined library with a copy of the same work based on the Library, uncombined with any other library facilities.  This must be distributed under the terms of the Sections above.

      2. Give prominent notice with the combined library of the fact that part of it is a work based on the Library, and explaining where to find the accompanying uncombined form of the same work.

 9. You may not copy, modify, sublicense, link with, or distribute the Library except as expressly provided under this License.  Any attempt otherwise to copy, modify, sublicense, link with, or distribute the Library is void, and will automatically terminate your rights under this License.  However, parties who have received copies, or rights, from you under this License will not have their licenses terminated so long as such parties remain in full compliance.

 10. You are not required to accept this License, since you have not signed it.  However, nothing else grants you permission to modify or distribute the Library or its derivative works.  These actions are prohibited by law if you do not accept this License.  Therefore, by modifying or distributing the Library (or any work based on the Library), you indicate your acceptance of this License to do so, and all its terms and conditions for copying, distributing or modifying the Library or works based on it.

 11. Each time you redistribute the Library (or any work based on the Library), the recipient automatically receives a license from the original licensor to copy, distribute, link with or modify the Library subject to these terms and conditions.  You may not impose any further restrictions on the recipients' exercise of the rights granted herein. You are not responsible for enforcing compliance by third parties to this License.

 12. If, as a consequence of a court judgment or allegation of patent infringement or for any other reason (not limited to patent issues), conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License.  If you cannot distribute so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not distribute the Library at all.  For example, if a patent license would not permit royalty-free redistribution of the Library by all those who receive copies directly or indirectly through you, then the only way you could satisfy both it and this License would be to refrain entirely from distribution of the Library.

     If any portion of this section is held invalid or unenforceable under any particular circumstance, the balance of the section is intended to apply, and the section as a whole is intended to apply in other circumstances.

     It is not the purpose of this section to induce you to infringe any patents or other property right claims or to contest validity of any such claims; this section has the sole purpose of protecting the integrity of the free software distribution system which is implemented by public license practices.  Many people have made generous contributions to the wide range of software distributed through that system in reliance on consistent application of that system; it is up to the author/donor to decide if he or she is willing to distribute software through any other system and a licensee cannot impose that choice.

     This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License.

 13. If the distribution and/or use of the Library is restricted in certain countries either by patents or by copyrighted interfaces, the original copyright holder who places the Library under this License may add an explicit geographical distribution limitation excluding those countries, so that distribution is permitted only in or among countries not thus excluded.  In such case, this License incorporates the limitation as if written in the body of this License.

 14. The Free Software Foundation may publish revised and/or new versions of the Library General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns.

     Each version is given a distinguishing version number.  If the Library specifies a version number of this License which applies to it and ``any later version'', you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation.  If the Library does not specify a license version number, you may choose any version ever published by the Free Software Foundation.

 15. If you wish to incorporate parts of the Library into other free programs whose distribution conditions are incompatible with these, write to the author to ask for permission.  For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this.  Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally.

     NO WARRANTY

 16. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE LIBRARY ``AS IS'' WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.  THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE LIBRARY IS WITH YOU.  SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.

 17. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.

END OF TERMS AND CONDITIONS

How to Apply These Terms to Your New Libraries
==============================================

If you develop a new library, and you want it to be of the greatest possible use to the public, we recommend making it free software that everyone can redistribute and change.  You can do so by permitting redistribution under these terms (or, alternatively, under the terms of the ordinary General Public License).

To apply these terms, attach the following notices to the library.  It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the ``copyright'' line and a pointer to where the full notice is found.

     ONE LINE TO GIVE THE LIBRARY'S NAME AND A BRIEF IDEA OF WHAT IT DOES.
     Copyright (C) YEAR  NAME OF AUTHOR

     This library is free software; you can redistribute it and/or
     modify it under the terms of the GNU Library General Public
     License as published by the Free Software Foundation; either
     version 2 of the License, or (at your option) any later version.

     This library is distributed in the hope that it will be useful,
     but WITHOUT ANY WARRANTY; without even the implied warranty of
     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
     Library General Public License for more details.

     You should have received a copy of the GNU Library General Public
     License along with this library; if not, write to the Free
     Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.

Also add information on how to contact you by electronic and paper mail.

You should also get your employer (if you work as a programmer) or your school, if any, to sign a ``copyright disclaimer'' for the library, if necessary.  Here is a sample; alter the names:

     Yoyodyne, Inc., hereby disclaims all copyright interest in the
     library `Frob' (a library for tweaking knobs) written by James Random Hacker.

     SIGNATURE OF TY COON, 1 April 1990
     Ty Coon, President of Vice

That's all there is to it!