消息缓冲区
每个cellclient都有自己的发送缓冲区和接收缓冲区,这两个缓冲区的功能是相近的,为了容纳每个客户端发送过来的数据,进行处理。
CELLBuffer.hpp
Cellclient.cpp的改变
Cellserver.cpp的改变
“`c++
#ifndef _CELL_SERVER_HPP_
#define _CELL_SERVER_HPP_
#include"CELL.hpp"
#include"INetEvent.hpp"
#include"CELLClient.hpp"
#include"CELLSemaphore.hpp"
#include<vector>
#include<map>
//网络消息接收处理服务类
class CELLServer
{
public:
<pre><code>//接收数据 处理粘包 拆分包
int RecvData(CELLClient* pClient)
{
//接收客户端数据
int nLen = pClient->RecvData();
if (nLen <= 0)
{
return -1;
}
//触发<接收到网络数据>事件
_pNetEvent->OnNetRecv(pClient);
//循环 判断是否有消息需要处理
while (pClient->hasMsg())
{
//处理网络消息
OnNetMsg(pClient, pClient->front_msg());
//移除消息队列(缓冲区)最前的一条数据
pClient->pop_front_msg();
}
return 0;
}
</code></pre>
};
#endif // !<em>CELL_SERVER_HPP</em>
“`