处理后立刻异步发送数据返回给客户端。客户端收到数据后,立刻继续发数据给服务器,服务器处理后返回客户端。这样一直反复,没有间断。
连接数大概在10个左右,每次发送的数据量不大,但是持续不到5分钟就报错误:
10055 由于系统缓冲区空间不足或队列已满,不能执行套接字上操作
请问是什么原因呢?是不是我boost asio用法上有问题?请哪位大侠知道的指点一下~谢谢!!
void SessionCtrl::InitAcceptSession()
{
BaseSession * _newSession = new InnerSession(m_IO_service,m_pAppImp,this,m_pStrand);
_newSession->Initalize();
m_acceptor.async_accept(_newSession->GetSocket(),
m_pStrand.wrap(boost::bind(&SessionCtrl::handle_accept,
this,
_newSession,
boost::asio::placeholders::error
)));
}
void SessionCtrl::handle_accept( BaseSession * pBaseSession, const boost::system::error_code& error )
{
if (error)
{
std::cout<<"SessionCtrl::handle_accept Error ID"<<error.value()<<" Message::"<<error.message()
<<" Is InnerNet"<<m_bIsInnerNet<<std::endl;
return;
}
//......
}
///////////////////////////////////////////////////////////////////////
void InnerSession::Connect(short nSerType,short nSerId)
{
m_pAppImp->GetInnerSessionMgr()->AddServerInfo(nSerType,nSerId,this);
m_Socket.async_connect(*m_pEndpoint,
m_Strand.wrap(boost::bind(&InnerSession::handle_connect,
this,
boost::asio::placeholders::error
,nSerId
,nSerType)));
}
void InnerSession::handle_connect(const boost::system::error_code &error,short nSerId,short nSerType)
{
if (error)
{
if (error.value() != boost::system::errc::operation_canceled)
{
std::cerr << boost::system::system_error(error).what() << std::endl;
}
m_pInnerSessionMgr->deleteServerInfo(nSerType,nSerId);
return;
}
}
bool InnerSession::Start()
{
static tcp::no_delay option(true);
m_Socket.set_option(option);
//_TEMP_BUFF_ASIO_RECIEVE_LEGNTH_ = 1024*30
boost::asio::socket_base::receive_buffer_size receSize(_TEMP_BUFF_ASIO_RECIEVE_LEGNTH_);
m_Socket.set_option(receSize);
boost::asio::async_read(
m_Socket,
boost::asio::buffer(m_buf,gTempBufLen),
transfer_at_least(1),
m_Strand.wrap(boost::bind(&InnerSession::handle_read,
this,
boost::asio::placeholders::error,
boost::asio::placeholders::bytes_transferred)));
return true;
}
void InnerSession::handle_read( const boost::system::error_code& error, size_t bytes_transferred )
{
if (error || bytes_transferred == 0)
{
std::cout<<"handle_read Error ID"<<error.value()<<error.message()<<std::endl;
std::cout<<"bytes_transferred is "<<bytes_transferred<<std::endl;
return;
}
//处理收来的数据
HandleRecData(error,bytes_transferred);
boost::asio::async_read(
m_Socket,
boost::asio::buffer(m_buf,gTempBufLen),
transfer_at_least(1),
m_Strand.wrap(boost::bind(&InnerSession::handle_read,
this,
boost::asio::placeholders::error,
boost::asio::placeholders::bytes_transferred)));
}
void InnerSession::handle_write( const boost::system::error_code& error, size_t bytes_transferred,char *pBuff )
{
if (error)
{
std::cout<<"InnerSession::handle_write Error ID"<<error.value()<<error.message()<<std::endl;
if (pBuff != NULL)
{
if(!m_pAppImp->GetBaseApp()->GetSendMessageMemory()->freePool(pBuff))
{
delete []pBuff;
pBuff = NULL;
}
}
boost::asio::async_read(
m_Socket,
boost::asio::buffer(m_buf,gTempBufLen),
transfer_at_least(1),
m_Strand.wrap(boost::bind(&InnerSession::handle_read,
this,
boost::asio::placeholders::error,
boost::asio::placeholders::bytes_transferred)));
return;
}
if (pBuff != NULL)
{
if(!m_pAppImp->GetBaseApp()->GetSendMessageMemory()->freePool(pBuff))
{
// free(pBuff);
// pBuff = NULL;
}
}
boost::asio::async_read(
m_Socket,
boost::asio::buffer(m_buf,gTempBufLen),
transfer_at_least(1),
m_Strand.wrap(boost::bind(&InnerSession::handle_read,
this,
boost::asio::placeholders::error,
boost::asio::placeholders::bytes_transferred)));
}
//异步发送数据
void InnerSession::SendPack(char *&pBuff, size_t Length )
{
if(!m_Socket.is_open())
{
std::cout<<"InnerSession::SendPack(char *pBuff, size_t Length )"<<"m_Socket is not open"<<endl;
if (pBuff != NULL)
{
if(!m_pAppImp->GetBaseApp()->GetSendMessageMemory()->freePool(pBuff))
{
delete []pBuff;
pBuff = NULL;
}
}
return;
}
boost::asio::async_write(m_Socket,
boost::asio::buffer(pBuff,Length),
m_Strand.wrap(boost::bind(&InnerSession::handle_write,
this,
boost::asio::placeholders::error,
boost::asio::placeholders::bytes_transferred,
pBuff)));
}
//同步发送数据
void InnerSession::SynSendPack(char *&pBuff, size_t Length )
{
boost::system::error_code ec;
m_Socket.write_some(boost::asio::buffer(pBuff,Length),ec);
if (ec)
{
}
if(!TOFBaseApp::Instance()->GetSendMessageMemory()->freePool(pBuff))
{
delete []pBuff;
pBuff = NULL;
}
}
3 个解决方案
#1
请大神帮忙看下哇.
#2
不要立即,要等到对方发送收到消息在继续,否则,会死了很惨,要是想多活会,建议wi7 x64 12G内存
#3
建议去这个专业的boost论坛上去问下, http://avboost.com/ 我和版主认识啊, 哈哈
#1
请大神帮忙看下哇.
#2
不要立即,要等到对方发送收到消息在继续,否则,会死了很惨,要是想多活会,建议wi7 x64 12G内存
#3
建议去这个专业的boost论坛上去问下, http://avboost.com/ 我和版主认识啊, 哈哈