0
我实施异步模式反应器中C++,基于是Epoll。 首先,我们将通过调用函数为类file_descriptor存储模型和处理在反应堆模式
template<typename Handle>
void Reactor::register(int descriptor, Handle handle){
//add this descriptor to epoll for monitoring
//store this handle with the key is the descriptor
}
然后,该方法hand_events,它一直运行下去,被称为
void Reactor::handle_events(){
epoll_wait(..)
for(event in events){
//call the handle corresponding to the file descriptor return from epoll
//event.data.fd ==> handle
handle(...)
}
}
我的问题反应器注册文件描述符如何组织存储模型在这种情况下:店面手柄以及映射文件描述符和手柄之间(有没有它的任何合适的图案)
希望看到你的答案!
Pilebor:这是问题所在。我只是想概括我的反应堆模式==>我不想修复签名==>我使用了传递Handle的模板。 ==>你有任何其他的想法或知道如何boost :: asio解决这个问题? – khanhhh89 2013-05-11 04:21:26
@ khanhhh89注册你的事件处理程序时,你应该可以使用'std :: bind',就像在我更新的答案中一样。 – 2013-05-11 04:46:20
@ khanhhh89 Boost ASIO通过使用'std :: bind'或'boost :: bind'的函数绑定解决了这个问题,但仍然有一些固定的签名。处理程序_必须至少在_this_次序中使用_these_参数,但如果需要使用'bind'的魔法,它们可能需要更多。 – 2013-05-11 04:47:51