首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

boost:asio 中async_write函数中的绑定函数未被调用,该怎么解决

2013-08-01 
boost::asio 中async_write函数中的绑定函数未被调用我刚刚接触socket编程,有很多不懂的地方,希望大家多多

boost::asio 中async_write函数中的绑定函数未被调用
我刚刚接触socket编程,有很多不懂的地方,希望大家多多指教啊
在类的成员函数SengmsgFromSocket中,我调用async_write发送数据包

void wiimote_linux::SendmsgFromSocket(unsigned char data_type,unsigned char bc,float p0,float p1,float p2)
 {
   static unit_data ud;

   ud.data_type = data_type;
   ud.button_char = bc;
   float2char(p0,ud.pa0);
   float2char(p1,ud.pa1);
   float2char(p2,ud.pa2);

   qud.push(ud);

   async_write(
   socket_,
       buffer(&qud.front(),
      sizeof(qud.front())),
       bind(&wiimote_linux::write_handler,this,placeholders::error)
       );
 }

qud是一个队列
write_handle函数如下:



void wiimote_linux::write_handler(const system::error_code& ec)
{
  if(ec)
    {
      cout << "error in write_handler()" << endl;
      return ;
    }
  else{
    cout << "send complete in write_handler " << endl;

    if(!qud.empty())
      {
    async_write(
        socket_,
        buffer(&qud.front(),
       sizeof(qud.front())),
        bind(&wiimote_linux::write_handler,
     this,
     placeholders::error));
      }
    qud.pop();
  }
}

我跟踪进去看,发现write_handler函数从来没有被调用过,这是为什么啊,io_service::run()我已经在main函数中调过了。
这个问题已经困扰了好多天了。
网上的一些教程都是简单的字符串发送,我要做的是采集外部设备的按键消息,然后通过socket发给服务端。
------解决方案--------------------


这里有一个async方式发送文件的例子
http://onegazhang.wordpress.com/2009/09/22/file-transfer-over-asynchronous-tcp-connection-via-boost-asio/

热点排行