From: rsalz@osf.org (Rich Salz)
Subject: Re: DCE RPC: [out] conformant arrays?
Date: 23 Sep 1993 14:21:13 GMT [thread overview]
Message-ID: <27sbcp$s3r@paperboy.osf.org> (raw)
In-Reply-To: CDrFDG.Cs@jabberwock.NeoSoft.com
In <CDrFDG.Cs@jabberwock.NeoSoft.com> daniels@jabberwock.NeoSoft.com (Brad Daniels) writes:
>typedef enum {
> INT_TYPE, FLOAT_TYPE, DOUBLE_TYPE
>} valType;
>
>typedef struct {
> union switch (valType t) {
> case INT_TYPE: int i;
> case FLOAT_TYPE: float f;
> case DOUBLE_TYPE: double d;
> } valUnion;
>} value;
>
>typedef struct {
> int count;
> [size_is(count)] value vals[];
>} valList;
>
>[idempotent] void getValues([out] valList *vals);
You were *very* close. :-) You want to do this:
void getValues([in, out] valList *vals);
Your client code should look like this:
valList x;
x.count = 0;
getValues(&x);
for (i = 0; i < x.count)
munge(x.vals[i]);
rpc_ss_client_free(x.vals);
Your server could should look like this:
getValues(valList *xp)
{
int i;
xp->count = get_count();
xp->vals = rpc_ss_allocate(xp->count * sizeof xp->vals[0]);
for (i = 0; i < xp->count; i++)
get_nth_value(i, &xp->vals[i]);
}
The key is that you cannot pass in a top-level conformant array. You have
to wrap it in a struct, as you did. The DCE Application Development Guide
says that a structure containing a conformant array must be passed by
reference, must have the [in] attribute, and that the containing structure
can only have one conformant array which must be the last element in the
array. See "Rules for Using Arrays" (section 17.14.5.3) in Volume 1 of
the guide.
:In either case, how are we actually supposed to handle memory allocation?
:I think we're supposed to just allocate the memory at the client end,
:and pass it in to be filled up by the stub.
You can do this but you'll also have to fill in dummy values or add a
[length_is] attribute and variable so that the memory is allocated, but
the client ships 0 elements and the server ships back the right number of
elements. Or, you can do as I did above and use the rpc_ss_xxx functions.
A basic rule is that if the server is going to allocate memory that will
be returned to a client, it must use rpc_ss_allocate (rather then malloc).
If a client wants to free memory that was allocated by a stub it should
call rpc_ss_client_free (rather then free). The client should free
everything that the server allocated.
Hope this helps,
/r$
next prev parent reply other threads:[~1993-09-23 14:21 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
1993-09-22 14:39 DCE RPC: [out] conformant arrays? Brad Daniels
1993-09-23 14:21 ` Rich Salz [this message]
1993-09-23 16:49 ` Brad Daniels
1993-09-27 15:20 ` Rich Salz
read-only archive
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox