Cross-platform general purpose C++ RPC library [closed]

大城市里の小女人 提交于 2019-12-21 03:00:50

问题


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:

  1. Application-plug-in interaction can be reenterable (e.g. application calls f1() from plug-in, in f1() plug-in calls g1() from application, in g1() application calls f2() from plug-in and so on...)
  2. Any such reenteration should be executed exactly by the same thread, which started the sequence

Where can I find a cross-platform C++ RPC library with such features?


回答1:


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:

http://www.xmlrpc.com/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...



来源:https://stackoverflow.com/questions/3061569/cross-platform-general-purpose-c-rpc-library

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!