[ Previous | Next | Table of Contents | Index | Library Home | Legal | Search ]

Communications Programming Concepts


Using Multiple Program Versions Example

By convention, the first version number of the PROG program is referred to as PROGVERS_ORIG, and the most recent version is PROGVERS. For example, the programmer can create a new version of the user program that returns an unsigned short value rather than a long value. If the programmer names this version RUSERSVERS_SHORT, then the following program permits the server to support both programs:

if (!svc_register(transp, RUSERSPROG, RUSERSVERS_ORIG,
  nuser, IPPROTO_TCP)) {
    fprintf(stderr, "can't register RUSER service\n");
    exit(1);
}
if (!svc_register(transp, RUSERSPROG, RUSERSVERS_SHORT,
  nuser, IPPROTO_TCP)) {
    fprintf(stderr, "can't register RUSER service\n");
    exit(1);
}

Both versions can be handled by the same C procedure, as in the following example using the nusers procedure:

nuser(rqstp, transp)
    struct svc_req *rqstp;
    SVCXPRT *transp;
{
    unsigned long nusers;
    unsigned short nusers2;

    switch (rqstp->rq_proc) {
    case NULLPROC:
        if (!svc_sendreply(transp, xdr_void, 0)) {
            fprintf(stderr, "can't reply to RPC call\n");
                  return (1);
        }
        return;
    case RUSERSPROC_NUM:

        /*
         * Code here to compute the number of users
         * and assign it to the variable nusers 
         */
        nusers2 = nusers;
        switch (rqstp->rq_vers) {
        case RUSERSVERS_ORIG:
            if (!svc_sendreply(transp, xdr_u_long, 
            &nusers)) {
                fprintf(stderr,"can't reply to RPC call\n");
            }
            break;

        case RUSERSVERS_SHORT:
            if (!svc_sendreply(transp, xdr_u_short, 
            &nusers2)) {
                fprintf(stderr,"can't reply to RPC call\n");
            }
            break;
        }
    default:
        svcerr_noproc(transp);
        return;
    }
}


[ Previous | Next | Table of Contents | Index | Library Home | Legal | Search ]