Skip Navigation Links | |
Exit Print View | |
ONC+ Developer's Guide Oracle Solaris 11.1 Information Library |
1. Introduction to ONC+ Technologies
4. Programmer's Interface to RPC
Client Side of Simplified Interface
Server Side of the Simplified Interface
Hand-Coded Registration Routine
Client Side of the Top-Level Interface
Client Side of the Intermediate-Level Interface
Server Side of the Intermediate-Level Interface
Client Side of the Expert-Level Interface
Server Side of the Expert-Level Interface
Client Side of the Bottom-Level Interface
Server Side of the Bottom-Level Interface
Testing Programs Using Low-Level Raw RPC
Connection-Oriented Transports
5. Advanced RPC Programming Techniques
6. Porting From TS-RPC to TI-RPC
7. Multithreaded RPC Programming
8. Extensions to the Oracle Solaris RPC Library
XDR routines normally serialize and deserialize data. XDR routines often automatically allocate memory and free automatically allocated memory. The convention is to use a NULL pointer to an array or structure to indicate that an XDR function must allocate memory when deserializing. The next example, xdr_chararr1(), processes a fixed array of bytes with length SIZE and cannot allocate memory if needed:
xdr_chararr1(xdrsp, chararr) XDR *xdrsp; char chararr[]; { char *p; int len; p = chararr; len = SIZE; return (xdr_bytes(xdrsp, &p, &len, SIZE)); }
If space has already been allocated in chararr, it can be called from a server as follows.
char chararr[SIZE]; svc_getargs(transp, xdr_chararr1, chararr);
Any structure through which data is passed to XDR or RPC routines must be allocated so that its base address is at an architecture-dependent boundary. An XDR routine that does the allocation must be written so that it can:
Allocate memory when a caller requests
Return the pointer to any memory it allocates
In the following example, the second argument is a NULL pointer, meaning that memory should be allocated to hold the data being deserialized.
xdr_chararr2(xdrsp, chararrp) XDR *xdrsp; char **chararrp; { int len; len = SIZE; return (xdr_bytes(xdrsp, charrarrp, &len, SIZE)); }
The corresponding RPC call is:
char *arrptr; arrptr = NULL; svc_getargs(transp, xdr_chararr2, &arrptr); /* * Use the result here */ svc_freeargs(transp, xdr_chararr2, &arrptr);
After use, free the character array through svc_freeargs(). svc_freeargs() does nothing if passed a NULL pointer as its second argument.
To summarize: