home *** CD-ROM | disk | FTP | other *** search
/ Gold Fish 3 / goldfish_volume_3.bin / files / comm / tcp / amitcp-sdk / src / rpclib / pmap_prot2.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-09-29  |  2.7 KB  |  97 lines

  1. /*
  2.  *      $Id: pmap_prot2.c,v 4.2 1994/09/29 23:48:50 jraja Exp $
  3.  *
  4.  *      Protocol for the local binder service, or pmap.
  5.  *
  6.  *      Copyright © 1994 AmiTCP/IP Group,
  7.  *                       Network Solutions Development Inc.
  8.  *                       All rights reserved. 
  9.  */
  10.  
  11. /* @(#)pmap_prot2.c    2.1 88/07/29 4.0 RPCSRC */
  12. #if !defined(lint) && defined(SCCSIDS)
  13. static char sccsid[] = "@(#)pmap_prot2.c 1.3 87/08/11 Copyr 1984 Sun Micro";
  14. #endif
  15.  
  16. /*
  17.  * Copyright (C) 1984, Sun Microsystems, Inc.
  18.  */
  19.  
  20. #include <sys/param.h>
  21. #include <rpc/types.h>
  22. #include <rpc/xdr.h>
  23. #include <rpc/pmap_prot.h>
  24.  
  25.  
  26. /* 
  27.  * What is going on with linked lists? (!)
  28.  * First recall the link list declaration from pmap_prot.h:
  29.  *
  30.  * struct pmaplist {
  31.  *    struct pmap pml_map;
  32.  *    struct pmaplist *pml_map;
  33.  * };
  34.  *
  35.  * Compare that declaration with a corresponding xdr declaration that 
  36.  * is (a) pointer-less, and (b) recursive:
  37.  *
  38.  * typedef union switch (bool_t) {
  39.  * 
  40.  *    case TRUE: struct {
  41.  *        struct pmap;
  42.  *         pmaplist_t foo;
  43.  *    };
  44.  *
  45.  *    case FALSE: struct {};
  46.  * } pmaplist_t;
  47.  *
  48.  * Notice that the xdr declaration has no nxt pointer while
  49.  * the C declaration has no bool_t variable.  The bool_t can be
  50.  * interpreted as ``more data follows me''; if FALSE then nothing
  51.  * follows this bool_t; if TRUE then the bool_t is followed by
  52.  * an actual struct pmap, and then (recursively) by the 
  53.  * xdr union, pamplist_t.  
  54.  *
  55.  * This could be implemented via the xdr_union primitive, though this
  56.  * would cause a one recursive call per element in the list.  Rather than do
  57.  * that we can ``unwind'' the recursion
  58.  * into a while loop and do the union arms in-place.
  59.  *
  60.  * The head of the list is what the C programmer wishes to past around
  61.  * the net, yet is the data that the pointer points to which is interesting;
  62.  * this sounds like a job for xdr_reference!
  63.  */
  64. bool_t XDRFUN
  65. xdr_pmaplist(xdrs, rp)
  66.     register XDR *xdrs;
  67.     register struct pmaplist **rp;
  68. {
  69.     /*
  70.      * more_elements is pre-computed in case the direction is
  71.      * XDR_ENCODE or XDR_FREE.  more_elements is overwritten by
  72.      * xdr_bool when the direction is XDR_DECODE.
  73.      */
  74.     bool_t more_elements;
  75.     register int freeing = (xdrs->x_op == XDR_FREE);
  76.     register struct pmaplist **next;
  77.  
  78.     while (TRUE) {
  79.         more_elements = (bool_t)(*rp != NULL);
  80.         if (! xdr_bool(xdrs, &more_elements))
  81.             return (FALSE);
  82.         if (! more_elements)
  83.             return (TRUE);  /* we are done */
  84.         /*
  85.          * the unfortunate side effect of non-recursion is that in
  86.          * the case of freeing we must remember the next object
  87.          * before we free the current object ...
  88.          */
  89.         if (freeing)
  90.             next = &((*rp)->pml_next); 
  91.         if (! xdr_reference(xdrs, (caddr_t *)rp,
  92.             (u_int)sizeof(struct pmaplist), xdr_pmap))
  93.             return (FALSE);
  94.         rp = (freeing) ? next : &((*rp)->pml_next);
  95.     }
  96. }
  97.