boost :: asio :: async_read不会调用处理程序并继续接收

时间:2013-09-12 20:14:51

标签: c++ sockets boost asynchronous boost-asio

boost :: asio :: async_read不会调用处理程序并继续接收,我试图接收一些我不知道它的长度的缓冲区,但是max是1024

#include "AsyncConnection.h"


AsyncConnection::AsyncConnection(boost::asio::io_service& io_service)
    : socket(io_service)
{
}


AsyncConnection::~AsyncConnection()
{
}

AsyncConnection::Pointer AsyncConnection::Create(boost::asio::io_service& io_service){
    return Pointer(new AsyncConnection(io_service));
}

boost::asio::ip::tcp::socket& AsyncConnection::GetSocket(){
    return socket;
}

void AsyncConnection::BeginReceive(){

    boost::asio::async_read(socket, boost::asio::buffer(buffer, 1024),
        boost::bind(&AsyncConnection::EndReceive, shared_from_this(),
        boost::asio::placeholders::error,
        boost::asio::placeholders::bytes_transferred));
}

void AsyncConnection::EndReceive(const boost::system::error_code& error, std::size_t bytes_transferred){
    if (!error){

    }
    else{
        std::cout << error.message() << std::endl;
    }
}

它永远不会调用EndReceive,我的猜测是它一直保持接收,直到缓冲区已满?!如何解决这个问题!

0 个答案:

没有答案