简体   繁体   中英

rpc pointer not showing the right result

So I'm trying to use some RPC function.

Basically I want to multiply 2 2*2 matrices, the client send 2 matrices the client calculates and sends the matrix.

The matrix received in my client isn't the one I sent.

// server.c
matrice* multiply(matrice2 *m2)
{ 
    matrice* res=&(matrice){.w=0.0,.x=0.0,.y=0.0,.z=0.0};
    res->w=m2->m.w*m2->n.w+m2->m.x*m2->n.y; // ww'+xy'
    res->x=m2->m.w*m2->n.x+m2->m.x*m2->n.z; // wx'+xz'
    res->y=m2->m.y*m2->n.w+m2->m.z*m2->n.y; // yw'+zy'
    res->z=m2->m.y*m2->n.x+m2->m.z+m2->n.z; // yx'+z'z

    return res;
}

int main(void)
{
    ...
    stat = registerrpc(PROGNUM, VERSNUM,PROCNUM, multiply, (xdrproc_t)xdr_matrice2, (xdrproc_t)xdr_matrice);
    svc_run();
}

//client.c
int main (int argc, char **argv)
{
    matrice m={1.0,2.0,3.0,4.0};
    matrice n={9.0,8.0,7.0,6.0};
    matrice2 donnees = {m , n};
    stat = callrpc(host, PROGNUM, VERSNUM, PROCNUM, (xdrproc_t) xdr_matrice2, (char *)&donnees, (xdrproc_t)xdr_matrice, (char *)&res);
}

//include.h
typedef struct { double w; double x; double y; double z; } matrice;
typedef struct { matrice m; matrice n; } matrice2;
bool_t xdr_matrice(XDR *, matrice *);
bool_t xdr_matrice2(XDR *, matrice2 *);

//xdr_matrice.c
bool_t xdr_matrice(XDR *xdrs, matrice *m)
{
    return xdr_double(xdrs,&(m->w)) && xdr_double(xdrs,&(m->x)) && xdr_double(xdrs,&(m->y)) && xdr_double(xdrs,&(m->z));
}

bool_t xdr_matrice2(XDR *xdrs, matrice2 *m2)
{
    return xdr_matrice(xdrs,&(m2->m)) && xdr_matrice(xdrs,&(m2->n));
}

Can someone explain me why it isn't working properly or which error I made ?

这真的很愚蠢,我只是将我的乘法函数更改为具有静态res (并且显然是return &res并更改为->. ),它确实有效。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM