本文整理汇总了C++中SocketPtr::GetBuffer方法的典型用法代码示例。如果您正苦于以下问题:C++ SocketPtr::GetBuffer方法的具体用法?C++ SocketPtr::GetBuffer怎么用?C++ SocketPtr::GetBuffer使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SocketPtr
的用法示例。
在下文中一共展示了SocketPtr::GetBuffer方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: OnRecvBody
void AcceptSession::OnRecvBody(SocketPtr socket_ptr, const boost::system::error_code& error)
{
if (!error)
{
m_network_mgr->OnRecv(socket_ptr);
if (socket_ptr->GetSocket().is_open())
{
socket_ptr->ChangeBufferSize(MESSAGE_HEADER_LENGTH);
boost::asio::async_read(socket_ptr->GetSocket(),
boost::asio::buffer(socket_ptr->GetBuffer(), MESSAGE_HEADER_LENGTH),
boost::bind(&AcceptSession::OnRecvHead, this, socket_ptr, boost::asio::placeholders::error));
}
}
else
{
if (error == boost::asio::error::eof)
{
std::stringstream ss;
ss << "AcceptSession::OnRecvBody Error : " << error.message();
DebugMessage::GetInstance()->ShowMessage(DebugMessageType::BASE_NETWORK, ss.str());
}
if (NULL != m_network_mgr && socket_ptr->GetSocket().is_open())
m_network_mgr->OnDisconnect(socket_ptr);
}
}
示例2: OnRecvHead
void AcceptSession::OnRecvHead(SocketPtr socket_ptr, const boost::system::error_code& error)
{
if (!error)
{
char *read_buff = socket_ptr->GetBuffer();
MessageHeader body_length = *(MessageHeader*)(read_buff);
socket_ptr->ChangeBufferSize(body_length);
boost::asio::async_read(socket_ptr->GetSocket(),
boost::asio::buffer(socket_ptr->GetBuffer(), body_length),
boost::bind(&AcceptSession::OnRecvBody, this, socket_ptr, boost::asio::placeholders::error));
}
else
{
std::stringstream ss;
ss << "AcceptSession::OnRecvHead Error : " << error.message();
DebugMessage::GetInstance()->ShowMessage(DebugMessageType::BASE_NETWORK, ss.str());
if (NULL != m_network_mgr && socket_ptr->GetSocket().is_open())
m_network_mgr->OnDisconnect(socket_ptr);
}
}
示例3: OnAccept
void AcceptSession::OnAccept(SocketPtr socket_ptr, const boost::system::error_code& error)
{
if (!error)
{
m_network_mgr->OnAccept(socket_ptr);
//socket_ptr->ChangeBufferSize(MESSAGE_HEADER_LENGTH);
socket_ptr->ChangeBufferSize(MESSAGE_HEADER_LENGTH);
boost::asio::async_read(socket_ptr->GetSocket(),
boost::asio::buffer(socket_ptr->GetBuffer(), MESSAGE_HEADER_LENGTH),
boost::bind(&AcceptSession::OnRecvHead, this, socket_ptr, boost::asio::placeholders::error));
this->AsyncListen();
}
else
{
std::stringstream ss;
ss << "AcceptSession::OnAccept Error : " << error.message();
DebugMessage::GetInstance()->ShowMessage(DebugMessageType::BASE_NETWORK, ss.str());
}
}