* DCE RPC: [out] conformant arrays?
@ 1993-09-22 14:39 Brad Daniels
1993-09-23 14:21 ` Rich Salz
0 siblings, 1 reply; 4+ messages in thread
From: Brad Daniels @ 1993-09-22 14:39 UTC (permalink / raw)
We want to send an array of names to a remote server and get back an
array of values and an array of status. Each value is of a discriminated
union type, and we want a conformant array of them. We can't seem to declare
an [out] parameter of the conformant type, though. E.g., we want to say
something like:
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);
... But we get errors. Do we need to do something like:
[idempotent] void getValues([in] int count,
[out,length_is(count)] value vals[]);
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. On the server end, we're
expecting the server stub to have allocated appropriate memory. Is this
the right way to handle the memory part? There weren't any examples we
could find in the docs to show how we should be doing this, and the
descriptions are a wee bit confusing.
Examples or explanations much appreciated.
Thanks,
- Brad
--
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: DCE RPC: [out] conformant arrays?
1993-09-22 14:39 DCE RPC: [out] conformant arrays? Brad Daniels
@ 1993-09-23 14:21 ` Rich Salz
1993-09-23 16:49 ` Brad Daniels
0 siblings, 1 reply; 4+ messages in thread
From: Rich Salz @ 1993-09-23 14:21 UTC (permalink / raw)
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$
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: DCE RPC: [out] conformant arrays?
1993-09-23 14:21 ` Rich Salz
@ 1993-09-23 16:49 ` Brad Daniels
1993-09-27 15:20 ` Rich Salz
0 siblings, 1 reply; 4+ messages in thread
From: Brad Daniels @ 1993-09-23 16:49 UTC (permalink / raw)
In article <27sbcp$s3r@paperboy.osf.org> rsalz@osf.org (Rich Salz) writes:
>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);
[... Rest of example deleted ...]
Thanks for the info, but I still have one concern...
Doesn't this approach result in our (uninitialized) array getting sent
across the network both ways? I just want to get back a filled-in array.
I could end up eating a lot of excess bandwidth and unnecessary conversion
time this way.
- Brad
P.S. The original message was from biles.com, not jabberwock.neosoft.com.
My mail software is confused on jabberwock. I can receive mail as
daniels@biles.com or daniels@neosoft.com.
--
Brad Daniels | "Let others praise ancient times.
daniels@neosoft.com | I am glad I was born in these."
I don't work for NeoSoft, and | - Ovid (43 B.C. - 17 A.D)
don't speak for my employer. |
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~1993-09-27 15:20 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
1993-09-22 14:39 DCE RPC: [out] conformant arrays? Brad Daniels
1993-09-23 14:21 ` Rich Salz
1993-09-23 16:49 ` Brad Daniels
1993-09-27 15:20 ` Rich Salz
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox