这里是任务:想象一下,我们有一个应用程序和一个插件(动态库)。 应用程序和插件之间的接口是完全定义的。 现在我需要在不同的计算机上运行应用程序和插件。我在运行实际应用程序的计算机上为插件编写了一个存根。应用程序加载它并调用它的函数,就像它是一个本地插件。在另一台计算机上有一个存根,而不是真正的应用程序,它加载本机插件。 现在我需要通过网络在我的存根之间组织RPC,不管是什么传输。 通常,这不难。但有一些限制:
在哪里可以找到具有此类功能的跨平台C ++ RPC库?
解决方案限制#1是完全合理的,只要任何机器上的函数都没有像在RPC上锁定一个mutex 。
我不完全确定#2是可能的 - 让我们假设你的呼叫是阻塞的;当g1()调用f2()时,RPC机制不能在与f1()相同的线程上执行f2(),因为f1()被间接地阻塞等待其结果!
如果你的调用是异步的,可以在等待f1()完成时轮询RPC系统,并在同一个线程中执行f2()。你不应该这样做;这意味着任何等待RPC完成的异步调用可能会在调用的RPC被推入调用堆栈时突然阻塞。
是否有特定的原因你想要这种行为?
在任何情况下,Googling的跨平台rpc都会提供不少结果;我想,如果你忽略第二个限制,任何他们将适合你的帐单。 XML-RPC是最好的结果之一,并且有一些C ++实现:
www.xmlrpc/directory/1568/implementations
编辑: 经过一些Google搜寻,我找不到一个完全符合您要求的图书馆。它们似乎都是阻塞或异步多线程。如果你真的需要实现限制#2,你必须手工做。使用 boost :: asio 将是一个很好的开始跨平台通信的目的。我仍然没有看到你想做什么和第二个线程中调用处理函数之间的区别,而第一个阻塞,但... ...
Here's the task: Imagine, we have an applications and a plug-in for it (dynamic library). Interface between the application and the plug-in is completely defined. Now I need to run the application and the plug-in on different computers. I wrote a stub for the plug-in on a computer where the real applications is running. And the application loads it and calls its functions like if it were a native plug-in. On the other computer there's a stub instead of the real application, which loads the native plug-in. Now I need to organize RPCs between my stubs over the network, regardless the very transport. Usually, it's not difficult. But there're some restrictions:
Where can I find a cross-platform C++ RPC library with such features?
解决方案Restriction #1 is perfectly reasonable, so long as none of the functions on either machine do anything like locking a mutex across an RPC.
I'm not entirely sure #2 is possible -- let's assume that your calls are blocking; when g1() calls f2(), the RPC mechanism can't execute f2() on the same thread as f1(), as f1() is blocked indirectly waiting on its result!
If your calls are instead asynchronous, it is possible to poll the RPC system while waiting for f1() to complete, and have it execute f2() in the same thread. You shouldn't do this, though; it means that any async call waiting for an RPC completion can suddenly "block" when the invoked RPC is pushed onto the callstack.
Is there a specific reason you want this behaviour?
In any case, Googling "cross platform rpc" comes up with quite a few results; I imagine any of them would fit your bill if you ignore the second restriction. XML-RPC was one of the top results, and there are a number of C++ implementations:
www.xmlrpc/directory/1568/implementations
EDIT: After some Googling I can't find a single library that does precisely what you're asking. They all appear to be either blocking or asynchronous multithreaded. If you really need to implement restriction #2, you're going to have to do it by hand. Use of boost::asio would be a good starting point for cross-platform communication. I still don't see the difference between what you want to do and calling the handler function in a second thread while the first one is blocking, however...
更多推荐
跨平台通用C ++ RPC库
发布评论