标签:des io os 数据 on c cti amp ad
防止内存的重复开辟:Free 而不 Destory
参数说明:
lpFreeSocketList:服务端数据结构中保存的退出的客户对象链表头
lpSocketListCs:临界区指针
s:SOCKET对象
LPSOCKET_OBJ GetSocketObj(LPSOCKET_OBJ * lpFreeSocketList, CRITICAL_SECTION * lpSocketListCs, SOCKET s)
{
LPSOCKET_OBJ lpSockObj = NULL;
EnterCriticalSection(lpSocketListCs);
if(*lpFreeSocketList)
{
lpSockObj = *lpFreeSocketList;
*lpFreeSocketList = lpSockObj->lpNext;
lpSockObj->lpNext = NULL;
}
else
{
lpSockObj = (LPSOCKET_OBJ)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(SOCKET_OBJ));
if(lpSockObj != NULL)
{
InitializeCriticalSection(&lpSockObj->SockCritSec);
}
}
LeaveCriticalSection(lpSocketListCs);
// Initialize the members
if(lpSockObj)
{
lpSockObj->s = s;
lpSockObj->lpUserData = NULL;
lpSockObj->lClosingStatus = 0;
memset(lpSockObj->szPeerAddr, 0, sizeof(lpSockObj->szPeerAddr));
}
return lpSockObj;
}
标签:des io os 数据 on c cti amp ad
原文地址:http://www.cnblogs.com/lp-blogs/p/3998362.html