Пример #1
0
void CClient::OnRecv(zsummer::network::ErrorCode ec, int nRecvedLen)
{
	if (ec)
	{
		LOGD("remote socket closed");
		OnClose();
		return;
	}

	m_recving._len += nRecvedLen;

	int needRecv = zsummer::protocol4z::CheckBuffIntegrity(m_recving._orgdata, m_recving._len, _MSG_BUF_LEN);
	if ( needRecv == -1)
	{
		LOGD("killed socket: CheckBuffIntegrity error ");
		m_sockptr->DoClose();
		OnClose();
		return;
	}
	if (needRecv > 0)
	{
		m_sockptr->DoRecv(m_recving._orgdata+m_recving._len, needRecv, std::bind(&CClient::OnRecv, shared_from_this(), std::placeholders::_1, std::placeholders::_2));
		return ;
	}

	//! 解包完成 进行消息处理
	zsummer::protocol4z::ReadStream rs(m_recving._orgdata, m_recving._len);
	try
	{
		MessageEntry(rs);
	}
	catch (std::runtime_error e)
	{
		LOGD("MessageEntry catch one exception: "<< e.what() );
		m_sockptr->DoClose();
		OnClose();
		return ;
	}
	m_process.AddTotalRecvLen(m_recving._len);
	m_process.AddTotalRecvCount(1);
	//! 继续收包
	DoRecv();
}
Пример #2
0
bool CClient::OnRecv(unsigned int nRecvedLen)
{
	m_curRecvLen += nRecvedLen;
	

	std::pair<zsummer::protocol4z::INTEGRITY_RET_TYPE, zsummer::protocol4z::DefaultStreamHeadTraits::Integer> ret = zsummer::protocol4z::CheckBuffIntegrity<zsummer::protocol4z::DefaultStreamHeadTraits>(m_recving._orgdata, m_curRecvLen, _MSG_BUF_LEN);

	if (ret.first == zsummer::protocol4z::IRT_CORRUPTION)
	{
		LOGE("killed socket: CheckBuffIntegrity error ");
		m_socket->Close();
		return false;
	}
	if (ret.first == zsummer::protocol4z::IRT_SHORTAGE)
	{
		m_socket->DoRecv(m_recving._orgdata+m_curRecvLen, ret.second);
		return true;
	}

	//! 解包完成 进行消息处理
	zsummer::protocol4z::ReadStream<zsummer::protocol4z::DefaultStreamHeadTraits> rs(m_recving._orgdata, m_curRecvLen);
	try
	{
		MessageEntry(rs);
	}
	catch (std::runtime_error e)
	{
		LOGE("MessageEntry catch one exception: "<< e.what() );
		m_socket->Close();
		return false;
	}

	m_process->AddTotalRecvCount(1);
	m_process->AddTotalRecvLen(m_curRecvLen);
	//! 继续收包
	m_recving._len = 0;
	m_curRecvLen = 0;
	m_socket->DoRecv(m_recving._orgdata, 2);
	return true;
}
Пример #3
0
bool CClient::OnRecv(unsigned int nRecvedLen)
{
	m_curRecvLen += nRecvedLen;
	m_process->AddTotalRecvCount(1);
	m_process->AddTotalRecvLen(nRecvedLen);

	int needRecv = zsummer::protocol4z::CheckBuffIntegrity(m_recving._body, m_curRecvLen, _MSG_BUF_LEN);
	if ( needRecv == -1)
	{
		LOGE("killed socket: CheckBuffIntegrity error ");
		m_socket->Close();
		return false;
	}
	if (needRecv > 0)
	{
		m_socket->DoRecv(m_recving._body+m_curRecvLen, needRecv);
		return true;
	}

	//! 解包完成 进行消息处理
	zsummer::protocol4z::ReadStream rs(m_recving._body, m_curRecvLen);
	try
	{
		MessageEntry(rs);
	}
	catch (std::runtime_error e)
	{
		LOGE("MessageEntry catch one exception: "<< e.what() );
		m_socket->Close();
		return false;
	}
	//! 继续收包
	memset(&m_recving, 0, sizeof(m_recving));
	m_curRecvLen = 0;
	m_socket->DoRecv(m_recving._body, 2);
	return true;
}