发送错误:
std::vector<boost::asio::const_buffer> reply::to_buffers()
{
std::vector<boost::asio::const_buffer> buffers;
char header[HEADERLEN];
auto short_len = (unsigned short) packetSize;
m_hston_(short_len,header,0);
m_hston_(cmd,header,2);
m_hiton_(serialNBR,header,4);
buffers.push_back(boost::asio::buffer((char*)header,HEADERLEN));
buffers.push_back(boost::asio::buffer((char*)data,packetSize-8));
return buffers;
}
发送正确:
std::vector<boost::asio::const_buffer> reply::to_buffers()
{
std::vector<boost::asio::const_buffer> buffers;
char header[HEADERLEN];
auto short_len = (unsigned short) packetSize;
m_hston_(short_len,header,0);
m_hston_(cmd,header,2);
m_hiton_(serialNBR,header,4);
char sendmsg[8190];
memcpy(sendmsg,header,HEADERLEN);
memcpy(sendmsg+HEADERLEN,data,packetSize-8);
buffers.push_back(boost::asio::buffer(sendmsg,packetSize));
//buffers.push_back(boost::asio::buffer((char*)header,HEADERLEN));
//buffers.push_back(boost::asio::buffer((char*)data,packetSize-8));
return buffers;
}
boost::asio::async_write(socket_, reply_.to_buffers(),
strand_.wrap(
boost::bind(&connection::handle_write, shared_from_this(),
boost::asio::placeholders::error)));