添加了一些注释和调整一些代码,变化不大

This commit is contained in:
ChangCheng 2020-05-19 19:09:26 +08:00
parent 8be9451190
commit 270ad0fd3c
7 changed files with 25 additions and 15 deletions

Binary file not shown.

View File

@ -139,7 +139,7 @@ void CCcRemoteDlg::Activate(UINT nPort, UINT nMaxConnections)
m_iocpServer = new CIOCPServer;
// 开启IPCP服务器 最大连接 端口 查看NotifyProc回调函数 函数定义
if (m_iocpServer->Initialize(NotifyProc, NULL, 100000, nPort))
if (m_iocpServer->Initialize(NotifyProc, NULL, nMaxConnections, nPort))
{
char hostname[256];
@ -156,7 +156,6 @@ void CCcRemoteDlg::Activate(UINT nPort, UINT nMaxConnections)
}
}
str.Format("监听端口: %d成功", nPort);
ShowMessage(true, str);
}
@ -166,7 +165,6 @@ void CCcRemoteDlg::Activate(UINT nPort, UINT nMaxConnections)
ShowMessage(true, str);
}
//m_wndStatusBar.SetPaneText(3, "连接: 0");
}
BOOL CCcRemoteDlg::OnInitDialog()
@ -199,19 +197,22 @@ BOOL CCcRemoteDlg::OnInitDialog()
SetIcon(m_hIcon, FALSE); // 设置小图标
// TODO: 在此添加额外的初始化代码
////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////
InitSystemMenu();//初始化系统托盘
InitToolBar();//初始化工具栏按钮控件
InitMyMenu();//初始化菜单控件
InitList();//初始化列表控件
InitStatusBar();//初始化状态栏控件
//---------改变窗口大小发动态调整-------|
//---------改变窗口大小发动态调整-------|
CRect rect;
GetWindowRect(&rect);
rect.bottom += 20;
MoveWindow(rect);
//----------------------------------------|
ListenPort();
ListenPort();//监听端口
Test();
return TRUE; // 除非将焦点设置到控件,否则返回 TRUE
@ -356,9 +357,11 @@ int CCcRemoteDlg::InitMyMenu()
int CCcRemoteDlg::InitList()
{
//设置list可选中
m_CList_Online.SetExtendedStyle(LVS_EX_FULLROWSELECT);
m_CList_Message.SetExtendedStyle(LVS_EX_FULLROWSELECT);
//计算控件宽度
for (int i = 0; i < COLUMN_ONLINE_COUNT; i++)
{
m_CList_Online.InsertColumn(i, m_Column_Online_Data[i].title, LVCFMT_LEFT, m_Column_Online_Data[i].nWidth);
@ -670,6 +673,8 @@ void CCcRemoteDlg::OnClose()
CDialogEx::OnClose();
}
//托盘图标回调函数
void CCcRemoteDlg::OnIconNotify(WPARAM wParam, LPARAM lParam)
{
switch ((UINT)lParam)

View File

@ -120,12 +120,17 @@ CIOCPServer::~CIOCPServer()
// N T ALMOND 06042001 1.0 Origin
//
////////////////////////////////////////////////////////////////////////////////
//lang2.1_5 初始化监听端口
//初始化监听端口
bool CIOCPServer::Initialize(NOTIFYPROC pNotifyProc, CMainFrame* pFrame, int nMaxConnections, int nPort)
{
m_pNotifyProc = pNotifyProc;
m_pFrame = pFrame;
m_nMaxConnections = nMaxConnections;
/*
AF_INET:Internet协议版本4IPv4
SOCK_STREAM:
*/
m_socListen = WSASocket(AF_INET, SOCK_STREAM, 0, NULL, 0, WSA_FLAG_OVERLAPPED);
//³õʼ»¯ Ì×½Ó×Ö
@ -148,6 +153,7 @@ bool CIOCPServer::Initialize(NOTIFYPROC pNotifyProc, CMainFrame* pFrame, int nMa
// The listener is ONLY interested in FD_ACCEPT
// That is when a client connects to or IP/Port
// Request async notification
// 指定的事件对象以与指定的一组FD_XXX网络事件相关联。
int nRet = WSAEventSelect(m_socListen,
m_hEvent,
FD_ACCEPT);
@ -230,7 +236,6 @@ bool CIOCPServer::Initialize(NOTIFYPROC pNotifyProc, CMainFrame* pFrame, int nMa
// N T ALMOND 06042001 1.0 Origin
//
////////////////////////////////////////////////////////////////////////////////
//lang2.1_6
unsigned CIOCPServer::ListenThreadProc(LPVOID lParam) //¼àÌýÏß³Ì
{
CIOCPServer* pThis = reinterpret_cast<CIOCPServer*>(lParam);
@ -303,8 +308,6 @@ unsigned CIOCPServer::ListenThreadProc(LPVOID lParam) //
// N T ALMOND 06042001 1.0 Origin
// Ulf Hedlund 09072001 Changes for OVERLAPPEDPLUS
////////////////////////////////////////////////////////////////////////////////
//lang2.1_7
void CIOCPServer::OnAccept()
{
@ -339,6 +342,7 @@ void CIOCPServer::OnAccept()
}
// Create the Client context to be associted with the completion port
// 创建要与完成端口连接客户端的上下文
ClientContext* pContext = AllocateContext();
// AllocateContext fail
if (pContext == NULL)
@ -396,7 +400,7 @@ void CIOCPServer::OnAccept()
NULL
);
CLock cs(m_cs, "OnAccept" );
CLock cs(m_cs, "OnAccept" );//多线程互斥按顺序改变变量
// Hold a reference to the context
m_listContexts.AddTail(pContext);
@ -417,7 +421,7 @@ void CIOCPServer::OnAccept()
return;
}
m_pNotifyProc((LPVOID) m_pFrame, pContext, NC_CLIENT_CONNECT); //回调函数处理 查看Initialize 的使用
m_pNotifyProc((LPVOID) m_pFrame, pContext, NC_CLIENT_CONNECT); //回调函数处理 有Initialize 传进来的函数指针的使用
// Post to WSARecv Next
PostRecv(pContext);

View File

@ -52,6 +52,7 @@ public:
void Lock()
{
//多线程操作变量需要互斥变量来让每个线程按顺序的访问
TRACE(_T("EC %d %s\n") , GetCurrentThreadId(), m_strFunc);
EnterCriticalSection(m_pcs);
}
@ -136,7 +137,7 @@ public:
CIOCPServer();
virtual ~CIOCPServer();
NOTIFYPROC m_pNotifyProc;
NOTIFYPROC m_pNotifyProc; //回调函数指针,从我们的回调传进来做参数,只想我们的回调函数
CMainFrame* m_pFrame;
bool Initialize(NOTIFYPROC pNotifyProc, CMainFrame* pFrame, int nMaxConnections, int nPort);
@ -170,7 +171,7 @@ protected:
bool m_bInit;
bool m_bDisconnectAll;
BYTE m_bPacketFlag[5];
BYTE m_bPacketFlag[5]; //数据标记
void CloseCompletionPort();
void OnAccept();
bool InitializeIOCP(void);

Binary file not shown.

Binary file not shown.

View File

@ -5,7 +5,7 @@ echo *.aps *.idb *.ncp *.obj *.pch *.tmp *.sbr
echo ----------------------------------------------------
pause
del /F /Q /S *.aps *.idb *.db *.ncp *.obj *.pch *.sbr *.tmp *.pdb *.bsc *.ilk *.sdf *.ncb *.dep *.ipch *.tlog *.dll *.exp
del /F /Q /S *.aps *.idb *.ipdb *.iobj *.db *.ncp *.obj *.pch *.sbr *.tmp *.pdb *.bsc *.ilk *.sdf *.ncb *.dep *.ipch *.tlog *.dll *.exp
pause