📄 httpsocketmgr.cpp
字号:
#include "HTTPSocketMgr.h"
HTTPSocketMgr * HTTPSocketMgr::mgr = NULL;
//
//将inFD存放在hash table中
//
void HTTPSocketMgr::PutInFD(int inFD, char * v_sessionID)
{
CHTTPSession *pHTTPSession = (CHTTPSession *)m_httpsessionTable->Lookup(v_sessionID);
if(pHTTPSession == NULL){
pHTTPSession = new CHTTPSession();
pHTTPSession->infd = inFD;
pHTTPSession->outfd = 0;
pHTTPSession->pClient = NULL;
m_httpsessionTable->Add(v_sessionID, pHTTPSession);
}
else{
pHTTPSession->infd = inFD;
}
}
//
//将outFD存放在hash table中
//
void HTTPSocketMgr::PutOutFD(int outFD, char * v_sessionID)
{
CHTTPSession *pHTTPSession = (CHTTPSession *)m_httpsessionTable->Lookup(v_sessionID);
if(pHTTPSession == NULL){
pHTTPSession = new CHTTPSession();
pHTTPSession->outfd = outFD;
pHTTPSession->infd = 0;
pHTTPSession->pClient = NULL;
m_httpsessionTable->Add(v_sessionID, pHTTPSession);
}
else{
pHTTPSession->outfd = outFD;
}
}
//
//将ClientSession存放在hash table中
//
void HTTPSocketMgr::PutClientSession(CClientSession * pClient, char * v_sessionID)
{
CHTTPSession *pHTTPSession = (CHTTPSession *)m_httpsessionTable->Lookup(v_sessionID);
if(pHTTPSession == NULL){
pHTTPSession = new CHTTPSession();
pHTTPSession->pClient = pClient;
pHTTPSession->infd = 0;
pHTTPSession->outfd = 0;
m_httpsessionTable->Add(v_sessionID, pHTTPSession);
}
else{
pHTTPSession->pClient = pClient;
}
}
//
//从hash table中取得session对应的FD
//
OS_Error HTTPSocketMgr::Get(int &outFD, CClientSession ** ppClient, char * v_sessionID)
{
CHTTPSession *pHTTPSession = (CHTTPSession *)m_httpsessionTable->Lookup(v_sessionID);
if(pHTTPSession){
outFD = pHTTPSession->outfd;
*ppClient = pHTTPSession->pClient;
return OS_NoErr;
}
return OS_Err;
}
//
//从HASHTABLE中移去一项
//
OS_Error HTTPSocketMgr::Remove(CClientSession * pClient)
{
OS_Error ret = OS_Err;
HashTable::Iterator* iter = HashTable::Iterator::create(*m_httpsessionTable);
CHTTPSession *pHttpSession;
char const* key;
while ((pHttpSession = (CHTTPSession *)(iter->next(key))) != NULL) {
if(pHttpSession->pClient == pClient){
m_httpsessionTable->Remove(key);
delete pHttpSession;
ret = OS_NoErr;
break;
}
}
delete iter;
return ret;
}
HTTPSocketMgr * HTTPSocketMgr::GetInstance()
{
if(mgr == NULL){
mgr = new HTTPSocketMgr();
}
return mgr;
}
void HTTPSocketMgr::DelInstance()
{
if(mgr)
{
delete mgr;
mgr = NULL;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -