C跨平台RPC需要最少的样板?

时间:2023-02-15 12:20:14

I have an existing library in C, which I want to be able to allow remote access to (either from Linux or Windows).

我在C中有一个现有的库,我希望能够允许远程访问(从Linux或Windows)。

I looked at the usual RPC suspects like Thrift and Protobuf, but neither of these deal cleanly with C-style function calls (things like pass-by-ref, char* instead of string, * instead of List<> etc).

我查看了常见的RPC嫌疑人,如Thrift和Protobuf,但这些都没有干净地处理C风格的函数调用(像pass-by-ref,char *而不是string,*而不是List <>等)。

In short, to use either of these it looks like I would need to write a complete IDL from scratch, and add a lot of boilerplate code to transfer C-style function calls into these environments.

简而言之,要使用其中任何一个,我看起来需要从头开始编写完整的IDL,并添加许多样板代码以将C样式函数调用传递到这些环境中。

Are there any RPC libraries around that

是否有任何RPC库

  • can deal directly with C header files (or have tools to auto generate the initial IDL from C definitions)?
  • 可以直接处理C头文件(或者有工具从C定义自动生成初始IDL)?
  • are cross-platform Linux/Windows compatible?
  • 是跨平台的Linux / Windows兼容吗?
  • require the absolute minimum of boilerplate code?
  • 要求绝对最小的样板代码?
  • support sockets
  • 支持套接字
  • are relatively high performance (XML-RPC i'm looking at you)?
  • 性能相对较高(XML-RPC我在看你)?

1 个解决方案

#1


1  

Well, there's protobuf-c, an implementation of protobuf in C.

好吧,有protobuf-c,在C中实现protobuf。

And then there's the classical XDR, found on most/(all?) unix-like systems, versions exist for windows as well. See also the Linux xdr(3) man page which contains an overview of the API.

然后是大多数/(所有?)unix类系统中的经典XDR,也存在用于Windows的版本。另请参见Linux xdr(3)手册页,其中包含API概述。

Note that both protobuf and XDR are serialization libraries, they don't provide RPC. The "companion RPC library" to XDR is called, well, RPC, but I don't think anyone writes new code with that, and AFAICS it's unix-specific (portmap doesn't run on windows, does it? And it's generally a bad idea anyway.). Then there's protobuf-c-rpc which is the C version of the protobuf RPC library; probably a better bet than classic RPC.

请注意,protobuf和XDR都是序列化库,它们不提供RPC。 XDR的“伴随RPC库”被称为RPC,但是我不认为有人用它编写新代码,而AFAICS它是特定于unix的(portmap不能在windows上运行,是吗?它通常是不管怎样,这个坏主意。)然后是protobuf-c-rpc,它是protobuf RPC库的C版本;可能比经典RPC更好的选择。

#1


1  

Well, there's protobuf-c, an implementation of protobuf in C.

好吧,有protobuf-c,在C中实现protobuf。

And then there's the classical XDR, found on most/(all?) unix-like systems, versions exist for windows as well. See also the Linux xdr(3) man page which contains an overview of the API.

然后是大多数/(所有?)unix类系统中的经典XDR,也存在用于Windows的版本。另请参见Linux xdr(3)手册页,其中包含API概述。

Note that both protobuf and XDR are serialization libraries, they don't provide RPC. The "companion RPC library" to XDR is called, well, RPC, but I don't think anyone writes new code with that, and AFAICS it's unix-specific (portmap doesn't run on windows, does it? And it's generally a bad idea anyway.). Then there's protobuf-c-rpc which is the C version of the protobuf RPC library; probably a better bet than classic RPC.

请注意,protobuf和XDR都是序列化库,它们不提供RPC。 XDR的“伴随RPC库”被称为RPC,但是我不认为有人用它编写新代码,而AFAICS它是特定于unix的(portmap不能在windows上运行,是吗?它通常是不管怎样,这个坏主意。)然后是protobuf-c-rpc,它是protobuf RPC库的C版本;可能比经典RPC更好的选择。