⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 httplisten.cpp

📁 java程序五子棋源代码。 java程序五子棋源代码。
💻 CPP
字号:
 // HttpListen.cpp : implementation file
//

#include "stdafx.h"
#include "ChessGate.h"
#include "HttpListen.h"
#include "HttpRequest.h"
#include "ChessGateDlg.h"


#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CHttpListen

CHttpListen::CHttpListen(CChessGateDlg *pDlg)
{
	this->pDlg=pDlg;
}

CHttpListen::~CHttpListen()
{
}


// Do not edit the following lines, which are needed by ClassWizard.
#if 0
BEGIN_MESSAGE_MAP(CHttpListen, CSocket)
	//{{AFX_MSG_MAP(CHttpListen)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()
#endif	// 0

/////////////////////////////////////////////////////////////////////////////
// CHttpListen member functions

void CHttpListen::OnAccept(int nErrorCode) 
{
	int		i,nFindFlag = 0;
	time_t	tCurTime;

	//进入临界区,写HttpSocket队列
	CSingleLock lock(&pDlg->m_csHttpQueue);
	lock.Lock();
	
	tCurTime = time(NULL);

	//关闭非活动连接
	for(i=0;i<sizeof(pDlg->httpQueue)/sizeof(HttpQueue);i++){
		if((pDlg->httpQueue[i].bState == 1) && (tCurTime - pDlg->httpQueue[i].tLast > 600)){
			pDlg->httpQueue[i].pHttpRequest->Close();
			delete pDlg->httpQueue[i].pHttpRequest;
			pDlg->httpQueue[i].pHttpRequest = NULL;
			pDlg->httpQueue[i].bState	= 0;
			pDlg->httpQueue[i].llSYN	= 0;
		}
	}

	//在队列中查找空闲的结点
	for(i=0;i<sizeof(pDlg->httpQueue)/sizeof(HttpQueue);i++){
		if(pDlg->httpQueue[i].bState == 0){
			nFindFlag = 1;
			break;
		}
	}
		
	if(nFindFlag == 1){
		//找到空闲的结点
		pDlg->httpQueue[i].pHttpRequest = new CHttpRequest(pDlg);
		Accept(*pDlg->httpQueue[i].pHttpRequest);
		pDlg->httpQueue[i].bState	= 1;
		pDlg->httpQueue[i].tLast	= time(NULL);
	}
	lock.Unlock();
	
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -