了解XDR规范以创建* .x文件 [英] Understanding XDR specification to create a *.x file

查看:255
本文介绍了了解XDR规范以创建* .x文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在浏览Internet上的多个网站,实际上想知道我们如何在 .x 文件中编写规范以在 中生成等效功能.c 文件用于RPC.我访问的每个站点建议在 *.x 文件中使用以下类型的规范:

I have been looking through several websites on the Internet and actually wanted to know how do we write specification in a .x file to generate equivalent functions in .c file for RPC. Every site I visited suggested to use following kind of specification in *.x file:

program ADD_PROG { 
    version ADD_VERS { 
        int ADD(intpair) = 1; 
    } = 1; 
} = 0x23451111;

因此,从实践上来说,我获得了 gm_protocol.x 来自称为ganglia的开源项目,并生成了等效的C源代码( gm_protocol_xdr.c )和C头文件( gm_protocol.h )使用rpcgen.

So, to understand practically, I obtained gm_protocol.x from an open-source project known as ganglia and generated equivalent C source code (gm_protocol_xdr.c) and C header file (gm_protocol.h) using rpcgen.

[rohit@ganglia-server rpc]$ rpcgen -C gm_protocol.x 
[rohit@ganglia-server rpc]$ 
[rohit@ganglia-server rpc]$ ll
total 24
-rw-rw-r-- 1 rohit rohit 5786 Oct 28 17:52 gm_protocol.h
-rw-rw-r-- 1 rohit rohit 3485 Oct 28 15:04 gm_protocol.x
-rw-rw-r-- 1 rohit rohit 8213 Oct 28 17:52 gm_protocol_xdr.c

令我惊讶的是,据我了解和了解,gm_protocol.x不包含上面代码所示的任何此类RPC规范,但仍会在文件gm_protocol_xdr.c中生成太多功能.

To my surprise, from what I have learned and understood, gm_protocol.x doesn't contain any such RPC specifications shown as code above but still it can generate too many functions in the file gm_protocol_xdr.c.

几乎可以肯定,我无法理解XDR规范,因为我咨询了错误的来源或它们已过时.我找不到任何可以解释生成函数的方法的教程(尽管我已经找到了生成struct,enum,union等的规范.)

It is pretty much sure that I am not able to understand the XDR specifications because either I have consulted wrong sources or they are outdated. I could not find any tutorial which could explain the way to generate functions (Although I have found specifications to generate struct, enum, union, etc).

请帮助学习这些规范.

推荐答案

通常,从.x文件中,您生成三个组"的代码:消息xdr编码器/解码器功能,客户端存根和服务器存根(好了,您可以也可以手动进行,但要使其正确处理,这是一项繁重的工作).使用-a选项运行rpcgen也会生成客户端,服务器信息和示例实现.首先尝试使用一个简单的示例:

Typically, from .x file you generate three 'groups' of code: message xdr encoder/decoder functions, client stub and server stub ( well, you can do it by hand as well, but it's too much work to get it right ). Run rpcgen with -a option too generate client, server sthus and an example implementation. Try to use a simple example first:

program STRLEN {
  version STRLENVERS {
    int strlen(string) = 1;
  } = 1;
} = 117;

规范program是RPCL但XDR语言的一部分.如果将上述规格放在 test.x 文件中并使用rpcgen -C test.x运行,则他/她将得到

The specification program is a part of RPCL but XDR language. If one puts above specifications in a test.x file and run it using rpcgen -C test.x, then he/she would just get

test.h, test_svc.c, test_clnt.c

test.h, test_svc.c, test_clnt.c

如果不需要任何服务器或客户端存根,而只需要XDR的编码器和解码器功能,则文件 gm_protocol.x 中的每个规范(例如枚举,结构,联合等)都将是在 gm_protocol.h 中生成为其等效的基于C的声明,并在 gm_protocol_xdr.c 中生成其相应的XDR编码器和解码器功能,这是在问题中指定的情况.

If one doesn't need any server or client stubs and just need encoder and decoder functions of XDR then every specifications such as enum, struct, union, etc in the file gm_protocol.x would be generated into their equivalent C based declarations in gm_protocol.h and their corresponding XDR encoder and decoder functions would be generated in gm_protocol_xdr.c, which is the case specified in the question.

运行rpcgen -a gm_protocol.x会生成 gm_protocol_svc.c gm_protocol_clnt.c ,而没有任何功能.

Running rpcgen -a gm_protocol.x would generate gm_protocol_svc.c and gm_protocol_clnt.c without any functions.

以下是一些XDR规范:

Below are some XDR specifications:

检查旧的SUN文档 http://www.shrubbery.net/solaris9ab/SUNWdev/ONCDG/toc.html

这篇关于了解XDR规范以创建* .x文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆