在动态加载的库之间共享 boost::asio::io_service 对象
首先,我做了什么(如果不仅仅是我在做一些简单的愚蠢的事情,将提供最小示例):
我有一个 GUI 应用程序,该应用程序应支持多个网络接口来更改 GUI 中显示的内容。网络接口被实现为在 GUI 启动时动态加载的插件。 GUI 应用程序提供了一个 boost::asio::io_service 对象,它通过对接口的引用传递该对象,以便它们可以使用它来构建异步 I/O。在 GUI 线程中,轮询该 io_service 对象以同步网络接口对内容的访问。
现在的问题是,当 io_service 对象被轮询时,处理程序不会被调用。为了缩小范围,我只实现了一个接口并在其中创建了 io_service 对象,仍然从 GUI 线程调用轮询并且有效。
我现在的问题是:将 io_service 对象传递到运行时加载的 DLL 函数中是否可能存在普遍问题?
如果场景太不清楚,我将提供一个最小的示例。
编辑:我觉得真的很愚蠢:)只是拼凑了一个最小的例子,当然,它就像一个魅力。这几乎意味着问题源于软件的其他部分。
感谢大家的意见!
为了使这个问题至少有点用: 任何想要做类似事情的人(通过 boost::asio::io_service 同步网络的插件),您可以下载最小示例 这里。
First what I did (minimum sample will be provided if it's not just me doing something plain stupid):
I have a GUI application that shall support several network interfaces to change content that's displayed in the GUI. The network interfaces are realized as plugins that are dynamically loaded on GUI startup. The GUI application provides a boost::asio::io_service object that it passes via reference to the interfaces so they can use that to build the asynchronous I/O. In the GUI thread this io_service object is than polled to synchronise the network interfaces' access to the content.
The problem now is that the handlers don't get called by the io_service object when it is polled. To narrow this down I implemented only one interface and created the io_service object therein, still calling the poll from the GUI thread and that works.
My question now is: is it possible that there is a general problem with passing the io_service object into DLL functions loaded at runtime?
If the scenario is too unclear, I'll provide a minimum example.
EDIT: I feel really stupid :) Just hacked together a minimum example and that - of course - works like a charm. That pretty much means the problem origins from some other part of the software.
So thanks everyone for their input!
To make this question at least a little bit useful:
Anyone who wants to do something similar (plugins for network synchronized via boost::asio::io_service), you can download the minimum example here.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我会检查几个选项:
* 也许该对象在某个时刻被复制而不是通过引用传递;你可以将其设置为 boost::noncopyable 来防止这种情况发生。
* 检查 poll 的返回值是否大于 0 某个处理程序已运行;如果它是 0,则问题是 boost 认为没有处理程序。
* 在 GUI 应用程序中添加测试处理程序以排除与 DLL 相关的问题。
调试愉快!
I would check several options:
* Maybe the object is copied at some point rather than passed by reference; you can make it boost::noncopyable to prevent this from happening.
* Check the return value of poll if it is bigger than 0 some handler was run; if it is 0 the problem is boost think there are no handler.
* Add a test handler in your GUI app to rule out the option it is DLL-related problem.
Happy debugging!