- 论坛徽章:
- 0
|
服务器收到客户端的消息后进行数据操作,可以这样写吗?
void CServer::OnRecv(CContext *pContext, CBuffer *pBuffer)
{
...
...
Switch(recvOperateID)
{
case 0:
EnterCriticalSection(&m_Lock);
dataOperateID = 111;//数据操作ID(根据它判断数据操作的类型)
m_hDataOp = CreateThread(...,DataOpThread,&dataOperateID...);//建创线程进行数据操作
LeaveCriticalSection(&m_Lock);
SendMsg(.....);//发消息给客户端
break;
case 1:
EnterCriticalSection(&m_Lock);
dataOperateID = 2222;
m_hDataOp = CreateThread(...,DataOpThread,&dataOperateID...);
LeaveCriticalSection(&m_Lock);
SendMsg(.....);
break;
case 2:
....
}
}
DWORD WINAPI CServer: ataOpThread(LPVOID lpParam)
{
DataOprate *id = (DataOprate *)lpParam;
if ( id->value = xxx )
{
sql = xxxx;
}
else if ( id->value = xxx )
{
sql = xxxx;
}
....
} |
|