提升asio自定义分配器处理程序io服务后编译错误

时间:2015-02-24 15:24:46

标签: c++ templates boost bind boost-asio

我正在进行io_service post调用,如下所示:

  _io_service.post(std::tr1::bind(&BlitzLogger::push,this,
                                    std::tr1::bind(&BlitzLogger::stringer<typename boost::decay<T const &>::type,
                                                   typename boost::decay<Args const &>::type ...>, this,
                                                   t, args ...)));

我怀疑绑定调用有一些可以消除的开销,所以我继续为处理程序布置自定义分配器,如

所述。
 http://www.boost.org/doc/libs/1_50_0/doc/html/boost_asio/example/allocation/server.cpp

在此之后,我想做点如下的事情:

_io_service.post(
    makeCustomAllocHandler(_allocator1,std::tr1::bind(&BlitzLogger::push,this,
    makeCustomAllocHandler(_allocator2,std::tr1::bind(&BlitzLogger::stringer<typename boost::decay<T const &>::type,
                                                      typename boost::decay<Args const &>::type ...>,this,t,args ...)))));

上面这段代码抛出编译时错误(模板参数扣除/替换失败的主机), 但是,如果我删除_io_service.post调用,并将其限制为

    makeCustomAllocHandler(_allocator1,std::tr1::bind(&BlitzLogger::push,this,
    makeCustomAllocHandler(_allocator2,std::tr1::bind(&BlitzLogger::stringer<typename boost::decay<T const &>::type,
                                                      typename boost::decay<Args const &>::type ...>,this,t,args ...))));

然后代码编译好了。

显然问题是makeCustomAllocHandler的返回类型不符合post函数的模板处理程序参数。

为什么会发生这种情况,以及如何解决这个问题。

1 个答案:

答案 0 :(得分:0)

要与makeCustomAllocHandler返回的CompletionHandler对象兼容,应定义void operator()(),而不是ReadHandler所需的void operator()(const boost::system::error_code&, std::size_t),并在服务器示例中使用。

相关问题