[英]How to share boost::asio::io_service across plugins [modules]
I would like to implement a single threaded application which also provides a plugin/module API. 我想实现一个单线程应用程序,该应用程序还提供插件/模块API。 My application is using a static
io_service
instantiated/initialized in a class method. 我的应用程序使用在类方法中实例化/初始化的静态
io_service
。 It might be called a singleton by some. 有些人可能将其称为单例。 Would it be a good idea to make this available to the plugin implementors?
将其提供给插件实现者是一个好主意吗?
boost::io_service& SomeClass::IOS()
{
static boost::io_service ios;
return ios;
}
First I thought of allowing the plugins to provide only file descriptors and the application wrapping them as stream_descriptor
objects but this would prevent the io_object
specific functionalities provided by boost; 首先,我考虑允许插件仅提供文件描述符,而应用程序将它们包装为
stream_descriptor
对象,但这会阻止boost提供的io_object
特定功能; this is the reason I thought of providing the static io_service
to the plugin implementors and restricting them to using io_object
instances only. 这就是我考虑为插件实现程序提供静态
io_service
并将其限制为仅使用io_object
实例的原因。
I think there's no problem in exposing directly io_service
as a singleton, if your architecture is based on boost::asio
. 我认为,如果您的体系结构基于
boost::asio
,则直接将io_service
作为单例公开是没有问题的。
The issues about ABI are common to every C++ plugin architectue, and not specific to boost::asio
. 关于ABI的问题对于每个C ++插件架构师来说都是常见的,并不是特定于
boost::asio
。 So, wrapping the io_service
(as suggested by Richard) is not a solution to this problem, but just a way to hide the decision to use asio
. 因此,包装
io_service
(由Richard建议)不是解决此问题的方法,而只是隐藏使用asio
的决定的一种方法。
BTW: I guess you want to allow the plugins to manage I/O through asio
, and the main application dispatch the tasks, so it wouldn't be enough for your wrapper to expose post
and dispatch
(useless for the plugins), you should instead provide eg sockets and other I/O methods. BTW:我想你想允许插件管理I / O通过
asio
,主要应用调度的任务,所以它不会满足你的包装揭露post
和dispatch
(无用插件),你应该而是提供例如套接字和其他I / O方法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.