mirror of
https://github.com/Cc28256/CcRemote.git
synced 2025-06-09 05:49:50 +00:00
添加了一些注释和调整一些代码,变化不大
This commit is contained in:
parent
8be9451190
commit
270ad0fd3c
Binary file not shown.
@ -139,7 +139,7 @@ void CCcRemoteDlg::Activate(UINT nPort, UINT nMaxConnections)
|
|||||||
m_iocpServer = new CIOCPServer;
|
m_iocpServer = new CIOCPServer;
|
||||||
|
|
||||||
// 开启IPCP服务器 最大连接 端口 查看NotifyProc回调函数 函数定义
|
// 开启IPCP服务器 最大连接 端口 查看NotifyProc回调函数 函数定义
|
||||||
if (m_iocpServer->Initialize(NotifyProc, NULL, 100000, nPort))
|
if (m_iocpServer->Initialize(NotifyProc, NULL, nMaxConnections, nPort))
|
||||||
{
|
{
|
||||||
|
|
||||||
char hostname[256];
|
char hostname[256];
|
||||||
@ -156,7 +156,6 @@ void CCcRemoteDlg::Activate(UINT nPort, UINT nMaxConnections)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
str.Format("监听端口: %d成功", nPort);
|
str.Format("监听端口: %d成功", nPort);
|
||||||
ShowMessage(true, str);
|
ShowMessage(true, str);
|
||||||
}
|
}
|
||||||
@ -166,7 +165,6 @@ void CCcRemoteDlg::Activate(UINT nPort, UINT nMaxConnections)
|
|||||||
ShowMessage(true, str);
|
ShowMessage(true, str);
|
||||||
}
|
}
|
||||||
|
|
||||||
//m_wndStatusBar.SetPaneText(3, "连接: 0");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOL CCcRemoteDlg::OnInitDialog()
|
BOOL CCcRemoteDlg::OnInitDialog()
|
||||||
@ -199,19 +197,22 @@ BOOL CCcRemoteDlg::OnInitDialog()
|
|||||||
SetIcon(m_hIcon, FALSE); // 设置小图标
|
SetIcon(m_hIcon, FALSE); // 设置小图标
|
||||||
|
|
||||||
// TODO: 在此添加额外的初始化代码
|
// TODO: 在此添加额外的初始化代码
|
||||||
|
////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
|
||||||
InitSystemMenu();//初始化系统托盘
|
InitSystemMenu();//初始化系统托盘
|
||||||
InitToolBar();//初始化工具栏按钮控件
|
InitToolBar();//初始化工具栏按钮控件
|
||||||
InitMyMenu();//初始化菜单控件
|
InitMyMenu();//初始化菜单控件
|
||||||
InitList();//初始化列表控件
|
InitList();//初始化列表控件
|
||||||
InitStatusBar();//初始化状态栏控件
|
InitStatusBar();//初始化状态栏控件
|
||||||
//---------改变窗口大小出发动态调整-------|
|
//---------改变窗口大小触发动态调整-------|
|
||||||
CRect rect;
|
CRect rect;
|
||||||
GetWindowRect(&rect);
|
GetWindowRect(&rect);
|
||||||
rect.bottom += 20;
|
rect.bottom += 20;
|
||||||
MoveWindow(rect);
|
MoveWindow(rect);
|
||||||
//----------------------------------------|
|
//----------------------------------------|
|
||||||
ListenPort();
|
ListenPort();//监听端口
|
||||||
Test();
|
Test();
|
||||||
|
|
||||||
return TRUE; // 除非将焦点设置到控件,否则返回 TRUE
|
return TRUE; // 除非将焦点设置到控件,否则返回 TRUE
|
||||||
@ -356,9 +357,11 @@ int CCcRemoteDlg::InitMyMenu()
|
|||||||
|
|
||||||
int CCcRemoteDlg::InitList()
|
int CCcRemoteDlg::InitList()
|
||||||
{
|
{
|
||||||
|
//设置list可选中
|
||||||
m_CList_Online.SetExtendedStyle(LVS_EX_FULLROWSELECT);
|
m_CList_Online.SetExtendedStyle(LVS_EX_FULLROWSELECT);
|
||||||
m_CList_Message.SetExtendedStyle(LVS_EX_FULLROWSELECT);
|
m_CList_Message.SetExtendedStyle(LVS_EX_FULLROWSELECT);
|
||||||
|
|
||||||
|
//计算控件宽度
|
||||||
for (int i = 0; i < COLUMN_ONLINE_COUNT; i++)
|
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);
|
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();
|
CDialogEx::OnClose();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//托盘图标回调函数
|
||||||
void CCcRemoteDlg::OnIconNotify(WPARAM wParam, LPARAM lParam)
|
void CCcRemoteDlg::OnIconNotify(WPARAM wParam, LPARAM lParam)
|
||||||
{
|
{
|
||||||
switch ((UINT)lParam)
|
switch ((UINT)lParam)
|
||||||
|
@ -120,12 +120,17 @@ CIOCPServer::~CIOCPServer()
|
|||||||
// N T ALMOND 06042001 1.0 Origin
|
// N T ALMOND 06042001 1.0 Origin
|
||||||
//
|
//
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
//lang2.1_5 初始化监听端口
|
//初始化监听端口
|
||||||
bool CIOCPServer::Initialize(NOTIFYPROC pNotifyProc, CMainFrame* pFrame, int nMaxConnections, int nPort)
|
bool CIOCPServer::Initialize(NOTIFYPROC pNotifyProc, CMainFrame* pFrame, int nMaxConnections, int nPort)
|
||||||
{
|
{
|
||||||
m_pNotifyProc = pNotifyProc;
|
m_pNotifyProc = pNotifyProc;
|
||||||
m_pFrame = pFrame;
|
m_pFrame = pFrame;
|
||||||
m_nMaxConnections = nMaxConnections;
|
m_nMaxConnections = nMaxConnections;
|
||||||
|
|
||||||
|
/*
|
||||||
|
AF_INET:Internet协议版本4(IPv4)地址族。
|
||||||
|
SOCK_STREAM:一种套接字类型
|
||||||
|
*/
|
||||||
m_socListen = WSASocket(AF_INET, SOCK_STREAM, 0, NULL, 0, WSA_FLAG_OVERLAPPED);
|
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
|
// The listener is ONLY interested in FD_ACCEPT
|
||||||
// That is when a client connects to or IP/Port
|
// That is when a client connects to or IP/Port
|
||||||
// Request async notification
|
// Request async notification
|
||||||
|
// 指定的事件对象以与指定的一组FD_XXX网络事件相关联。
|
||||||
int nRet = WSAEventSelect(m_socListen,
|
int nRet = WSAEventSelect(m_socListen,
|
||||||
m_hEvent,
|
m_hEvent,
|
||||||
FD_ACCEPT);
|
FD_ACCEPT);
|
||||||
@ -230,7 +236,6 @@ bool CIOCPServer::Initialize(NOTIFYPROC pNotifyProc, CMainFrame* pFrame, int nMa
|
|||||||
// N T ALMOND 06042001 1.0 Origin
|
// N T ALMOND 06042001 1.0 Origin
|
||||||
//
|
//
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
//lang2.1_6
|
|
||||||
unsigned CIOCPServer::ListenThreadProc(LPVOID lParam) //¼àÌýÏß³Ì
|
unsigned CIOCPServer::ListenThreadProc(LPVOID lParam) //¼àÌýÏß³Ì
|
||||||
{
|
{
|
||||||
CIOCPServer* pThis = reinterpret_cast<CIOCPServer*>(lParam);
|
CIOCPServer* pThis = reinterpret_cast<CIOCPServer*>(lParam);
|
||||||
@ -303,8 +308,6 @@ unsigned CIOCPServer::ListenThreadProc(LPVOID lParam) //
|
|||||||
// N T ALMOND 06042001 1.0 Origin
|
// N T ALMOND 06042001 1.0 Origin
|
||||||
// Ulf Hedlund 09072001 Changes for OVERLAPPEDPLUS
|
// Ulf Hedlund 09072001 Changes for OVERLAPPEDPLUS
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
//lang2.1_7
|
|
||||||
void CIOCPServer::OnAccept()
|
void CIOCPServer::OnAccept()
|
||||||
{
|
{
|
||||||
|
|
||||||
@ -339,6 +342,7 @@ void CIOCPServer::OnAccept()
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Create the Client context to be associted with the completion port
|
// Create the Client context to be associted with the completion port
|
||||||
|
// 创建要与完成端口连接客户端的上下文
|
||||||
ClientContext* pContext = AllocateContext();
|
ClientContext* pContext = AllocateContext();
|
||||||
// AllocateContext fail
|
// AllocateContext fail
|
||||||
if (pContext == NULL)
|
if (pContext == NULL)
|
||||||
@ -396,7 +400,7 @@ void CIOCPServer::OnAccept()
|
|||||||
NULL
|
NULL
|
||||||
);
|
);
|
||||||
|
|
||||||
CLock cs(m_cs, "OnAccept" );
|
CLock cs(m_cs, "OnAccept" );//多线程互斥按顺序改变变量
|
||||||
// Hold a reference to the context
|
// Hold a reference to the context
|
||||||
m_listContexts.AddTail(pContext);
|
m_listContexts.AddTail(pContext);
|
||||||
|
|
||||||
@ -417,7 +421,7 @@ void CIOCPServer::OnAccept()
|
|||||||
return;
|
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
|
// Post to WSARecv Next
|
||||||
PostRecv(pContext);
|
PostRecv(pContext);
|
||||||
|
@ -52,6 +52,7 @@ public:
|
|||||||
|
|
||||||
void Lock()
|
void Lock()
|
||||||
{
|
{
|
||||||
|
//多线程操作变量需要互斥变量来让每个线程按顺序的访问
|
||||||
TRACE(_T("EC %d %s\n") , GetCurrentThreadId(), m_strFunc);
|
TRACE(_T("EC %d %s\n") , GetCurrentThreadId(), m_strFunc);
|
||||||
EnterCriticalSection(m_pcs);
|
EnterCriticalSection(m_pcs);
|
||||||
}
|
}
|
||||||
@ -136,7 +137,7 @@ public:
|
|||||||
CIOCPServer();
|
CIOCPServer();
|
||||||
virtual ~CIOCPServer();
|
virtual ~CIOCPServer();
|
||||||
|
|
||||||
NOTIFYPROC m_pNotifyProc;
|
NOTIFYPROC m_pNotifyProc; //回调函数指针,从我们的回调传进来做参数,只想我们的回调函数
|
||||||
CMainFrame* m_pFrame;
|
CMainFrame* m_pFrame;
|
||||||
|
|
||||||
bool Initialize(NOTIFYPROC pNotifyProc, CMainFrame* pFrame, int nMaxConnections, int nPort);
|
bool Initialize(NOTIFYPROC pNotifyProc, CMainFrame* pFrame, int nMaxConnections, int nPort);
|
||||||
@ -170,7 +171,7 @@ protected:
|
|||||||
|
|
||||||
bool m_bInit;
|
bool m_bInit;
|
||||||
bool m_bDisconnectAll;
|
bool m_bDisconnectAll;
|
||||||
BYTE m_bPacketFlag[5];
|
BYTE m_bPacketFlag[5]; //数据标记
|
||||||
void CloseCompletionPort();
|
void CloseCompletionPort();
|
||||||
void OnAccept();
|
void OnAccept();
|
||||||
bool InitializeIOCP(void);
|
bool InitializeIOCP(void);
|
||||||
|
Binary file not shown.
Binary file not shown.
@ -5,7 +5,7 @@ echo *.aps *.idb *.ncp *.obj *.pch *.tmp *.sbr
|
|||||||
echo ----------------------------------------------------
|
echo ----------------------------------------------------
|
||||||
pause
|
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
|
pause
|
||||||
|
Loading…
x
Reference in New Issue
Block a user