如何解决远程过程调用:如何在XDR文件中声明同一程序的两个版本
|| 我正在编写一个程序,该程序使RPC打印一条消息,该消息作为参数发送给远程功能。远程函数不应返回任何内容,但是出于好奇,我已将远程函数设计为返回整数。 无论如何,一切正常,我能够远程打印消息。现在,我正在尝试在XDR文件中创建程序的两个版本(只是好奇!!),但对我来说不起作用。 这是我的新XDR文件anirudh@anirudh-Aspire-5920:~/Documents/C/DS/RPC$ cat spec.x
program MSGPROG{
version PRINTMSGVERSION{
int PRINTMSG(string) = 1;
} = 1;
version PRINTMSGVERSION{
int PRINTMSG(string) = 1;
} = 2;
} = 0x2000001;
这是服务器代码:
anirudh@anirudh-Aspire-5920:~/Documents/C/DS/RPC$ cat server.c
#include<stdio.h>
#include \"spec.h\"
int *printmsg_1_svc(char **msg,struct svc_req * sr){
static int ret;
printf(\"version = 1--%s\\n\",*msg);
ret = 1;
return &ret;
}
int *printmsg_2_svc(char **msg,struct svc_req * sr){
static int ret;
printf(\"version = 2--%s\\n\",*msg);
ret = 1;
return &ret;
}
这是我在编译时遇到的错误:
anirudh@anirudh-Aspire-5920:~/Documents/C/DS/RPC$ rpcgen -C spec.x
anirudh@anirudh-Aspire-5920:~/Documents/C/DS/RPC$ gcc server.c spec_svc.c -o ani_server -lnsl
In file included from server.c:2:
spec.h:32: warning: \"PRINTMSGVERSION\" redefined
spec.h:18: note: this is the location of the previous definition
In file included from spec_svc.c:6:
spec.h:32: warning: \"PRINTMSGVERSION\" redefined
spec.h:18: note: this is the location of the previous definition
因此出现错误是因为我无法弄清楚如何在XDR文件中声明程序的两个版本。非常感谢您阅读我的文章。请帮帮我。提前致谢。
解决方法
\“版本名称在一个范围内不能出现多次
程序定义。版本号也不能多次出现
在程序定义的范围内。\“-RFC 1057
您只需为版本字符串指定不同的名称,例如:
program MSGPROG{
version PRINTMSGVERSION_1 {
int PRINTMSG(string) = 1;
} = 1;
version PRINTMSGVERSION_2{
int PRINTMSG(string) = 1;
} = 2;
} = 0x2000001;
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。