Hello,
I'm writing an RPC C program in LInux and i want to pass dynamically allocated arrays, but only the first element of the arrays is reachable at the server side.
Code:
struct data {
int size;
int *X;
int *Y;
float r;
};
struct myarray {
float pin<2>;
};
struct dianisma {
int size;
float *X;
};
program ASKISI_PROG {
version ASKISI_VERS {
int ESOTERIKO_GINOMENO(data) = 1;
myarray MESI_TIMI(data) = 2;
dianisma GINOMENO(data) = 3;
} = 1;
} = 0x23451111;
Let's focus on ESOTERIKO_GINOMENO function. Two dynamically allocated arrays should be passed to the server, but only the first element of both arrays is passed.
xdr file:
Code:
bool_t
xdr_data (XDR *xdrs, data *objp)
{
register int32_t *buf;
if (!xdr_int (xdrs, &objp->size))
return FALSE;
if (!xdr_pointer (xdrs, (char **)&objp->X, sizeof (int), (xdrproc_t) xdr_int))
return FALSE;
if (!xdr_pointer (xdrs, (char **)&objp->Y, sizeof (int), (xdrproc_t) xdr_int))
return FALSE;
if (!xdr_float (xdrs, &objp->r))
return FALSE;
return TRUE;
}
bool_t
xdr_myarray (XDR *xdrs, myarray *objp)
{
register int32_t *buf;
if (!xdr_array (xdrs, (char **)&objp->pin.pin_val, (u_int *) &objp->pin.pin_len, 2,
sizeof (float), (xdrproc_t) xdr_float))
return FALSE;
return TRUE;
}
bool_t
xdr_dianisma (XDR *xdrs, dianisma *objp)
{
register int32_t *buf;
if (!xdr_int (xdrs, &objp->size))
return FALSE;
if (!xdr_pointer (xdrs, (char **)&objp->X, sizeof (float), (xdrproc_t) xdr_float))
return FALSE;
return TRUE;
}
client usage snippet:
Code:
scanf("%d", &size);
data_1_arg.X= (int *) malloc(size*sizeof(int));
data_1_arg.Y= (int *) malloc(size*sizeof(int));
// ....
result_1 = esoteriko_ginomeno_1(&data_1_arg, clnt);
Server Side:
Code:
int * esoteriko_ginomeno_1_svc(data *argp, struct svc_req *rqstp)
{
int i;
static int result;
result = 0;
for(i=0; i<argp->size; i++) {
printf("%d ", argp->X[i]);
}
puts("");
for(i=0; i<argp->size; i++) {
printf("%d ", argp->Y[i]);
}
puts("");
for(i=0; i<argp->size; i++) {
result = result + ( argp->X[i] * argp->Y[i] );
}
return &result;
}
Any idea ?
Thanks in advanced.